Make a dd image restorable to a smaller drive

Suppose I have a 32 GB USB flash drive (UFD) and an 8 GB UFD. I have a 5 GB partition at the start of the bigger UFD, and the rest is unallocated. The problem is to copy the partition and boot sector to the 8 GB UFD using dd or a similar tool. Is this achievable?


If you're sure that the 32GB drive has only one 5GB partition, and that partition is at the start of the drive, or at least it starts under 3GB, dd if=/dev/sdx of=/dev/sdy (where /dev/sdx is the bigger drive, and /dev/sdy is the smaller one), would be enough. To speed up the process or to limit the amount of bytes you copy from one drive to another, you can add bs and count operands (have a look at man dd for more details).

If the 5GB partition ends beyond the exact capacity of your 8GB drive, you can either shrink the partition or move it closer to the start of your 32GB drive.

P.S.: I assumed you're using dd under linux. It may or may not work the same under other OS.