You can perform the process without using a live CD, by going to single user (root) mode. This is necessary to avoid loosing updates to files in /home while transferring it to the new partition, something that is possible (depending on the apps you run and your cron jobs) if you try to copy /home and modify your /etc/fstab from within your GUI login.
Preparation:
1. Print this entire post in paper. You will need it, as there will be no ability to use your browser while performing the steps described. Make sure that the entire commands are printed.
2. Verify that all the needed tools are installed on your system: blkid, rsync, awk, sed, grep. They will, most probably, but it is a Good Thing to check beforehand.
3. If your new disk is not properly formatted, do it now, before proceeding below.
Implementation:
Reboot in single user mode. Use either method of A or B below:
A. Use the reboot command and upon reboot choose the recent `(recovery)' kernel - typically, the 2nd line of your grub menu. In the menu that appears at the end of the boot process choose `Root shell ...' (with or without networking).
B. Open a terminal and type `sudo telinit 1'.
You are now, after reboot, at a root shell. Be careful. Type the following commands (read them again and verify them before hitting the <ENTER> key):
1. Make a directory and mount new home partition there.
Code:
mkdir -p /mnt/newhome
mount /dev/sdb1 /mnt/newhome
2. Copy entire contents of old home to new home, preserving *everything* (aHAX) while staying on the same filesystem (x). The (v) is to see progress; it will take time to complete. The slashes at the end of source, destination *are* important.
Code:
rsync -vaxHAX /home/ /mnt/newhome/
3. Unmount both partitions and remove the directory of step #1.
Code:
umount /mnt/newhome
umount /home
rm -R /mnt/newhome
4. Modify your /etc/fstab to mount the new partition as /home; comment out the old one. You may delete it afterwards, when you are sure everything is ok.
Code:
NEWID=$(blkid | grep '/dev/sdb1' | awk '{print $2}' | sed 's/"//g')
cat /etc/fstab | awk '{ if ($0~/^.*[[:space:]]\/home[[:space:]]/) { print "#" $0; sub(/UUID=[0-9a-f\-]*/, "'"$NEWID"'", $0); print $0 } else print $0 }' > /etc/fstab.new
mv /etc/fstab /etc/fstab.old
mv /etc/fstab.new /etc/fstab
chmod 640 /etc/fstab /etc/fstab.old
The code uses `blkid' to read the UUID of your partitions, `grep' to select the right line and `awk' and `sed' to select the right field and clear the double quotes around the uuid. The result is stored to environment variable NEWID.
Then your /etc/fstab is processed by an awk script that finds the line containing /home, puts a # to comment it out, duplicate it and change the old uuid value (that of /dev/sda7) to the new one (that of /dev/sdb1). That way your mount options are kept the same. The result is written to a new file, because writing it back to /etc/fstab directly would truncate it (this would be bad!).
Then a backup of original /etc/fstab is made to /etc/fstab.old - to use it if something goes wrong to restore your system - and the new file replaces /etc/fstab. Lastly, permissions of both files are set as should be (in case your umask changes them).
Note that the double quote/single quote/double quote parts around $NEWID, ie:
are essential, because the value of the shell variable is thus entered inline the awk code as if it was a string contained in double quotes.
5. Sync to ensure changes are back to disk and then remount /home to verify the correct setup of your system.
6. Issue a command without arguments and inspect the output. Navigate (`cd' and `ls -l') through /home and see if everything looks right.
7. Leave the single user mode. Use either method of A or B below:
A. B. Restoration (if things go wild):
If something goes wrong after changing /etc/fstab and rebooting, simply replace the new fstab by the old (backup) and reboot:
Code:
sudo mv /etc/fstab /etc/fstab.new
sudo mv /etc/fstab.old /etc/fstab
chmod 640 /etc/fstab*
Bookmarks