What is the correct way to store /var on a separate partition?
First prepare a new partition (e.g. with parted or fdisk and mkfs).
For example, let’s create a new partition in fdisk:
|
1 |
#fdisk /dev/vda |
then choose n for the new partition and go through configuration steps.
choose w at the end to write changes to a disk.
Now format the newly created partition.
Say the partition is /dev/vda3:
|
1 |
#mkfs.ext4 /dev/vda3 |
Now you are ready to mount your partition:
|
1 |
#mount /dev/vda3 /mnt |
and sync your current /var:
|
1 |
#rsync -a /var/ /mnt |
or
|
1 |
#cp -av /var/* /mnt |
Make sure all data is copied to /mnt, pay special attention that soft links are preserved.
Cleanup the current /var : for example delete logs, spool data and so on to free up some space.
Now you are ready to add the entry to /etc/fstab:
|
1 |
/dev/vda3 /var ext4 defaults 0 2 |
and reboot.
If you happen to need to go back you your old /var just comment out the entry in /etc/fstab.





