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?
16 Answers
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/tmpassuming /sdb1 is the new partition for HOME
Copy HOME to the new location:
sudo rsync -avx /home/ /mnt/tmpWe then may mount the new partition as HOME with
sudo mount /dev/sdb1 /hometo 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 homeMake HOME permanent
We need to know the UUID of the new partition for the fstab entry seen from:
sudo blkidNote or copy/paste the correct UUID to edit your fstab with
sudo nano /etc/fstab # or any other editorand add the following line at the end:
UUID=<noted number from above> /home ext4 defaults 0 2Take 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.
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
After that select the user that you want to change and click properties, go to advanced tab
change the home directory to new directory i.e the directory that you copied to other partition.
6The official detailed procedure is here on the Ubuntu help wiki
Find the UUID of the Partition
sudo blkidSet 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/homeCopy /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/fstaband 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 /homeReboot or Remount all
Reboot or remount all with this:
sudo mount -a 0 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
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.
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:
- Terminal method of formatting storage drive -
- Add additional HDD in Ubuntu -
- Move home folder to second drive -
Format disks
Plugin all necessary SATA and power cables to your HDDs. Load Ubuntu.
Press keyboard and type "Disks".
"Disks" utility will be opened:
In this utility you could format your HDDs into Ext4 file system. Otherwise to format disks use commands:
- fdisk (man fdisk);
- parted (man parted);
- 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 parametersKeep 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 -aMoving 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