73

I have 2 HDD drives in my computer. At the moment second drive is mounted as /media/storage.

How can I move my user data from /home to /media/storage/home?

Can I just move the data over there and then simply symlink it back?

Eric Carvalho
  • 54,385
Stann
  • 15,116
  • The answer that uses usermod is easiest: create a temp admin user, switch to that account, usermod -m -d /path/to/non_existent_home_dir username, switch back to your account (username), remove temp admin user. Although it is still 5 steps, way fewer than other answers, way less risky and way simpler steps. – Oliver Oct 09 '18 at 23:45

6 Answers6

102

Moving HOME from command line

To avoid side effects while working in a graphical, environment we should perform all actions to move HOME from a terminal with Ctrl+Alt+F1.

Temporarily mount the new partition:

sudo mkdir /mnt/tmp
sudo mount /dev/sdb1 /mnt/tmp

assuming /sdb1 is the new partition for HOME

Copy HOME to the new location:

sudo rsync -avx /home/ /mnt/tmp

We then may mount the new partition as HOME with

sudo mount /dev/sdb1 /home

to make sure all data are present. Easiest is to delete the old /home at this point (you could do this later but then you will have to boot a live system to see the old home):

sudo umount /home    # unmount the new home first!
sudo rm -rf /home/*  # deletes the old home

Make HOME permanent

We need to know the UUID of the new partition for the fstab entry seen from:

sudo blkid

Note or copy/paste the correct UUID to edit your fstab with

sudo nano /etc/fstab   # or any other editor

and add the following line at the end:

UUID=<noted number from above>    /home    ext4    defaults   0  2

Take care to choose the appropriate filesystem here, e.g. ext3 if ext3 formatted

Reboot

After a reboot, your /home resides on the new drive having plenty of space.

AndrewL
  • 103
Takkat
  • 142,284
  • 1
    Did not work for me. – corev Sep 27 '11 at 02:30
  • 2
    I recommend logging out of the profile you want to move, you then can also use the distribution tools like usermod for this task. – LiveWireBT Feb 10 '13 at 10:39
  • It worked! Thanks. Can I remove /mnt/tmp after reboot? – e9t Sep 13 '15 at 06:39
  • @e9t: it is only a mount point we had created to be able to temporarily mount our HOME. It is possible to remove this mount point but it will do no harm (and may be safer) to just keep it. If for any reason you still want to remove it please take extra care to not have anything mounted there (otherwise you risk to irreversibly delete all data you had mounted to /mnt/tmp). – Takkat Sep 13 '15 at 06:57
  • 1
    I followed these instructions for my server and now I cannot access to it via SSH (Permission denied (publickey) :(:(:( – f10w Apr 18 '18 at 11:14
  • 1
    this caused a login loop on 19.04 – Tooniis Oct 19 '19 at 12:30
  • I also got a login loop on 20.04. It turned out that I ended up with my home directory owned by root. I fixed the problem by chowning it back to me. – erik Dec 29 '21 at 11:41
34

If you want to just move your home directory i.e /home/your-username then simply copy your home directory to other partition and then use System->Administration->Users & Groups to open user settings dialog. Click on the keys icon to authenticate your self

alt text

After that select the user that you want to change and click properties, go to advanced tab

alt text

change the home directory to new directory i.e the directory that you copied to other partition.

binW
  • 13,034
  • 3
    Indeed. it is a great way to easily change the home directory location of a specific user. While reading the question, I was understanding that this would have been for the /home directory globally. In this case, you could create the partition on the other device, manually move all files there and then change the device for the mount point in /etc/fstab file itself. – jfmessier Jan 13 '11 at 13:09
  • 3
    @jfmessier: you should make that an answer rather than a comment! – Skizz Jan 13 '11 at 15:19
  • 2
    If you're copying your home directory with 'cp' on the command line, you'd better use 'cp -rPa *' : r for recursive, P for not following links, a for preserving ownership and permission flags. – drevicko Feb 28 '12 at 11:20
  • 2
    Unity in 13.04 has no "Users & Groups", just a "Users" setting that does not include these options. Can you mention the corresponding terms for Unity in 13.04? – Torben Gundtofte-Bruun Aug 08 '13 at 21:57
  • 1
    If your using Ubuntu 12.04 or greater the option to use the GUI method may not be available, at least for me it's not. I had to use this method found here: https://help.ubuntu.com/community/Partitioning/Home/Moving – Kyle Coots Feb 13 '14 at 00:24
  • I would say in the general case not including symlinks is a double edged sword, or at least if you had symlinks in there, you'd not get what you would like by copying without them. – matanox Jun 06 '21 at 11:17
17

The official detailed procedure is here on the Ubuntu help wiki


Find the UUID of the Partition

sudo blkid

Set up Fstab

sudo -H gedit /etc/fstab 

and add these lines into it

UUID=????????   /media/home    ext4    defaults    0  2 

and replace the ???????? with the UUID number of the intended /home partition.

Save and close the fstab file, then type the following command:

sudo mkdir /media/home

Copy /home to the new partition

sudo rsync -aXS --progress --exclude='/*/.gvfs' /home/. /media/home/.

