How to Move Your Home Folder to Another Partition [Linux/Ubuntu]

If you have accepted the default option while installing Ubuntu, or that your computer comes with Ubuntu pre-installed, chances are that your Home folder and the system folders all lie in the same partition. This is perfectly fine, but if you want to upgrade your existing Ubuntu version, or reinstall Ubuntu, you won’t be able to preserve your app settings, or even retain your files and documents. One of the good practice is to give the Home folder its own partition, so whatever changes you made to the System folder won’t affect your Home directory, and you can easily upgrade or reinstall Ubuntu with ease.

If you want to move your Home folder to another partition, here is how you can do so.

Note: You can skip this step if you already has an existing external partition that you can use.

Assuming that your computer has only one hard disk and it contains only one partition. To create a new partition, you have to first obtain a Ubuntu Live CD/USB and boot into it. You can’t partition the hard disk when it is running.

Once you are booted into the Live session, open the app “GParted”. Select the hard disk from the list. It should be labelled something like “sda”.

gparted-select-hard-disk

You should see a number of entries in the list. Select the entry that corresponds to the main partition. It should be the one with the biggest file size and is either in the ext3 or ext4 filesystem format. Right click on it and select “Resize/Move”.

gparted-resize-move-partition

Set the size for the new partition in the “Free Space Following” field. The number is represented in MB, so if you want to set aside 10GB for the new partition, enter “10000”. You will notice that as you enter the number, the number in the “New Size” field will decrease accordingly. My usual practice is to set aside 10GB for the system files and allocate the rest to the Home partition. Click “Resize/Move”.

gparted-set-new-partition-size

Back to the GParted main screen, you should now see a new “Unallocated” entry with the file size that you have set earlier. Right click on it and select “New”. Select “ext4” as the filesystem and click “Add”.

gparted-add-new-partition

Lastly. click the green check button to apply the changes. Depending on your hard disk size, the resizing process might take a long time

gparted-apply-changes

After the process is completed, you should see something like the screen below. Record down the new partition number.

gparted-new-partition-number

Now shut down the live session, remove the live CD/USB and boot up the computer.

To migrate your current Home folder to an external partition, there are four things that you need to do:

  1. Mount the external partition onto a temporary Home location.
  2. Copy the files from your current Home folder to this temporary Home folder.
  3. Relocate the current Home folder
  4. Mount the new Home folder.

1. Create a temporary Home folder

Open a terminal and type the following:

This will display the UID of all the partitions. Record down the UUID for the partition that you have created earlier.

ubuntu-get-uid-of-partition

Next, open the fstab file:

and add the following line to the end of the file.

Replace the UUID with the UUID value of the external partition.

ubuntu-new-entry-in-fstab

Save (Ctrl + o) and exit (ctrl + x) the file.

Next, create a mount point:

and reload the updated fstab.

You should now see a “home” folder in the Media directory.

2. Copy the files from your current Home folder to the new Home folder

The next thing we are going to do is to copy all the files from the current Home folder to the new Home folder. You can simply do a “Select all”, “Copy” and “Paste” to transfer all the files to the new Home folder. However, you might be missing out the hidden files and some of the file permissions might not be preserved. A more complete method would be using rsync.

3. Relocate the current Home folder

Once we have set up the new Home folder, we need to remove the existing Home folder to make way for the new Home folder in the external partition. To do that, type the following commands in the terminal:

What the above commands do is to move the existing Home folder to Home_backup, and create an empty Home folder for the new Home folder to mount to.

4. Mount the new Home folder

The last step to complete the migration is to mount the new Home folder as “/home”. To do that, we have to revisit the fstab file again.

All you have to do is to change the “/media/home” to “/home”. Save and exit the file.

ubuntu-mount-new-home-in-fstab

Lastly, reload the fstab file:

That’s it. You have now migrated your Home folder to an external partition.

Optional: removing the Home_backup folder

Once you are done with the migration, you can either use the old Home folder as a backup, or remove it to release the storage space. To remove it, use the command:

Let us know in the comments if you encountered any difficulty.

Image credit: Moving House – Kiwi Style

