Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am currently stuck with a restrictive partitioning scheme that makes my partitions fill up. It looks like this:

/dev/sda7             870G  315G  511G  39% /
/dev/sda6             2.0G  271M  1.6G  15% /tmp
/dev/sda3              15G   13G  1.5G  90% /usr
/dev/sda2              15G  8.6G  5.0G  64% /var
/dev/sda1              99M   36M   58M  39% /boot
tmpfs                 7.9G     0  7.9G   0% /dev/shm

I want to move the data in /usr (and /var as well, probably) to the root partition. I don't really care about the partitions themself, so a merge is not required.

What would be the best approach in doing this? Currently, my plan is this:

cp -R /usr /newusr
umount /usr
mv /newusr /usr

Could it really be this simple, or am I overlooking something?

share|improve this question

Your approach is correct. Create a directory on the root partition, copy your data there, unmount the usr partition and move your new directory to usr. Don't forget to edit your /etc/fstab afterwards.

share|improve this answer
It is not enough, cp -R doesn't copies hard links, symlinks, sockets, devices, suidbits and acls correctly. He needs cp -vfa – peterh Dec 20 '13 at 14:59
cp -av should be enough. – etagenklo Dec 20 '13 at 15:36
  1. First you should always check, if you have enough free space. This time, you have.

  2. About the copy:

Not so simple. There special files, whose special attributes isn't copied always correctly. Instead of cp -R, use

cp -vfa /usr /newusr

If you like to see what is currently being done, this can be reached with the "-v" flag.

  1. Don't forget to edit /etc/fstab to the changes.
  2. WARNING: After a repartitioning, the kernel can't always to re-read your new partition table, and thus it is possible, that it will use further your old! It is very dangerous! The version of the kernel about the current partition table can be found in /proc/partitions, and the partition table on disk can be read with an fdisk -l /dev/sda. If there is a mismatch about the partition which you like to change currently, best thing to reboot.
share|improve this answer
Where exactly do you see anything about repartitioning in the question? – etagenklo Dec 20 '13 at 15:37
@etagenklo Because the next rational step after a such operation is a complex repartitioning/resizing, although I admit it wasn't mentioned in the question directly. – peterh Dec 20 '13 at 16:52

In order to achieve this it would be necessary to do it on single user mode or using a LiveCD, that's what you'll find on internet.

Furthermore, it's possible to perform this at runtime (a little bit risky, of course) but I think this way will only work for /var and not for /usr, some runtime libs depend on this folder. You can try on a test machine previously if it do works.

First at all you must check that any process/services is using/writing to the directory you want to move.

lsof | grep -E '/usr|/var'

Generally /var is still in use for pid and sock files, /usr as well as any lib will need it.

So, stop/kill services and processes that appear.

COMMAND    PID  TID        USER   FD      TYPE             DEVICE   SIZE/OFF       NODE NAME
cupsd      723             root    5u      REG                8,1          0    8651393 /var/log/cups/error_log
cupsd      723             root    6u      REG                8,1          0    8651908 /var/log/cups/page_log
cupsd      723             root   12u     unix 0xffff88020d97d780        0t0       9958 /var/run/cups/cups.sock

In this short example, cups daemon is running and using those directories. If stop them, they will not appear on lsof output.

After that, you need a copy of your current data, I'll suggest using rsync instead of cp (in order to preserve everything, permissions, symlinks, etc.)

mkdir /mnt/var
mkdir /mnt/usr

Do your backup

rsync -avz /var/* /mnt/var
rsync -avz /usr/* /mnt/usr

Unmount folders

umount /var
umount /usr

Restore data

rsync -avz /mnt/var/* /var
rsync -avz /mnt/usr/* /usr

Edit your /etc/fstab file and comment/delete the entries where /var and /usr where supposed to be mounted.

Then you can start all services you stopped or restart your machine. If for /usr doesn't work, you can't stop a daemon (maybe you can't kill it cause depends on init pid) the only way will be using a LiveCD.

Though you didn't mention which type of machine is (your PC, office machine, a server, etc) it will depend on this to do perform the formal way possible.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.