Moving usr home to another partition


Before following this guide, make sure you:
a) have backups of your data
b) understand what you are doing
This worked fine for me but I don't promise or guarantee it will work 100% for you!

There are two ways to move /usr /home etc, the easy and the hard...

The easy way

Create a partition for each directory, let's assume /usr.
Mount the new partition: /mnt/new_partition/ (let's assume /dev/sda99)
Copy all the files in /usr to the root of the new partition like so:
Run the following IN the /usr directory:
find . -depth -print0 | cpio --null --sparse -pvd /mnt/new_partition

Now unmount /mnt/new_partition (/dev/sda99)
Rename your current /usr directory to /oldusr
Edit your fstab file to have a line like this:
/dev/sda99 /usr ext3 defaults 0 0

Reboot!

NOTE: You'll find that VIM, bash, etc won't work once you've renamed /usr

Once it all works, you can remove the original directories (/oldusr)


The hard way (multiple directories on same partition)

Create the new partition to hold all the different directories.
Mount the partition: /mnt/new_partition (assume /dev/sda99)
Create the new directories on the new partition, ie:
mkdir /mnt/new_partition/usr
mkdir /mnt/new_partition/home

Copy the current directories over by running this in each directory:
cd /usr
find . -depth -print0 | cpio --null --sparse -pvd /mnt/new_partition/usr

cd /home
find . -depth -print0 | cpio --null --sparse -pvd /mnt/new_partition/home

Create a new mount point on your current drive. I created this:
mkdir /mnt-extended

Edit fstab to have a line like this:
/dev/sda99 /mnt-extended ext3 defaults 0 0

Now create the following file in /etc/init.d called bind.sh:
#!/bin/sh
if [ "X$1" = "Xstart" ]; then
echo "Binding /mnt-extended/usr to /usr..."
mount --bind /mnt-extended/usr /usr
mount --bind /mnt-extended/home /home
echo "...done"
fi

This binds each new directory to the old directory on boot up.

Now create a symlink in /etc/rcS.
Watch out! The number is important. It mustn't be called too soon or too late. I placed it at S38, ie:
ln -s /etc/init.d/bind.sh /etc/rcS.d/S38bind.sh

Finally rename /usr and /home to /oldusr and /oldhome and do:
mkdir /usr
mkdir /home

Reboot.

Once it all works, you can remove /oldhome /oldusr

NOTE: do not try to move the /lib directory using this method - it won't work!