Ubuntu – Convert bootable USB stick to ISO file

bootisousb

I am trying to get an ISO file from a bootable USB memory stick. The device name for the stick is dev/sdf1. In this answer: Convert bootable USB to ISO file , dd was suggested for copying. So I did:

sudo dd if=/dev/sdf1 of=win7.iso

However, the stick has a size of 30G, but only 12G are used. Running the command above, it creates an iso image larger than 12G, I stopped dd when the file was > 20G, since I ran out of disk space.
Is it normal that the ISO file gets so big or is there another way to achieve my goal?

Best Answer

dd is a 1:1 copy, it copies the entire device regardless what's on it. If you only copy a partition (sdf1) it's unlikely to be bootable as the bootloader usually resides on sdf MBR.

If the free space is zeroed, you could save the free space by use of gzip.

To zero the free space, you may use:

mount /dev/sdf1 /mnt/tmp
dd if=/dev/zero bs=1M | split -b 1G - /mnt/tmp/zerofile
sync
rm /mnt/tmp/zerofile*
umount /mnt/tmp

To create a gzip compressed image:

dd if=/dev/sdf bs=1M | gzip > win7.img.gz

To restore from that image, it's:

gunzip < win7.img.gz | dd of=/dev/sdf bs=1M

Other alternatives are partimage or ntfsclone (in case of ntfs), which only store files, not free space, however the result may not be bootable as it's not a 1:1 copy.

Related Question