I have a webserver with a 4GB CF card in a very very small computer. I was trying to come up with ways to reduce writes on this device and I remembered UnionFS. UnionFS can take 1 folder and make it read-only and have all the changes written to another folder. To the user, everything will look the same. This is very good when adding a disk to a computer and your not using LVM.
What I want to do? I want /tmp, /var/log, /var/home, and /root to have the changes written to my USB device that is mounted as /mnt. These directories receive a lot of writes to them.
I copied the following commands to /etc/rc.local so that they are executed when the machine boots:
mount -t unionfs -o dirs=/mnt/logs=rw:/var/log=ro unionfs /var/log
mount -t unionfs -o dirs=/mnt/filesystem/root=rw:/root=ro unionfs /root
mount -t unionfs -o dirs=/mnt/filesystem/home=rw:/home=ro unionfs /home
mount -t unionfs -o dirs=/mnt/filesystem/tmp=rw:/tmp=ro unionfs /tmp
Lets make sure everything worked by doing `df -h`:
/dev/sda1 3.8G 1.6G 2.1G 44% /
unionfs 7.5G 3.3G 3.8G 47% /var/log unionfs 7.5G 3.3G 3.8G 47% /root unionfs 7.5G 3.3G 3.8G 47% /home unionfs 7.5G 3.3G 3.8G 47% /tmp ----------------- If you want this to be mounted at boot time without using /etc/rc.local, simply add the following to /etc/fstab: ----------------- unionfs /tmp unionfs dirs=/mnt/filesystem/tmp=rw:/tmp=ro 0 0 unionfs /home unionfs dirs=/mnt/filesystem/home=rw:/tmp=ro 0 0 unionfs /var/log unionfs dirs=/mnt/logs=rw:/var/log=ro 0 0 unionfs /root unionfs dirs=/mnt/filesystem/root=rw:/tmp=ro 0 0 ----------------- Now all the changes will be written to my USB device and my main CF cards will not be written to a lot.