Move Installation to new disk

I currently have one hd with these partitions:

/dev/sdb1    /
/dev/sdb2    swap
/dev/sdb3    /home

I'm thinking about buying a ssd for my / partition.

Now my question is: Is it possible to move/convert my current configuration to the new one (two disks, /home remains)? Prefarably from within the running system?


I recommend against using dd. It just does a dumb sector by sector copy, which means it will fail if the destination partition is smaller, and wastes a lot of time copying free space, and if the destination partition is larger, the additional space will not be available until you run resize2fs to expand the filesystem.

It is best to do this from a live CD because if you copy files while they are being modified, you will end up with corrupt results.

Format the ssd and get both the new ssd partition and the original root partition mounted, then just run sudo cp -ax /media/old-partition/* /media/new-partition, where old-partition and new-partition are replaced with their actual mount points. That will copy every file over, preserving ownership, permissions, and timestamps.

Then run sudo grub-install --root-directory=/media/new-partition /dev/SSD_DEVICE, after substituting correct values for new-partition and SSD_DEVICE. That will install grub, making the disk bootable.

Once you reboot (making sure your bios is configured to boot from the ssd instead of the old drive ), make sure that you are running from the ssd and not from the old drive by checking the output of df and/or mount, and you should be good to blow away the old partition.

Oh, and you will want to edit the /etc/fstab file on the new partition after copying and updating the UUID of the root partition to match the UUID of the new SSD partition instead of the old one. You can find that UUID by running sudo blkid.

Edit: added /* in copy above, but needed edit to be more than 6 characters. Now it's 101 characters!


This command:

dd if=/dev/sdb1 of=DEVICE_PATH_OF_SSD_DRIVE

should work for cloning the / partition to the SSD drive.

EDIT: this will only work if your partition is the same size as the drive. If they are not the same size, you can use partimage:

partimage -z0 -d save /dev/sdb1 clone.partimg
partimage restore DEVICE_PATH_OF_SSD_DRIVE clone.partimg
rm clone.partimg

A caveat to this method is that you need enough space on your drive for an image containing all of the contents of /. You should be fine if you have >10GB free. Otherwise, you may use -z1 instead of -z0 to compress the image. For even greater compression, use -z2. Also, partimage does not support the ext4 file system.

Once you have done that, you should then mount the SSD and check if your data has properly copied:

$ mkdir /tmp/ssd
$ sudo mount -t ext4 DEVICE_PATH_OF_SSD_DRIVE /tmp/ssd
$ ls /tmp/ssd
bin    dev   initrd.img      lost+found  opt   sbin     sys  var
boot   etc   initrd.img.old  media       proc  selinux  tmp  vmlinuz
cdrom  home  lib             mnt         root  srv      usr  vmlinuz.old

Replace ext4 with the file system you have used for /.

You will probably need to install the GRUB bootloader on this drive:

sudo grub-install DEVICE_PATH_OF_SSD_DRIVE

You will then need to edit your /etc/fstab file to replace /dev/sdb1 with the device path of your SSD drive in the entry that mounts to /. (sudo $EDITOR /etc/fstab)

Please wait until this answer has a few upvotes before following these instructions. I am not an expert at these things so I may have missed some vital information. Anyone who sees any flaws in this, please add a comment explaining them. You should take such precautions because if something goes wrong, it could leave your computer unbootable.