Diff for "Partitioning/Home/Moving"


Differences between revisions 40 and 41
Revision 40 as of 2010-12-13 02:50:05
Size: 7436
Editor: 69
Comment: Fixed couple spelling errors.
Revision 41 as of 2010-12-13 04:49:48
Size: 7846
Editor: 32
Comment: Removed "Sneaky Safety Maneuver" as it was showing people how to delete their old home folder AFTER they had edited their fstab to mount their new home folder.
Deletions are marked like this. Additions are marked like this.
Line 16: Line 16:
This is beyond the scope of this page. [[HowtoPartition|Try here if you need help]]. Memorize or write down the location of the partition, something like /sda3. Its been suggested to use either ext2, ext3 or ext4 rather than vfat or ntfs. Using vfat is not supported and may fail, since vfat does not support permissions. Ntfs has an advantage of being journalized, like ext3 & ext4 but it can also be read easily by Windows. It is a lot less stable than ext3 or ext4 so it is really a question of stability compared with easy access for Windows. If you don't dual-boot with Windows or have plenty of hard-drive space then staying with very much safer ext3 or 4 is the obvious choice. This is beyond the scope of this page. [[HowtoPartition|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.
Line 20: Line 20:
The uuid reference to all partitions get to a [[https://help.ubuntu.com/community/UsingTheTerminal#Starting%20a%20Terminal | command-line]] to try this The uuid (Universally Unique Identifier) reference for all partitions can be found by opening a [[https://help.ubuntu.com/community/UsingTheTerminal#Starting%20a%20Terminal | command-line]] to type the following:
Line 32: Line 32:
Now you just need to note down (copy&paste into a text-file) the uuid of the partition that you have set-up ready to be the new /home partition. 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.
Line 36: Line 36:
These commands should;
 1. Creates a backup of fstab. The "$(date +%Y-%m-%d)" at the end automatically (and quite cleverly) gives the file today's date backwards.
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.
Line 39: Line 38:
 2. Compares fstab with the new back-up just to be certain it's good. 1. Duplicate your fstab file:
{{{
sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d)
}}}
Line 41: Line 43:
 3. Opens the standard text-editor (gedit) in Ubuntu to edit fstab. Note that Kubuntu uses "kate" & Xubuntu uses "mousepad" instead but you could use any text-editor you have installed if you prefer.{{{
sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d)
2. Compare the two files to confirm the backup matches the original:
{{{
Line 44: Line 46:
gksu gedit /etc/fstab }}} and add these lines into it {{{ }}}

3. Open the original fstab in a text editor:
{{{
gksu gedit /etc/fstab
}}} and add these lines into it {{{
Line 47: Line 54:
}}}Replace???????? with the UUID number of the intended /home partition. }}} and replace the "????????" with the UUID number of the intended /home partition.
Line 49: Line 56:
 4. Save the file 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.
Line 51: Line 58:
 5. The Fstab location will be a temporary one - we are to mount the temporary location and copy the existing home to it. (/media/home is assumed in the rest of the guide). If /media/home does not exist yet, then you should create it with the command: {{{
sudo mkdir /media/home
}}}
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.
Line 55: Line 60:
 6. Now, mount the partition with: {{{ To ensure your partition is mounted, mount all file systems declared in fstab with: {{{
Line 61: Line 66:

Next we will copy all files, directories and sub-directories from your current /home folder into the new partition:
Line 67: Line 75:
The data in /home now exists in 2 places but we need to check that it looks about right. If it looks approximately the same then it is probably completely right. 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 differences that should is the excluded /.gvfs directory mentioned above.

==Removing the 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
}}}
After doing this, you will notice your desktop change in appearance and the contents of your home folder will be empty. This is because your /home folder stores user preferences relating to your desktops appearance settings, among other things. Don't worry, both copies of your home folder still exist, but the new location is not being mounted just yet.
Line 70: Line 95:
We now need to modify the fstab again to point to the new /home and mount it properly. So again on a command-line 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
Line 74: Line 99:
and now edit the lines you added earlier to delete the /media part. This should make /media/home into /home as follows and now edit the lines you added earlier, changing the "/media/home" part to simply say "/home" so that it looks like this:
Line 80: Line 105:
Then, press Save.
== ............. ==
== A Sneaky Safety Maneuverer ==
So you now have 2 copies of your /home folder. The new one on the new partition and the old one still in the same partition it was always in. The problem is how to delete the right one!! Since we are still using the old /home 'just' rename your current /home folder:
{{{
cd /
sudo mv /home /old_home
}}}
Now re-create a new blank /home directory just in case it has all gone wrong!
{{{
cd /
sudo mkdir -p /home/user
}}}
Now if things have gone wrong then the system will boot into what appears to be a fresh install with all your data missing. In fact, of course, there are still 2 copies of it all :)
== ............. ==
Then, press Save, close the file and Reboot your PC.
Line 96: Line 107:
and finally, remount the partition with:
{{{
sudo mount -a
}}}

Does it all still look fine? Can you still access your files & folders from the "Places" menu? Reboot to ensure that currently running programs use the /home that is on the new partition.

== After a reboot ==
If everything is working, great, you can delete /old_home. If things aren't working, you can undo by moving your /old_home back to /home, and delete the line you added to fstab.
== Deleting the old Home ==

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.

  • Prepares Partitions and fstab first then only tweaks fstab at the end
    • People test and gain familiarity with the tools before the final crunch-test, another advantage of this guide. Some other guides use mount commands, then move the /home & then set-up fstab. However, if you mess up your fstab at that crunch-point then when you reboot your system will lose track of your /home files! Setting up fstab first and using "sudo mount -a" to mount the partitions checks the modified fstab works at a safe point in the process.

  • 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 differences that should is the excluded /.gvfs directory mentioned above.

==Removing the 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

After doing this, you will notice your desktop change in appearance and the contents of your home folder will be empty. This is because your /home folder stores user preferences relating to your desktops appearance settings, among other things. Don't worry, both copies of your home folder still exist, but the new location is not being mounted just yet.

Make 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 and Reboot your PC.

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/

http://ubuntuforums.org/showthread.php?t=46866

Partitioning/Home/Moving (last edited 2015-11-13 13:16:06 by 80)