Copy Your Linux Install Without Using DD
I know, everyone’s all over dd
and depending on your needs it can be a great tool. However, for a variety of reasons it may not always be what you need. In my case I was migrating my OS to an SSD, and I wanted to upgrade from ext3 to ext4. In spirit this post is no different than the 2009 article on this subject in Linux Journal, but being from 2009 is exactly why it didn’t quite work for me today.
To start, get a live CD and boot into it. I prefer Ubuntu for things like this. It has Gparted. Now follow the steps outlined below.
I don’t think a LiveCD is strictly speaking required, but it’s certainly the safest route. As an aside, using an external USB hard or flash drive typically gives you significantly better performance than a DVD drive.
Copying
- Mount both your source and destination partitions.
Run this command from a terminal:
sudo cp -afv /path/to/source/* /path/to/destinationDon’t forget the asterisk after the source path.
[…]
Configuration
- Mount your destination drive (or partition).
- Run the command “gksu gedit” (or use nano or vi). [I prefer SciTE myself.]
Edit the file
/etc/fstab
. Change the UUID or device entry with the mount point/
(the root partition) to your new drive.You can find your new drive’s (or partition’s) UUID with this
command:$ ls -l /dev/disk/by-uuid/
That’d be the end of what’s still usable. Here’s what you need to know to set up GRUB 2 on the new disk.
sudo mount /dev/sdXY /mnt #most likely something like /dev/sda1 or /dev/sdb1
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
chroot /mnt
Here we mount the relevant partition, chroot into it, and give it access to what Grub will need to set up. chroot
allows you to effectively run multiple systems without needing to reboot. All that should be left now is to install Grub:
grub-install /dev/sdXY
update-grub
Do you love the consistency there as much as I do? Anyway, notice that you need to run update-grub
manually since grub-install
doesn’t do it for you. It sure tripped me up.
In case you’re migrating to an SSD like I did, there are some other adjustments to make, which I’ll write about in more detail soon.