How to move /var folder to a new partition in Linux

  • make the new partition, & format with mkfs.ext3
  • mount the new filesystem in /mnt
#mkdir /mnt/newvar
#mount /dev/sdb1 /mnt/newvar
  • Go to single-user mode so that there is no rw activity on the directory during the process
#init 1
  • Backup data in var only (not the /var directory itself)
#cd /var
#cp -ax * /mnt/newvar
  • Rename the /var directory (to make sure this has worked before deleting it!)
#cd /
#mv var var.old
  • Make new var directory
#mkdir /var
  • Unmount the new partition
#umount /dev/sdb1
  • Remount it as /var
#mount /dev/sdb1 /var
  • If everything goes fine then put an entry into /etc/fstab
/dev/sdb1               /var          ext3    defaults        0 0

15 thoughts to “How to move /var folder to a new partition in Linux”

  1. Nice Post! As comment, i'll just add that it's better to disable selinux before starting (or u'll need more options on cp to preserve security contexts…).

    1. could you be a little more specific, How do you disable selinux, or which options you think will be needed…the original post was concise and detailed.

    2. In fact, you don’t need to disable SELINUX. After mounting the brand new var directory, just make:
      #restorecon -Rv /var

      And it will restore the SELINUX contexts.

  2. Thanks, worked fine, except that now I'm stuck in terminal mode & can't get back to GUI. Tried init 5 and init 3,also reboot and shutdown -r now, but still no gui. Anyone got another idea? System is deb 7.8 stable.
    -teejay

  3. Worked fine, but now I'm stuck in terminal mode. init 5 or shutdown -r now or reboot doesn't get me to GUI.
    Any other ideas? System is Deb 7.8 stable on Desktop with BIOS

    1. I had the same problem.Best way to solve this is to use a live CD.
      You will have to mount the root partition in /mnt just like /var

Leave a Reply

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