How to transfer Ubuntu to SSD, but keeping home on HDD?
I would like to transfer my existing Ubuntu Trusty (14.04.1) system (including installed apps from PPAs) to an SSD. I want to retain my existing home directory on hard disk). What is the best method, preferably ones that doesn't involve reinstalling Ubuntu?
Solution 1:
When booting from live media, this can be broken down into 3 steps:
-
Copying the operating system data to the new drive
Before you start, make shure that the new drive has the correct partition table. GPT is (mostly) for EFI and requires a special partition for the bootloader. Don't forget to mark the new operating system partition as bootable on MBR installs.
Using rsync from live media should be the most practical solution to copy the files:
sudo rsync -av --exclude=/home/* /media/$mountpoint_of_old_drive/ /media/$mountpoint_of_new_drive/
-
Install the bootloader to the new drive
sudo grub-install --boot-directory /media/$mountpoint_of_new_drive/boot /dev/sdX
/dev/sdX
should be changed to the actual device name of the new drive.If you have an EFI installation instead of MBR you should make sure that you booted the live media in EFI mode, ran
sudo apt-get install grub-efi-amd64
, have created an EFI System Partition (ESP) on the new drive and that the ESP is mounted to/media/$mountpoint_of_new_drive/boot/efi
(or use the--efi-directory
option, have a look at the grub-install manpage). -
Update the configuration
You need to update the UUID in
/etc/fstab
for/
. Get the UUID of the new operating system partition by executingsudo blkid /dev/sdXY
, copy the UUID without quotation marks, runsudo nano /media/$mountpoint_of_new_drive/etc/fstab
and replace the existing UUID in a line that looks like this:# / was on /dev/sda2 during installation UUID=a7aea81b-0e7f-4ec0-8be4-b0ec75c13fdc / ext4 errors=remount-ro 0 1
But before you replace the line you may want to make a copy of it by pressing Ctrl+K and Ctrl+U. As your home is still on the old drive, the old UUID should be correct and you would just need to update the mountpoint to
/home/$your_username
(replace$your_username
with the name of your user's home directory) and some options (pay attention torelatime,acl
and2
at the end):# Mountpoint for home or user partition UUID=063a996a-0303-42b2-b719-af920fd105fa /home/$your_username ext4 relatime,acl 0 2
Save with Ctrl+O and exit with Ctrl+X.
You should think about moving the individual home directories to a separate
home
-partition (it's just a partition with user's home directories mounted as/home
infstab
, you can usesudo rsync -av
again to copy data, see How can I move my /home directory to another partition if it's already part of the / partition?), as you would have to create a new line for each user this way.If you created a new swap partition on the SSD you have to update the UUID for this too:
# SSD swap UUID=b7c315cb-cf89-463b-888a-185a1faa8250 none swap sw 0 0
Additionally you need to update the UUID of the swap partition in
/media/$mountpoint_of_new_drive/etc/initramfs-tools/conf.d/resume
, runsudo update-initramfs -k all -u
after booting from the new drive the first time and reboot to have hibernation working again.Remember to also update the mountpoint for the ESP in fstab too for EFI installs.
Looks complicated, but it's simple to do, just difficult and lengthy to describe in detail.
Troubleshooting
grub-install somehow fails to install with UEFI
Hint: You probably forgot to run sudo apt-get install grub-efi-amd64
when GRUB says something about i386-pc
.
- You copied the content of your root (
/
) partition including/boot
, right? -
You copied the content of your ESP? Do that if you havent.
-
Edit
EFI/ubuntu/grub.cfg
on the new ESP. Replacing the UUID with the UUID of the new root partition should be sufficient, if not change thehd0,gpt2
part from this example accordingly too. This is how the content of file usually looks like:search.fs_uuid a7aea81b-0e7f-4ec0-8be4-b0ec75c13fdc root hd0,gpt2 set prefix=($root)'/boot/grub' configfile $prefix/grub.cfg
-
-
Boot from your old installation, run
sudo update-grub
, os-prober should find the new installation on the other partition and add a GRUB entry.- Boot this new entry.
- You should be booting now from the SSD, run
sudo update-grub
here again to update and fix the GRUB configuration on the SSD.
- Run
efibootmgr -c -d /dev/sdX -p Y -l \EFI\ubuntu\grubx64.efi -L "Ubuntu"
to add the boot loader for new/transferred installation as a new boot option to UEFI NVRAM./dev/sdX
is the device name of the new harddrive,Y
the partition number.