Saturday, February 28, 2015

Linux Mint: Move your home-directory into a separate partition after installation

Objective


I installed Linux Mint 17.1 Rebecca on new computer with a SSD with the Mint Installer default partitioning scheme, which mounts /boot, /root and /home into the same partition.

Motivation


I decided to have my home-directory in a separate partition which I can mount into /home to make leter upgrading the system a little more painless.

Prerequisites


  • Linux Mint 17.1 Rebecca
  • 512 GB SSD

Solution


Create a new partition


Resize your system partition and create a new partition in the free space. Follow this guide to see how you can resize Ubuntu partitions to complete this step.

Copy the home files into the new partition


Open a terminal and run the following command to create a copy of your current /home directory on the new partition, where /media/HOME is the location of your newly mounted partition (I gave it the LABEL=HOME during the creation process) where the new /home should reside:

$> sudo cp -Rp /home/* /media/HOME

You should check if everything went fine to avoid to loose data:

$> ls /media/HOME

In my case I got:

csch data lost+found

Determine the UUID of the newly created partition


Use the following command to get the UUID of your new home-partition:

$> sudo blkid

In my case I got (you can see the label HOME again here)

...
/dev/sda2: UUID="f270b74b-ce14-4481-bf32-1226b4fd776e" TYPE="ext4"
/dev/sda3: LABEL="HOME" UUID="a9c81163-f588-462a-89b0-dbdad87cef9c" TYPE="ext4"
/dev/sda6: UUID="023cf9e6-199f-475c-9fe1-c70b73d3047c" TYPE="swap"
...

Adapt your mount table in fstab to mount the new partition into "/home"


Make a backup of your current fstab (with a timestamp):

$> sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d)_backup

and edit the original fstab:

$>gksu gedit /etc/fstab

Add this line to your fstab and save the file (replace xxxxx with your UUID):

...
# (identifier) (location) (format, eg ext3 or ext4) (some settings)
UUID=xxxxx /home ext4 nodev,nosuid 0 2

Move home-directory into a backup and create a new mount-directory


$> cd / && sudo mv /home /old_home && sudo mkdir /home

Now you're done, finally reboot and prey!

$> sudo shutdown -r now

After your system is up again, you can savely clean-up the system:

$> sudo rm -rf /home_old

Remark

Additional info on how to deal with separate home-partitions can be found here.

4 comments:

  1. Thanks very much! Before reading this tutorial I saw some other ones that were much more complicated and some people actually suggested just reinstalling Linux. LMAO! Not doing drastic things like that for basically trivial tasks is one of the reasons I'm switching to Linux.

    I am using Linux Mint Cinnamon 18.1 x64.
    The only thing that didn't match with the tutorial is: when I formatted the partition as HOME, for some reason it didn't mount at /media/HOME. It mounted as: /media/[username]/HOME
    It was probably something I did wrong. But just in case, if someone following this tutorial gets that issue, I had it too.
    The solution is simple. Whenever it says "/media/HOME" in the tutorial, I just typed "/media/[username]/HOME" instead.
    Obviously you have to replace [username] with your Linux username.

    Thank you so much for this easy and accurate tutorial. So far, in late May 2017, it's still current. You rock Christian!

    ReplyDelete
    Replies
    1. Thanks! Great to hear that the article was useful to others. I started this blog as a reminder to myself about "how things worked".
      Maybe Mint does now auto-mounting (by clicking in the file-explorer) in a user-specific way now below the "" sub-directory in "/media/". I think, I did an explicit "mount" into "/media/HOME" at that time, though.

      Delete
  2. Thanks from me as well! This worked well and was much less complicated than other guides I've seen. I added a 1TB HDD to a mini PC that only included a 32GB MMC drive; now I have plenty of room for my files.

    ReplyDelete