Clone larger disk into smaller one with dd


Clone larger disk into smaller one with dd

´╗┐Please make sure to backup your data before attempting to try this method. Use at your own risk .

I recently had to clone a disk of 250GB capacity into an other one of 80GB capacity . The first disk had about 30GB of used space divided into 2 partitions .
I tried using clonezilla using the option -lcds as many suggested, but without luck .
however the dd command saved the day .

I placed both disks in the same computer, and then booted into an Ubuntu live CD, the fdisk -l chose the following results :

So the goal is to clone the sda drive into sdb. In my case it will translate into cloning the first 30GB .

dd command uses the number of sectors and their count  instead of number Gigabytes :

30 Gigabytes =  32212254720 Bytes
Our sector size is 512 Bytes, so 32212254720 / 512  = 62914560 sectors .

We will formulate the dd command as follow :

Be extra careful of the disks labels, to not switch them up, dd will give no confirmation ! .

So this will translate into copying 62914560 sectors of 512 Bytes , which should be 30 GB . 
Now  we have to wait for the copy to complete.

While this should be enough in most cases, in my case i wasn't able to boot using the cloned disk, it was something to do with the GPT table wasn't correctly copied . To fix that with can copy it as well from the original disk using these 2 sgdisk commands :

If you check fdisk -l  again , you should see that the target disk has 2 partitions similar to the original disk :


Comments :