Random thoughts about technology, politics, culture, business, and the intersection of all of the above.

Move your Linux installation to a new Solid State Drive - even a smaller one

Overview

Solid State Drives (SSD) are all the rage these days - and for good reason. They are fast, silent, and have no mechanical parts to go wrong (although firmware bugs can and do bite people).

They are also horribly expensive. For this reason many people who take the plunge buy drives that are smaller than the mechanical drives that they are replacing. This can be a problem. If you are moving to a larger drive, Clonezilla or other imaging programs do a fine job, but moving to a smaller drive can be daunting. If you do a Google search there are articles all over the Web that will give you bits and pieces of advice. The following is a procedure that I know will work, because I just moved my installation from a 300GB hard drive to a 240GB Intel 520 SSD.

First things first - preparation

First of all, make sure that all your data will fit on your new drive. No article in existence can explain how to fit 400GB of data onto a 200GB drive. So check out how much space you are using and start housecleaning. Remember that you want to have some free working space as well.

Second, back up your drive. I said BACK UP YOUR DRIVE! Better yet, download a copy of Clonezilla and image it. Then you can recover from even the worst screwup by restoring the image. Clonezilla, learn it, love it, live it.

Finally, your /etc/fstab file should be using UUIDs instead of device ids to identify drives. Open /etc/fstab, and if you have entries that look like this:

Then start Googling until you can boot with UUIDs. Although I won't cover the difference between device designations and UUIDs in this article except to say that the reason for using UUIDs is that the device IDs and partition numbers on the new drive may not match the old ones, so fstab could be incorrect. Once you can boot with UUIDs, we are in a position to assign new drives the same UUIDs as the old drive had, ensuring that fstab will not have to be edited.

Create and copy your partitions

For this part you will need a Linux Live CD or USB flash drive. Hopefully, you already have one handy in case of emergency. Boot from the live CD or USB flash drive. Attach the old and the new drive to the system.

Ok, here we go.

To copy partitions:

1. Partition the new drive. If you have "/boot" and "/" partitions on the old drive, create them on the new drive.

2. Format the partitions with the same file systems as the old drive partitions.

3. Boot from a live CD or USB flash drive

4. Open a terminal

5. mount the partitions from both the old and the new drives (use "sudo blkid" to see the devices and partitions).

6. For each partition, run:

sudo cp -afv source_mount_point/. destination_mount_point

So for example:

sudo cp -afv /mnt/old_drive_boot/. /mnt/new_drive_boot

7. run "sudo blkid" and make note of the UUIDs of the old drive (open text editor and copy and paste from the terminal).

8. Unmount the old drive partitions ("sudo umount MOUNT_POINT")

9. For each partition, set the GUID to match the ones on the old partitions:

sudo tune2fs -U UUID /dev/sdXX

10. Turn off your machine, remove the old drive and boot from the Live CD/USB again.