Clone hard disk with rsync
I recently wanted to move a system over to a faster, larger SSD. I didn’t want to have to re-install an OS, figure out which old files to transfer over, and then re-configure everything. That’s not a fun time in my book.
Here’s what I did (on a live system, yeah!) to clone my disk. Note that this may cause data loss, don’t blame me, keep backups, blah blah…
First, use a partition tool like GNU parted
to create a nice big partition on the new drive and mark it as bootable. Leave some space for other partitions or swap space. If you use a separate /boot partition, then I think that needs the bootable flag instead. I’m only using a single root partition and swap. For the purposes of this tutorial, I’ll call my new root partition /dev/sdb1. YMMV.
1
2
3
4
|
sudo su -
mkdir d
mount /dev/sdb1 d
rsync -avhPWHAXx / d/
|
Wait a while.
1 |
blkid |
Take note of the UUID listed for /dev/sdb.
1 |
vi d/etc/fstab
|
Or use whatever editor you like and put the UUID for /dev/sdb in place of the existing UUID for /.
1
2
3
4
5
6
7
8
9
10
11
12
|
mount --bind /dev d/dev
mount --bind /sys d/sys
mount --bind /proc d/proc
chroot d
grub-install /dev/sdb
update-grub
exit
umount d/dev
umount d/sys
umount d/proc
umount d
rmdir d
|
Now you should just need to swap out the drives.