I have a bootable USB-drive with one partiton. The drive is 16GB and the partition is 32 MB. I'd like to create an ISO of the drive (including the boot sector). Using dd, I can either create an image of the partition (which would be 32MB large, but is not what I want, because it won't be bootable) or I can create an image of the entire drive, which would be a huge waste of time and disk space. I tried using clonezilla, but I wasn't able to create an ISO from a clonezilla image.

How can I create a bootable image of my drive without imaging the entire unused part of the drive too? PS: As long as the image is bootable and can be used in virtualbox, I don't really care if it is an ISO or not.


What you want to do is copy the partition table along with the partition. You can achieve that by copying the drive only up to the end of the partition (the table resides in the first sectors).

First, check the exact geometry of your drive. For instance with parted:

# parted /dev/sdb
GNU Parted 3.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit B
(parted) print
Model: blah
Disk /dev/sdb: 1000204886016B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start     End             Size          File system   Name   Flags
 1      2048B     33556480B       33554432B     fat32         Boot

I switched the unit to Byte to have the exact position of the end of the partition. Now with dd, it's a simple matter of copying the right amount of data.

# dd if=/dev/sdb of=drive.img iflag=count_bytes bs=32k count=33556480

That should do it. You'll get the partition along with the partition table at the start. Note the use of count_bytes so we don't have to use a multiple of the block size (so we can use a larger size, which will be faster as long as the cache can hold it).

  • 1
    With GPT you must also fix the backup partition table at the tail end of the drive, if the size of the target drive is [one single bit] different from that of the source drive. You need not do it in the step when the image file is created, but in the next step, when cloning from the image file to a target device. If you do this second step with mkusb, it will be done automaticlly, otherwise you can do it manually with gdisk after the cloning. – sudodus Apr 30 '20 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.