Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to move /var folder to a new partition in Linux  (Read 1311 times)

0 Members and 3 Guests are viewing this topic.

vaishakp

  • Guest
How to move /var folder to a new partition in Linux
« on: November 16, 2018, 05:10:17 am »
Your /var directory has filled up and you are left with no free disk space available. This is a typical scenario which can be easily fixed by mounting your /var directory on a different partition.


- 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

Done.