How to migrate Ubuntu from HDD to SSD


Tips for migrating Ubuntu to SSD

Last week I installed an SSD (Solid State Drive) into my main computer and moved my operating system over from its original location on HDD.

The HDD has multiple partitions, one of which runs Ubuntu 12.04 (Precise Pangolin). The SSD is larger than the Ubuntu partition, but smaller than the entire HDD. (For the record, my SSD was 90 GB and the original Ubuntu partition was 55 GB carved out of a 1 TB HDD.)

I'm recording my experience because, while I found excellent guidance on the web already, several things went wrong for me, and in fact it took me four tries to get it right. These tips should work the same for any recent Ubuntu or with little change for any recent Linux system. You should need no more than basic Linux experience to follow along. (That's what I have.)

I'm assuming you've installed and cabled your SSD.

  • Boot a live Ubuntu CD (or DVD or USB). It's safest to use the same version you used to install your current OS. In my case this was 64 bit Ubuntu 12.04 on a USB stick. 
  • Partition and format the SSD, choosing filesystem ext4. I was successful with GParted. (You may be able to get away with the Disk Utility instead, but one of my failed tries involved Disk Utility so I know GParted works.) You should now have an SSD recognized as something like /dev/sda with one ext4 partition presumably identified as /dev/sda1.
  • Mount both your old and new drives, for example as /media/hdd and /media/ssd. If you've never mounted a drive just cd /media, sudo mkdir hdd and sudo mkdir ssd, then Google how to use the mount command. It's easy.
  • Copy all files from your old partition to your new one. Be sure to include the *, or else you will get an extra, unwanted high level directory on the target:
    sudo cp -ax /media/hdd/* /media/ssd 
  • Change the UUID in your fstab file to comport with the new SSD. 
    • ​Here are 2 ways to find the UUID, either of which works fine
    1. sudo blkid /dev/sda1
    2. ls -l  /dev/disk/by-uuid
    • ​Once you have the UUID, just sudo gedit fstab and copy the new one over the old one. While you're mucking around in fstab I would comment out any other drives that appear; their names could interfere with booting your new SSD, and once you have a clean boot you can uncomment and correct those lines later. For example your former /dev/sda1 may now need to appear as /dev/sdb1 now that /dev/sda1 refers to your SSD. Fix these nits later.
  • Install your boot manager (grub or actually grub2 for any recent Ubuntu) on the SSD. The script here works beautifully, with the clarification shown below, assuming your SSD is identified as sda:
    sudo -s
    for f in sys dev proc ; do mount --bind /$f /media/ssd/$f ; done
    chroot /media/ssd
    grub-install /dev/ssdsda
  • Finally, shutdown, set your BIOS to boot first from the SSD (instead of the live CD/DVD/USB), and try booting

Troubleshooting, gotchas, embellishments, tweaks, ...

Not everything may be working as you expected, or perhaps you want to do some fine tuning. If so, read on.

  • My boot time doubled! :-( Sometimes it even hung midboot. (But if and when it booted the system was considerably snappier.) The fix is to go back to BIOS and look for your SATA controller settings and toggle from IDE to AHCI (Advanced Host Controller Interface). My boot time then halved! :-)
  • If, like me, your old HDD had several other important partitions such as data partitions, you may need to go back to your fstab and make appropriate changes. Start by clicking around the Disk Utility to see what the proper device names are because they may have changed. At most you may need to tweak devices like /dev/sda2 to /dev/sdb2 and so on. After saving the changes to fstab check your work with sudo mount -a.
  • If your SSD doesn't even come close to booting, make sure in your zeal to be tidy you didn't delete lost+found after you formatted your SSD. There may be a way to get it back and achieve bootability, but I ended up re-doing the entire procedure from scratch.
  • To (theoretically) increase the longevity of your SSD as well as (theoretically) improve performance, you can consider these additional tweaks. Add the 3 parameters discard,noatime,nodiratime in fstab so the tail end of the line for your SSD looks something like:
    ... ext4    discard,noatime,nodiratime,errors=remount-ro 0       1

    discard enables TRIM, which prevents performance degradation, noatime prevents writing an event on disk every time you merely read a file, and nodiratime similarly eliminates a write every time you read a directory.

  • Move your /tmp from disk to RAM to reduce wear and tear on the SSD, assuming you have plenty of RAM. I found this tweak here.
    tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0


Пожалуйста оцени моё видео на ютубе

Please rate my video on YouTube

Test, just a test

Hello. And Bye.dd

The scripts looks kinda quick

The scripts looks kinda quick to apply. I just came up with my project ( ) a home based project to do a host on my own.

oh thanks man!!!!!!!!!

Worked really good. It's making life easier to creat the mount folders. I unfortunatly didn't do it and had to fiddle about it a bit but it worked out well.

Using the default mount folders you will be ending up with soething like /media/uuid so lines are getting long.

You made my day!

Edit: don't forget to enable the swap partition after booting in the migrated system.

Linux Mint 15 now on SSD

Your article was very clear and concise, it really helped me when installing Linux on a new SSD.

A few notes:
* if your drive is brand new, you'll have create a partition table before you can partition it; it's easy to do in gParted and the default MsDOS format is fine
* when partitioning, align to the MiB (not the cylinder) and leave 1 MiB preceeding (to align the SSD), this should be the default option
* on Mint, the path to the other drives was /media/mint/ssd