2

I need to convert this HDD containing a Windows installation to a *.vdi in order to create a bootable *.img WITHOUT the unallocated space.

this HDD

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?

2
  • 1
    Do you have space to store a ~50.35 GiB image? If so, you could use 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
    – Attie
    Commented Sep 30, 2018 at 21:12
  • 2
    Thank you attie for your help! I didn't think of going down the dd road. As to your suggestion the only flag I used was count=10582591 since setting the blocksize parameter to 4M doubled the resulting image's size. Feel free to paste your post as answer and I'll mark it as solved. Cheers.
    – maxwhere
    Commented Oct 2, 2018 at 0:28

1 Answer 1

3

As the partitions are both at the front of the disk, you could just image that portion of the disk.

Try using dd:

dd if=/dev/sdb of=image.dd bs=4M count=54058286592 iflag=count_bytes

Here, count is equal to the number of bytes to be imaged - parition 2's end, ×512 (size of a sector).

To then allow a larger block size (increase transfer rate), you must indicate that your count argument is in "bytes" and not "input blocks" (as it would be by default) - use iflag=count_bytes.

1
  • Clean, simple, and works perfectly. Thank you. Just make slightly larger than the used disk space (presuming used space at front of the disk's blocks).
    – M. K.
    Commented Apr 12, 2022 at 22:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .