Intro
The following info could come in handy, as most cloning software will not allow you to clone your harddrive to a smaller one, even if the used data is not more than the maximum capacity of the target device.
Here’s how to do it, either manually or scripted.
Disclaimer:
You should always be super carefull when handeling data.
Continue with this guide on your own risk!
Here it is
1. Get partition info
First you must figure out what you want to clone to where.
You must do this thouroughly, because a mistake here will ruin your day and data can and will most certainly be irrecoverably lost.
Figure out which partitions will be your source, and what drive will become their destination.
fdisk -l
For the sake of this example, we’ll use /dev/sda
as source and /dev/sdb
as target.
Ideally, your target drive will be completely clean, with no existing partitions.
2. Resize partitions
Next, you want to resize the partitions on the source disk, so they will fit within the target disk.
This shouldn’t be a problem, as you’ve already made sure all the data will fit on your target drive.
To do this, you may use any tool of your liking, as long is it gets the job done.
Personally I would recommend GParted.
3. Clone partition table using sgdisk
To be safe, create a backup of the partition table on your source disk:
sgdisk -b=gpt.bak.bin /dev/sda
Then, clone the partition table to the new drive:
sgdisk -R=/dev/sdb /dev/sda
4. Clone the partition data
Finally, we can clone the partition data over from the source drive to the target drive:
dd if=/dev/sda1 of=/dev/sdb1 status=progress
dd if=/dev/sda2 of=/dev/sdb2 status=progress
dd if=/dev/sda3 of=/dev/sdb3 status=progress
If everything went well your target drive should now be bootable with all your data there.