6

Recently I reinstalled ubuntu and created two partitions. The whole system was on an SSD and / home was inside the other partition, in HD. However, I wanted the / home to stay on the SSD and the HD to be a second / home, just for files. Can someone help me?

NOTE: I can not deallocate memory from /home on HD if i have the risk of losing my files. If possible I wanted to create a / home on the SSD and rename the old / home so there is no conflict in the system.

user68186
  • 33,360
  • Do you mean '/ home' as in / and /home or /home itself ? – Liso Jun 03 '19 at 02:15
  • "/home", the folder default – Mateus Silva Jun 03 '19 at 02:19
  • When I partitioned, I put the home to stay on another hard drive, now I want the home to stay on the SSD, and the HD still remains as an accessible memory location. – Mateus Silva Jun 03 '19 at 02:22
  • You can follow the guide at Move home folder to second drive to move your home folder from one spot to another. Substituting locations as needed. You WONT be able to move it to /home immediately as that's already a mounted partition. Once you've moved your home area, you can mount the HD as /mnt/storage and follow the previous guide again, substituting /home as the final destination. – SHawarden Jun 03 '19 at 02:37
  • 1
    Yes. Basically I want to rename the partition from "/ home" to "/ media" and create a new "/ home" in the default location ("/" inside the SSD). – Mateus Silva Jun 03 '19 at 10:07
  • If you think the answer is correct please put the green check mark ✅ next to it. This will indicate your problem is solved, and help others. – user68186 Jun 05 '19 at 14:55

3 Answers3

5

Go from a separate /home partition in the HDD to the default configuration where /home is a folder in /, which is in the SSD

We will do this from a Live USB running Ubuntu 18.04 so that we can work with the /home partition and mount it as /internal_home.

Step 1: Boot from a Live USB Ubuntu

Select the Try Ubuntu without Installing option as we want to run Ubuntu from the USB, not the internal SSD.

Step 2: Find the uuid of the /home and / Partitions

Open a terminal by pressing Ctrl+Alt+T and enter:

sudo blkid > myUUIDs.txt

Keep the terminal open and go to Files (also known as Nautilus) and find the file myUUIDs.txt and open it by double clicking so that you can easily copy and paste the UUIDs of your internal drives' /home and / partitions. You will need them later.

Step 3: Mount the /home and / Partitions

As this is just temporary, it does not matter what the mount points are. You can use Nautilus to click and mount them. However, the autogenerated mountpoints are hard to type. So we will use command line to create 2 mountpoints and mount the two partitions there.

First, make some temporary folders as mount points

sudo mkdir /internal_root
sudo mkdir /internal_home

Second, mount the two internal partitions

I assume:

  • 1234-UUID-OF-SYSTEM-PARTITION is your internal / (root) partition and
  • 1234-UUID-OF-HOME-PARTITION is your current home partition.

Copy and paste the correct UUIDs into the terminal from Step 2 above before using.

sudo mount --uuid 1234-UUID-OF-SYSTEM-PARTITION /internal_root
sudo mount --uuid 1234-UUID-OF-HOME-PARTITION   /internal_home

Step 4: Copy the home folder from its own partition to SSD under /

Use the following command to copy everything in the old /home partition to the new /home folder. Note, you don't need to create the folder as it was created as a mountpoint for the partition.

sudo rsync -aXS --exclude='/*/.gvfs' /internal_home/. /internal_root/home/.

Step 5: Create a new mountpoint for the old home

We need a new pountpoint for the old home so that we can use it to store data I will call it oldhome. Use the following command:

sudo mkdir //internal_root/oldhome

Note: I don't recommend mounting the old home under /media. This folder is usually reserved for the system to autmetically mount partitions temporarily.

An alternate would be to create the oldhome folder under the existing /mnt folder with the command:

sudo mkdir //internal_root/mnt/oldhome

Step 6: Edit /etc/fstab to mount the oldhome automatically when Ubuntu starts

Use the following command to open /etc/fstab in gedit with administrative privilages.

sudo -H gedit /internal_root/etc/fstab

Look for the line like line with the UUID of your home partition. See Step 2 for the UUID. Change it to look like this:

UUID=1234-UUID-OF-HOME-PARTITION  /oldhome ext4 defaults 0 2

where 1234-UUID-OF-HOME-PARTITION is the UUID number of the old /home partition as found on Step 2. Note, in this file we don't include the /internal_root/ prefix as when we created the oldhome folder.

Save the file and exit gedit.