Check copying worked

sudo diff -r /home /media/home -x ".gvfs/*"

Note: You can also expect to see some errors about files not found. These are due to symbolic links that point to places that don't presently exist (but will do after you have rebooted). You can ignore these - but check out anything else.

Preparing fstab for the switch

sudo -H 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:

UUID=????????   /home   ext4    defaults     0  2 

Moving /home into /old_home

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

Reboot or Remount all

Reboot or remount all with this:

sudo mount -a
Zanna
  • 70,465
Steve
  • 171
7

Indeed. it is a great way to easily change the home directory location of a specific user. While reading the question, I was understanding that this would have been for the /home directory globally. In this case, you could create the partition on the other device, manually move all files there and then change the device for the mount point in /etc/fstab file itself

jfmessier
  • 6,126
2

ok, the only way I found this would work is to create another user, give it admin authority, logoff the main id, logon with the new id and then use usermod command.

0

Task:

  • Check availability and format two HDDs: "WD Purple" and "WD Gold".
  • Mount two HDDs to Ubuntu file system.
  • Move HOME folder to "WD Gold" HDD.

Related links:

Format disks

Plugin all necessary SATA and power cables to your HDDs. Load Ubuntu. Press keyboard and type "Disks". "Disks" utility will be opened: enter image description here

In this utility you could format your HDDs into Ext4 file system. Otherwise to format disks use commands:

  1. fdisk (man fdisk);
  2. parted (man parted);
  3. mkfs (man mkfs)

For example, but I'm not sure with parameters because used GUI "Disks":

sudo mkfs.ext4 -L purple /dev/sdb  # not sure with parameters
sudo mkfs.ext4 -L gold   /dev/sdc  # not sure with parameters

Keep in mind, that formatting will delete everything on target hard disk. You can skip this step if there are any data on the hard disk and you want to not lose it.

Slow formatting should take a lot of time: from 16 up to 20 hours for 4TB disk.

Permanently mount disks

# Press CTRL+ALT+T and open a console.
# Check your /dev/sdb and /dev/sdc discs are visible:
lsblk
# Create directories for the new HDD WD Purple and WD Gold
sudo mkdir /hdd_purple
sudo mkdir /hdd_gold  # temporary directory
# Temporary mount to the new mount point
sudo mount /dev/sdb1 /hdd_purple
sudo mount /dev/sdc1 /hdd_gold
# Unmount drives
sudo umount /dev/sdb1
sudo umount /dev/sdc1

# Configuration file /etc/fstab has list of all partitions that will be mounted at boot.
# 1. Show and copy UUID of the HDD with this command:
sudo blkid
# My data is:
#     /dev/sdb1: LABEL="purple" UUID="6ce9ec1f-3bf5-420f-8502-1b4f55f2fc60" TYPE="ext4" PARTUUID="a14c8357-a8ce-42e4-9772-64ccfad3e226"
#     /dev/sdc1: LABEL="gold" UUID="1d049c7c-4565-480b-a181-2459e8ff8c1b" TYPE="ext4" PARTUUID="4c691b21-b4e3-4dab-ab91-d7bf7272b2b5"
# Make a backup of that file to be able to revert changes.
sudo cp /etc/fstab /etc/fstab.2018.11.29.bak
# 2. Add a new partitions by editing /etc/fstab file as root:
sudo nano /etc/fstab
# 3. At the bottom of fstab file add 2 lines similar to this:
UUID=6ce9ec1f-3bf5-420f-8502-1b4f55f2fc60   /hdd_purple   ext4   defaults           0  2
UUID=1d049c7c-4565-480b-a181-2459e8ff8c1b   /hdd_gold     ext4   defaults           0  2
# Your UUID have to be different!
# Write the file with keys <Ctrl+O> then <Return>. Quit the editor with <Ctrl+X>.
# If you have Midnight Commander running, then save before quitting with <Ctrl+X>,
# because <Ctrl+O> will switch from nano editor to your MC.

# To see if the drive is mounted correctly we can simulate the mount process at boot with:
sudo mount -a

Moving HOME from command line

# To avoid side effects while working in a graphical, environment
# we should perform all actions to move HOME from a terminal with Ctrl+Alt+F3.

# Press <Ctrl+Alt+F3> and swidth to console mode.
# Login in the console mode.

# Copy HOME to the new location:
sudo rsync -avx /home/ /hdd_gold

# Delete everything in the HOME directory.
# Be careful with this command, make sure you have a backup.
rm -rf /home/*

# Make HOME permanent -- edit /etc/fstab configuration file
sudo nano /etc/fstab
# Change string
UUID=1d049c7c-4565-480b-a181-2459e8ff8c1b  /hdd_gold  ext4  defaults  0  2
# to string
UUID=1d049c7c-4565-480b-a181-2459e8ff8c1b  /home      ext4  defaults  0  2
# /hdd_golds change to /home directory

# After a reboot, your /home resides on the new drive having plenty of space.
sudo reboot
FooBar167
  • 251
  • 2
  • 6