Migrate from a HDD to a SSD hard disk




# hardware connect
I plugged my new SDD (256G) through a USB-SATA adapter to my running Unbuntu system.
After that, I checked if the system recognizes the new hardware:

	$ dmesg | grep sd[a-z]	# assuming SATA

In my case it was the third SATA device "sdc"

# partitioning and file system creation
The next steps can be done manually with fdisk and mkfs, but if you have gparted installed I recommend to use it:

	$ sudo gparted /dev/sdc		# replace "sdc" with your recognized hardware

My old running Ubuntu system has a dedicated /boot partition - I decided against this in my new environment.
I create one big root partition (labeled as SSD) and a 4G swap partition within gparted.
The recommended root filesystem for SSD devices in Linux is ext4 (Nov 2013), because of its implemented ATA Trim features.
You can check your SSD for ATA Trim support with hdparm:

	$ sudo hdparm -I /dev/sdc | grep TRIM
           *    Data Set Management TRIM supported (limit 16 blocks)
           *    Deterministic read ZEROs after TRIM

Finally my SSD device partition table looks this:	

	$ sudo fdisk -l /dev/sdc
	Disk /dev/sdc: 256.1 GB, 256060514304 bytes [...]
	Gerät    boot.     Anfang        Ende      Blöcke   Id  System
	/dev/sdc1            2048   491728895   245863424   83  Linux
	/dev/sdc2       491728896   500117503     4194304   82  Linux Swap / Solaris

# mounting the SSD

	$ sudo mkdir /mnt/ssd
	$ sudo mount /dev/sdc1 /mnt/ssd/

# initial sync
Before an initial sync, I recommend to do some cleanup work. 
This may include deleting unneccessary files, folders, test-, temp- or cache files.
In my case, I had to remove some "bind" mounts from other file systems.

rsync is the tool of my choice to sync data from a running linux system to the SSD.
It is important to exclude some system folders. 
I do rsync with the "-a" (archive mode) and the "-P" (--partial --progress) option, 
my running root as source and /mnt/ssd/ as destination:

	$ rsync --exclude="mnt" --exclude="lost+found" --exclude="sys" --exclude="proc" --exclude="cdrom" -aP / /mnt/ssd/

This can take a while, depending on HDD size and performance.
I transfered approximatly 20GB.

	# create system directories
	$ mkdir /mnt/ssd/{mnt,proc,sys}

After this, I did a break and continued one or two days later.

As I plugged in my SSD, Ubuntu OS recognized and mounted the file system automatically.
Attention: Ubuntu's default mount directory is /media, so I had to exclude it in my next last sync too:

	# final sync
	$ rsync --exclude="mnt" --exclude="media" --exclude="lost+found" --exclude="sys" --exclude="proc" --exclude="cdrom" -aP / /media/SSD/


# prepare /etc/fstab
You can build your new /etc/fstab file with /dev/sdX entries or you can use universally unique identifiers (UUIDs).
I decided to use UUIDs - a more robust way to name devices, that works even if disks are added and removed. See fstab(5). 
To get your new UUIDs from your SSD, you can do the following:

	$ sudo blkid /dev/sdc1		# for root partition
	$ sudo blkid /dev/sdc2		# for swap

It is recommended to modify the mount options for SSDs.
To enable TRIM you have to set the "discard" option.
It is also recommended to disable read-logging by appand the options "noatime" and "nodiratime".

My /etc/fstab looks like this:

	$ head /etc/fstab
	# file system		mount point	type  	options						dump	pass
	proc			/proc           proc    nodev,noexec,nosuid				0       0
	UUID=5d8[...]abe	/               ext4    discard,noatime,nodiratime,errors=remount-ro	0       1
	UUID=a01[...]4cc	none            swap    sw						0       0
	
In a next step, some system directores have to be mounted:

	$ sudo mount -o bind /dev	/media/SSD/dev 
	$ sudo mount -o bind /sys 	/media/SSD/sys 
	$ sudo mount -t proc /proc	/media/SSD/proc 

Because we want to install Grub on the SSD, we have to provide an up-to-date /etc/mtab file:

	$ sudo cp /proc/mounts /media/SSD/etc/mtab 

The next step is very usual for gentoo linux user, because they need it for installing a gentoo base system -
also Unix/Linux veterans will know about it. Modern Ubuntu users are likely not very familiar with this process.
Enter the new system on the SSD by doing a change root command:

	$ sudo chroot /media/SSD /bin/bash 

Now Grub should be installed on the SSD:

	$ grub-install /dev/sdc
	$ grub-install --recheck /dev/sdc		# only in case of errors in the step before

	$ update-grub 

It's done! With Ctrl-D the chroot environment can be left now.

Finally stop your system, install your SSD in your computer and modify your BIOS (change boot order) to boot from your SSD.

Voila! Now, open a beer and enjoy your new system!!
 


by Markus Sesser