This website uses Google Analytics and Advertising cookies, used to generate statistical data on how visitors uses this website (with IP anonymization) and to deliver personalized ads based on user prior visits to this website or other websites. [read more]
These cookies are disabled by default until your Accept/Reject Consent.
The Consent can be changed at any time by accesing the ePrivacy button located at the bottom of every page. Enjoy your visit!



How to copy a bootable large disk to a smaller disk

In Linux, cloning a disk (USB/SSD/HDD) is really simple, using dd utility we can make identical copies of one disk to another disk. Basically, the command will be:

sudo dd if=/dev/sdX of=/dev/sdY bs=4M status=progress
help_outline sdX is the source disk and sdY is the destination one. Disk identification (eg sda, sdb, sdc) can be obtained by using sudo fdisk -l and read the result.

If we have a large disk as source (sdX) and a smaller disk as destination (sdY), in order to ensure that the clone operation will succeed and that all used data from source disk will be copied to the destination, including the boot sector, we need to check first that partitions from sdX (and used space inside) will fit into the sdY destination disk.

Case study: if we have a 32GB(sdb) USB/SSD/HDD with two partitions, one of 1GB(sdb1) and one of 31GB (sdb2) and we need to clone this disk into a 8GB one (sdc) then this operation is possible if
a) 8 GB (available space in sdc) - 1 GB (sdb first partition [sdb1]) - 31 GB (sdb second partition [sdb2]) >= 0 and b) unused space from sdb remain "unallocated" and positioned/moved to the end of the disk
In this example, assuming that used data from sdb2 (the 31GB partition from the source disk) is not larger that 7GB all we need is to shrink this partition to <= 7GB and let the remaining space unallocated.

Gparted: disk space on a large disk that need to be cloned into a smaller disk

To do the math, resize/move partition(s), we will use Gparted and if we manage to resize the partitions accordingly then we are ready to go

sudo dd if=/dev/sdX of=/dev/sdY bs=4M status=progress

That’s it, when dd will finish you will have the destination disk bootable and with all the data intact.

label_outline

Share this post on your favorite networks.
© Copyright 2017 b247.eu.org | Just another information technology blog - All Rights Reserved