Size: 7226
Comment:
|
Size: 7241
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 82: | Line 82: |
== Make the Switch == | == Preparing fstab for the switch == |
The Advantages of This Guide
This guide was written simply because there were flaws in the other guides and it was worth recording these notes for future reference. Community Documentation is an excellent way to help others at the same time. This guide:
- Aims to keep the system usable and the data all safe.
If the system unexpectedly loses power or goes into hibernate mode or anything at any point through this guide then it should still boot-up & work just fine. That's the main aim anyway.
- Use rsync to move the files
Rsync is designed for backups of /home, and much more. It is able to maintain other characteristics of the file, like permissions, ownership, and timestamps. There was a lot of debate about which command to copy your files to the new /home partition which stemmed from a time when cp was not able to do it properly (apparently it skipped files?). Cp was not designed to be a powerful backup tool, rsync was. The fix, then, was to use a combination of find and cpio (See section 8.3.5).
The Guide
Setting up /home on a separate partition is beneficial because your settings, files, and desktop will be maintained if you upgrade, (re)install Ubuntu or another distro. This works because /home has a sub-folder for each user's settings and files which contain all the data & settings of that user. Also, fresh installs for linux typically like to wipe whatever partition they are being installed to so either the data & settings need to be backed-up elsewhere or else avoid the fuss each time by having /home on a different partition.
Setup Partitions
This is beyond the scope of this page. Try here if you need help. Memorize or write down the location of the partition, something like /sda3. When you do create a new partition it is highly suggested that you create an ext3 or ext4 partition to house your new home folder.
Find the uuid of the Partition
The uuid (Universally Unique Identifier) reference for all partitions can be found by opening a command-line to type the following:
sudo blkid
Alternatively, for some older releases of Ubuntu the "blkid" command might not work so this could be used instead
sudo vol_id -u <partition>
for example
sudo vol_id -u /dev/sda3
Now you just need to take note (copy&paste into a text-file) the uuid of the partition that you have set-up ready to be the new /home partition.
Setup Fstab
Your fstab is a file used to tell Ubuntu what partitions to mount at boot. The following commands will duplicate your current fstab, append the year-month-day to the end of the file name, compare the two files and open the original for editing.
1. Duplicate your fstab file:
sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d)
2. Compare the two files to confirm the backup matches the original:
cmp /etc/fstab /etc/fstab.$(date +%Y-%m-%d)
3. Open the original fstab in a text editor:
gksu gedit /etc/fstab
and add these lines into it
# (identifier) (location, eg sda5) (format, eg ext3 or ext4) (some settings) UUID=???????? /media/home ext3 nodev,nosuid 0 2
and replace the "????????" with the UUID number of the intended /home partition.
NOTE: In the above example, the specified partition in the new text is an ext3, but if yours is an ext4 partition, you should change the part above that says "ext3" to say "ext4", in addition to replacing the ???'s with the correct UUID. Also note that if you are using Kubuntu or Xubuntu, you may need to replace "gedit" with "kate" or "mousepad", respectively. They are text editors included with those distributions.
4. Save and Close the file, and then restart your machine. It should now auto-mount the new partition as /media/home. We will edit the fstab again later so this arrangement of the partition is only temporary.
To ensure your partition is mounted, mount all file systems declared in fstab with:
sudo mount -a
Copy /home to the New Partition
Next we will copy all files, directories and sub-directories from your current /home folder into the new partition:
sudo rsync -axS --exclude='/*/.gvfs' /home/. /media/home/.
The --exclude='/*/.gvfs' prevents rsync from complaining about not being able to copy .gvfs, but I believe it is optional. Even if rsync complains, it will copy everything else anyway. (See here for discussion on this)
Check Copying Worked
You should now have two duplicate copies of all the data within your Home Folder; the original being located in /home and the new duplicate located in /media/home. You should confirm all files and folders copied over successfully. One way to do this is by using the diff command:
diff -r /home /media/home
The only difference that should exist is excluded /.gvfs directory mentioned above.
Preparing fstab for the switch
We now need to modify the fstab again to point to the new partition and mount it as /home. So again on a command-line
gksu gedit /etc/fstab
and now edit the lines you added earlier, changing the "/media/home" part to simply say "/home" so that it looks like this:
# (identifier) (location, eg sda5) (format, eg ext3 or ext4) (some settings) UUID=???????? /home ext3 nodev,nosuid 0 2
Then, press Save, close the file but don't reboot just yet.
Moving /home into /old_home
You now have 2 copies of your /home folder; the new one on the new partition (currently mounted as /media/home) and the old one still in the same partition it was always in (currently mounted as /home). If we were to edit our fstab at this point so that our new partition is mounted as /home, the contents of the new partition would conflict with the contents of the old /home folder, so we need to move the contents of the old home folder out of the way and create an empty "placeholder" folder to act as a mount point.
Type the following string of commands in to do all this at once:
cd / && sudo mkdir /old_home && sudo mv /home /old_home && cd / && sudo mkdir -p /home/user
With your fstab now edited to mount your new partition as /home and your old /home folder now living in /old_home, reboot your computer. Your new partition will mount as /home and everything should look exactly the same as it did before you started.
Deleting the old Home
You can delete your old home directory with:
cd / sudo rm -r /old_home
Technical Notes and Resources
Rsync was chosen over cp and find|cpio because it seemed to maintain permissions.
http://ubuntu.wordpress.com/2006/01/29/move-home-to-its-own-partition/