I need to convert this HDD containing a Windows installation to a *.vdi in order to create a bootable *.img WITHOUT the unallocated space.
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 718847 716800 350M 7 HPFS/NTFS/exFAT
/dev/sdb2 718848 105582591 104863744 50G 7 HPFS/NTFS/exFAT
However using VBoxManage convertfromraw /dev/sdb2
creates a vdi of dynamic size but with an unchangeable maximum of 223 GB. VBoxManage modifyhd --resize
can't reduce size at all, VBoxManage modifymedium --compact
also doesn't change it. Writing zeroes with sdelete as suggested frequently is not applicable since it's unallocated space.
Using dd
as suggested in this thread on Server Fault, by creating two images and combining them later, results in a non-bootable image.
So how to exclude that unallocated space of the source HDD?
dd
to image the first ~50.35 GiB of the disk, and create a VDI from that. You need to take all data from the beginning of the disk to the end of partition 2... i.e: 105,582,591 sectors or (typically x512) 54,058,286,592 bytes -dd if=/dev/sdb of=image.dd bs=4M count=54058286592 iflag=count_bytes