38 comments

  1. Since Ubuntu 8.04, reinstalling without formatting the existing partitions will save the previous home folder even if it’s all on a single partition.

    • Yes, but that is only when you have set it up properly. In addition, not all ubuntu-based distro retain the same installation process as Ubuntu. I installed one and it wipe out my hard disk entirely.

  2. Damian, thanks a million for this, you obviously work for GCHQ in the UK and have been monitoring my emails!
    I have been researching buying a “small” SSD (say 64Gb) to put my Ubuntu/Linux OS on with the HDD being used for the Home folder. This would do the trick perfectly.
    Thanks again.

  3. This is a really well-written and easy to follow article. Thanks.

    I have found the rsync command you gave has not been transferring all my files (e.g. the .thunderbird directory, which is obviously important I don’t lose).

    Do you have any idea why?

    Thanks.

  4. I use the following procedure to set up my /home partition:
    Since whenever we are to change anything on the HD we should back it up,
    1) I first back up my /home partition to another drive (usually an external).
    2) Then I re-partition the drive, setting up separate “/”, “/home” and swap partitions.
    3) Do a fresh install of the O/S.
    4) Configure the O/S, setting up all the users.
    5) Restore the backed up /home partition to its new location.
    6) Reboot.

    This procedure avoids the use of Terminal and editing of system files. Any error in editing or in issuing a command can result in an unbootable system.

    BTW – I use a Live GParted CD rather than a Live Ubuntu CD. GParted Live loads much faster and goes right into the partitioning screen.

      • It does work. What do you mean “reformat hard disk”? That gets done as part of the re-partitioning process.

        For my next trick I will put the “/” partition on an SSD and “/home” and “/var” on an HDD. :)

  5. kindly let me know how to undo this… it did not work. I get major error on startup and now only starts without my data partition mounted (and does not let me mount it!) thanks.

    • “I get major error on startup”
      What does the error message say?

      “kindly let me know how to undo this… it did not work.”
      You backed up your “/home” before trying to move it, right?
      One way of “undoing this” is to do a fresh install of the distro, letting it do default partitioning. Set up your userids and then restore the files from the backup to the respective “/home/userid/” partition.

  6. Brilliantly clear and easy to follow steps – not all of which I understand which is irrelevant. What puzzles me: HOME is still in the file directory list on the boot partition. On opening HOME (boot) it opens in the the new partition. What concerns me: A new OS install will wipe the Boot partition but won’t deletion of the file link cause the data in the other partition to be deleted as well?? Thank you very much. MaxK

    • The data won’t be deleted. It is just a mounting point. All you need to do is to update the fstab file and it will remount the external partition as Home again.

      When you are install a new Linux distro, you can set the external partition as “/home” and set it to “Do not format”. In this case, you can preserve your data in the home folder.

  7. I used the following to ensure ALL my files where copied over and I could see the progress:
    sudo rsync -avrXS /home/. /media/home/.

    • This was super-easy to follow. My OS is on a 20gig SSD and space was running out, quick. You saved my bacon with this post… Siyabonga :-)

  8. I have 2 older SATA drives, each 300 GB and each with their own distros UBU STudio 12.04.4 LTS 64 bit, and UBU 13.10 64 bit.
    I just installed a new WD SATA drive, 1 TB, partitioned it at 200GB for Windows 7 (now installed first) as NTFS. The remaining I partitioned ext4.
    How can I migrate my 2 Ubuntu OS’s into the new 1TB drive? I intend to follow your suggestions here to:
    1) Move the /home folders of each Ubu OS into its own separate /home folder on its each own partition in the new drive;
    2) Delete the old /home folders;
    3) Migrate the old Ubuntu OS’s to their own separate partitions on the new drive;
    4) Reformat each old SATA drives as ext4;
    5) My goal as an end result would be:
    a) Keep the WIN 7 partition as is with its own world;
    b) Set up each Ubu Distro with its own separate /home folder on SATA #1 (old drive) /home folder, so that any data happening through my everyday use of those distros would automatically save that data in it’s new /home location.
    After all this I will setup SATA #2 as a backup medium, which is another matter that I’m not asking about here.

    Cheers, and any kind of direction/help you can offer I would be grateful.
    ~Leo Newburn
    leokn@yahoo.com

    • Your scenario is pretty complicated. It is easy to move files and folders, but not the whole OS. I would advise you to partition the ext4 into several smaller partitions, then reinstall the 2 Ubuntu OS to each partition. Once you have installed and booted up Ubuntu, you can then transfer files over from the old SATA drive.

  9. Thanks for the timely information. Just one question. What about data that might be somewhere besides the /home directory? and how do you know if there is any elsewhere? I’m thinking of db files or scripts you’ve installed.

    Best Regards,
    Jim

    • It depends on the configuration of each individual application. Most
      applications do store their data in the Home folder. One thing though, as
      long as your file structure is intact, it doesn’t really matter where they
      are stored. You can still access them even though you have changed to a new
      Home partition

  10. Hey Damien,

    First of all, thanks a bunch for this clear tutorial! It seems to work ok, however I get an error whenever I close gedit: ** (gedit:2698): WARNING **: Could not write gedit state file: Failed to create file ‘/home/user/.gnome2/gedit/gedit-2.PWGJBX’: Permission denied

    I believe this has to do with the rights to the home folder? Do you have any idea to what I should change this, given that this is indeed the issue?

  11. This is a very well writen post, thanks. I recommend using:

    sudo rsync -aSXv /home/. /media/home/.

    The [v] for verbose will show users that rsync is still runing if they get an error. Panic might unsue if they think the process has stopped or hung-up causing them to do something silly. Like kill the machine.

    Don’t forget to backup everything before starting this. That can’t be stressed enough.

    My System:
    Mint Linux 14
    1- 2 TB Drive – 2 Partitions – /home /shared media
    1- 500 GB Drive – /
    2- 650 GB Drive in Hardware RAID 1 – /backup (location of all backup files)

    If I want to upgrade the kernel or any failure in the OS I unplug the 2 TB drive and do all the repair or upgrades. Once everything is working properly then reconnect the 2 TB and mount back at /home. Works great! I have a persistant copy of home data going back 12 yrs.

  12. Looks promising.
    I have on question: will your old settings/desktop etc. not break your updated machine? For example: I am on Ubuntu 12.04 and want to update to 14.04, will the settings/desktop settings not break my updated 14.04? How will this works when you want another distro, because all settings, files and desktop will be maintained?

    https://help.ubuntu.com/community/Partitioning/Home/Moving

    “settings, files, and desktop will be maintained if you upgrade, (re)install Ubuntu or another distro.”

    • It shouldn’t break the settings. Only the system files will get updated. The Home folder and settings will still be intact.

  13. Great technique to havea shared storage drive between Windwes and Ubuntu. However, it did not work perfectly for me. The home folders on the left sidebar of Unity are there, but when I click on them I get an error: “Documents” could not be found. Perhaps it has recently been deleted.

    However, my storage drive is now under the home folders, and that’s how I can access my files. How do I make those folders on the left bar represent the folders in the shared drive?

    • Did you check that the “Documents” and all other system folders are in the
      new Home partition? If it still doesn’t work, one of the alternative is to
      create bookmarks for the folder you want to access.

      • After rebooting Ubuntu, I see that the Documents, Picutres, etc. folders from the storage partition are now accessible in /home. But the shortcut folders in Unity have gone back to the default Ubuntu home folders, not the shared partition folder. They are in /home/my-name. It would be nice if they were the same folders as the ones in /home. When I right-click on then, the option of Remove is ghosted out.

  14. How I migrated the data from a HDD with bad blocks to a new HDD.

    I have Linux Mint running in a SDD and the /home folder in a HDD. The HDD developed bad blocks and was under warranty. WD sent me a new HDD to replace my old new 2TB HDD. After much reading and researching online this is what I did:

    First plug the new HDD into a SATA slot in motherboard, then

    1. Boot from linux mint live CD
    2. Open Gparted
    3. Format and partition new HDD. I decided to format as GUID, even though the old HDD was MSDOS with 4 partitions in LVM
    4. Copy-Paste partitions from the old drive to the new drive. This will copy everything – including file structure and UUID. Now you have 2 partitions with the same UUID (recipe for a mess).
    5. Asign new UUID to the old HDD partitions (right click on a partition and select New UUID).
    This will give the old partitions their own random UUID.
    No need to modify fstab.
    6. restart computer normally
    7. to be safe you can compare the old and new HDD with diff or Meld (diff with a nice GUI http://meldmerge.org/)
    6. If you are getting rid of old HDD secure erase everything with hdparm: https://ata.wiki.kernel.org/index.php/ATA_Secure_Erase
    7. Done – now you should have a working new HDD, and a securely erased old HDD ready to ship to WD.

    Hope this helps someone.

  15. Thank you for your tutorial. It saved my a lot of problems and discovery. We just bought 4 disc drive in RAID10 that we will use for sharing files and this does the trick.

    Best regards,
    Blaz

Comments are closed.

Sponsored Stories