Move /var to another existing partition?

Go into single user mode, and make sure any process writing to /var is stopped. (Check with lsof | grep /var)

mkdir -p /home/var
rsync -va /var /home/var
mv /var /var.old # you can remove /var.old when you are done to reclaim the space
mkdir -p /var
mount -o bind /home/var /var

update your /etc/fstab to make the bind-mount permanent.
/etc/fstab

/home/var /var        none    bind

1) make the new partition, & format with mkfs.ext3
2) mount the new filesystem in /mnt
# mkdir /mnt/newvar
# mount /dev/sdb1 /mnt/newvar

3) Go to single-user mode so that there is no rw activity on the directory during the process
# init 1

4) Backup data in var only (not the /var directory itself)
# cd /var
# cp -ax * /mnt/newvar

5) Rename the /var directory (to make sure this has worked before deleting it!)
# cd /
# mv var var.old

6) Make new var directory
# mkdir /var

7) Unmount the new partition
# umount /dev/sdb1

8) Remount it as /var
# mount /dev/sdb1 /var

9) If everything goes fine then put an entry into /etc/fstab
/dev/sdb1 /var ext3 defaults 0 0

Posted in Howto

Leave a Reply

Your email address will not be published. Required fields are marked *

*