Yuugian's answer is definitely the safe and proper way to go. But for some people, it might be good to know that you can actually do that without even shutting down your running system. You can treat this answer as a training or last resort in situations where booting from a liveCD is not an option.
Disclaimer: This procedure is not recommended for beginner users. If you don't put enough attention to step 1, your system might crash while you perform next steps and you can experience unexpected behaviour of various applications after reboot. Before you attempt this, you should check that you're familiar with /var
description on tldp and your distribution-specific deviations from that.
Close programs that have open files under /var
. Start by switchin to console (one of the "real" ttys) and shutting down the X server, as well as the Desktop Manager (kdm/gdm/lightdm/...), if you use one. If you don't know how to do that or what it means, do NOT continue - chances that you might break you system are too high, and there are just too many possibilities to cover in a step-by-step procedure here - sorry!
Use lsof
or fuser
to find remaining programs that have files open under /var
. Notice that if a program was started as/by a system service, it is always better to stop the service, rather than killing the task. If there are some programs/services too stubborn to deal with this way, you might also try switching to single-user mode (init level 1) - if that is acceptable for you. In most cases it would be OK to have a few(!) files still open under /var
- for instance the pid files under /var/run
, in case your system uses that location.
Mount your root partition (for the second time). Simply choose any empty directory as a temporary mount point for that - I'll use /mnt/tmp
as an example. Usually the mount
command (without parameters) will not display the real device name behind your root partition, you will need to check which one is it (unless you know for sure). You can usually get the information either from lsblk
(if you have it on your system), or bootloader configuration, or by cat /proc/cmdline
, or by identifying the partition by size reported by fdisk
.
Copy /var
contents. Once you've found the partition and mounted it, copy the contents of /var
to your rootfs (mounted in the new location), using cp -ad
, such as: cp -ad /var /mnt/tmp/
. Note: if your distro still manages /var/run
and /var/lock
directories instead of recently introduced /run/
, you should skip the contents of these two directories. If extglob is enabled in your shell, you can do that using cp -ad /var/!(run|lock) /mnt/tmp/var/
- or use cpio
instead. Just to create the two directories under /mnt/tmp/var/
and set their permissions properly after copying.
Remove old /var
entry in fstab
. The safe way is to comment it out, of course.
Reboot