Resize /var partition on a remote system (Linux Debian Lenny)

If you have room on your root partition for the contents of /var you could:

  1. stop anything that is using /var where possible
  2. remount /var readonly for good measure mount -f -oremount,ro /var
  3. copy /var to / under a different name with mkdir /vartmp; cp -av /var/* /vartmp/
  4. move things around with mv /var /varmount; mv /vartmp /var
  5. comment out the entry for /var in /etc/fstab
  6. reboot

You should now have /var in place as-was on your root partition instead of its own. You can now resize the old partition as needed. Step 4 should let you rename the /var directory even though it is in use as a mount-point and otherwise busy (and proceses with open files there will track the change as the open files are not referred to by path+name, but instead by inode, once open).

If you don't have space on / but do on /someotherfs then you could try move it there with a symlink in / like so:

  1. stop anything that is using /var where possible
  2. remount /var readonly for good measure mount -f -oremount,ro /var
  3. copy /var with cp -av /var /someotherfs/var
  4. move things around with mv /var /varmount; ln -s /someotherfs/var /var
  5. comment out the entry for /var in /etc/fstab
  6. reboot

This is slightly more risky though as you need to be sure that /someotherfs gets mounted before /var when booting.

If you don't have room where you want to copy it to temporarily you might be able to reduce the size of /var by removing things like cached packages (aptitude clean on Debian style setups, there is no doubt an equivalent yum command), moving other stuff away (for instance, Debian keeps the default httpdocs in /var/www so if it is still there and you have lots of data in there, move it to another partition), and deleting files from /var/log that are not very recent (backing the up first, in case you do need to refer to them later).

As Zoredache says: what ever you do, make sure you are happy with your backup arrangement before proceeding.

Caveat: all the above is from memory, I've not tested it anywhere, follow at own risk!


The traditional way is to boot in single-user mode. That way, /var won't even be mounted by default, so you can mess around with it all you like.