Step 7: Restart the computer and boot to the internal SSD

If all goes well your /home is not in the default location in the SSD.

To access the /oldhome partition with Nautilus you will need to go to Other Locations on the left margin and click on the Computer icon and navigate to oldhome.

Hope this helps

user68186
  • 33,360
  • Thanks, I did this today and it works on Ubuntu 20.04 as well. I had two small issues: 1. SSD did not have enough space, so copying the entirety of /home was not possible in step 4. I ended up copying few essential dot files. 2. After rebooting I got stuck in a login loop, turns out that was because root was now the owner of /home/<username>. A simple chown fixed it as explained in this answer. – Gaurang Tandon Jul 28 '20 at 17:26
  • @GaurangTandon Thanks for the comments. I am glad you were able to solve the problems you encountered. I rechecked the rsync command in the answer. The options -aSX, specifically the option -a should have preserved the ownership of the user folder. This should not have happened. Can you please copy in a comment the exact command you used to copy the files? Thanks. – user68186 Jul 28 '20 at 19:30
  • 1
    Ah, I see. Actually I manually did mkdir and cp to copy over the relevant files, as I did not know this issue could arise :P Thanks for your response btw! – Gaurang Tandon Jul 28 '20 at 19:52
  • Worked for me on MX 19. Thanks for the great tutorial. – shmu Sep 10 '20 at 03:15
  • @shmu I am glad that I could help you. As you know MX is not an official flavor of Ubuntu and is not supported in this site. – user68186 Sep 10 '20 at 15:24
  • Right, that distro is not under discussion here, but still worth a comment, since the principle is the same. – shmu Sep 10 '20 at 19:13
2

I'll try to answer with no-live-boot-required method.

  1. Boot your PC and wait for grub-menu to appear
  2. When in grub menu select the "Default" option and press e key
  3. Edit the line that starts with linux and append init=/bin/bash at the end
  4. press CTRL+x
  5. after root prompt issue mount -o remount,rw /
  6. make new directory for your new home: mkdir /mnt/newhome
  7. mount old home: mount /home
  8. mount new home: mount /dev/ssd_partition /mnt/newhome
  9. copy all the data: cp -rp /home/* /mnt/newhome/
  10. modify the /etc/fstab entry for /home mountpoint accordingly
  11. reboot
  12. profit :)
Roman Spiak
  • 147
  • 1
  • 5
  • on my raspberry pi I was actually able to move a /home folder by logging as root and killing off all the processes in /home path - this is however not advised in a production env :) . – Roman Spiak Aug 22 '20 at 02:29
1

This is a 1y old question but for those coming across...

I Think you miss to delete the old /home which it's still in the filesystem wasting space (have a look at the dimension of the / (root) partition)

so as explained in the other answers copy/sync all files in new partition

you do not need a live image

SYNC

  1. mount the new partition somewhere using the tool you prefer (I used gnome-disks with no root privileges.)

To make your life easy, give to the partition a lable other than a name so that disks will create a mount point using given lable in /media/username

  1. sync
    sudo rsync -aXS --exclude='/*/.gvfs' /home/. /media/my_user/home/.  
  
  1. add new partition in /etc/fstab but comment it out (# at the beginning) for step 5
 # UUID=1234-YOUR-UID  /home ext4 defaults 0 2
  1. To make sure in which home folder I'm looking into, I usually create an empty file (this is optional)

    $ touch /media/my_user/home/blahhhhh 

Free the space no more required

  1. reboot in safe mode and get a root shell (easy, just follow the messages on screen)

  2. look into /home, you should not see file /home/blahhhhh

    $ ls /home 

because the new /home has not been mounted (line in fstab is commented ) instead the portion of / filesystem in available.

  1. if you want to double check your new home partition has all files in it, mount it and look for file /home/blahhhhh

    $ mkdir /new_home $ mount /dev/the_new_home_partition /new_home $ ls /new_home

*you may want to use /dev/dev_name instead the UUID: it is shorter to write.* 
  1. if your are happy... delete all files from old home

    WARNING !!!!! be sure where you are, what are you doing... no way back

         $ rm -fr  /home/*
    

    WARNING !!!!!

the new home candidate partition is still mounted at /new_home

  1. edit /etc/fstab and un-comment (delete #) the entry for /home

      UUID=1234-YOUR-UID  /home ext4 defaults 0 2

8.reboot

  1. check the space partition mounted on / (root)

Try to understand what you are doing... if you mistake, you loose everything...

Joff
  • 11