The easy way
The easy way is to boot from a live installation on a machine where both the old disk and the new disk are connected and copy the data wholesale with cat
. For example, assuming that the old disk is /dev/sdo
and the new disk is /dev/sdn
(make sure you get the device names right — if you copy to the old disk, your data will be lost!):
cat /dev/sdo >/dev/sdn
This assumes that the new disk is at least as large as the old disk. Then enlarge the partition(s) on the new disk to fill it as you see fit.
Some ways that give you more control
If the new disk is larger, you might prefer to first create a partition table, then copy each partition (e.g. cat /dev/sdo1 >/dev/sdn1
). You can skip swap partitions and call mkswap
instead (e.g. mkswap /dev/sdn1
). Once you've copied a filesystem, if the target partition is larger, you'll need to enlarge the filesystem to match to benefit from the added size (resize2fs /dev/sdn1
if /dev/sdn1
contains an ext4 filesystem).
Alternatively, you can copy a partition by copying all of its files. You'll need to create a filesystem on the target partition, mount both the source partition and the new partition (e.g. at /media/old
and /media/new
respectively) and run
cp -ax /media/old /media/new
This may be slower or faster than copying the raw partition depending on how many files it contains.
If you don't copy the disk wholesale, you'll need to install the bootloader on the new disk. A typical way to do this is to mount the new installation on e.g. /media/new
and run
chroot /media/new
grub-install /dev/sdn
but that depends on your bootloader and on your disk configuration. Another possible approach which may be the least painful is to use the “recover bootloader” option from your distribution's installer, if it has one.
Once you've done the copy
Follow the steps in
Moving linux install to a new computer to make the installations different. If you don't do that, you may run into trouble if you keep using the old installation.