Debian – How to Move /var to Another Existing Partition

debianpartition

I have a / partition which contains /var and is too small.
I have another existing partition with enough space.

Here is my df:

File system          Size. Occ. Avai. %Ful. Monté sur
/dev/sda1             5,0G  4,5G  289M  95% /
tmpfs                 242M     0  242M   0% /lib/init/rw
udev                   10M  2,7M  7,4M  27% /dev
tmpfs                 242M     0  242M   0% /dev/shm
/dev/sda2              15G  406M   14G   3% /home

How can I move the /var folder from sda1 to sda2 ?

Best Answer

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
Related Topic