How to move /var directory to another partition

Your /var directory has filled up and you are left with with no free disk space available. This is a typical scenario which can be easily fixed by mounting your /var directory on different partition. Let’s get started by attaching new storage, partitioning and creating a desired file system. The exact steps may vary and are not part of this config article. Once ready obtain partition UUID of your new var partition eg. /dev/sdc1:

# blkid | grep sdc1
/dev/sdc1: UUID="1de46881-1f49-440e-89dd-6c32592491a7" TYPE="ext4" PARTUUID="652a2fee-01"

Create a new mount point and mount your new partition:

# mkdir /mnt/newvar
# mount /dev/sdc1 /mnt/newvar

Confirm that it is mounted. Note, your output will be different:

# df -h /mnt/newvar
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdc1       1.8T  1.6T  279G  85% /mnt/newvar

Copy current /var data to the new location:

# rsync -aqxP /var/* /mnt/newvar

Unmount new partition:

# umount /mnt/newvar/  /mnt/var/

Edit your /etc/fstab to include new partition and choosing a relevant file-system:

UUID=1de46881-1f49-440e-89dd-6c32592491a7 /var        ext4    defaults        0       2

Reboot your system and you are done. Confirm that everything is working correctly and optionally remove old var directory by booting to some Live Linux system etc.

Comments and Discussions
Linux Forum