0

I am in the process of migrating windows installation to a VM. On the physical device with windows, there are two partitions: /dev/sda1 and /dev/sda2. There's also a large amount of free space following the second partition.

I can create a virtual disk off the full /dev/sda easily with this command:

cat /dev/sdg | VBoxManage convertfromraw stdin OutPutFile.vdi NUMBEROFBYTES

However this will create a huge file, which will include all the free space. I want the file to only include the two partitions. How can I do this? Alternatively, is there an option to resize down the virtual disk after it's created?

2
  • Why not shrink the partition first? Jan 26, 2015 at 17:58
  • @Ƭᴇcʜιᴇ007 The partition is already the correct size. I don't want to include the non-partitioned space in the file.
    – Aleks G
    Jan 26, 2015 at 18:40

1 Answer 1

0

Apparently, it's all quite easy. Here's what my partition table looked like:

   Device Boot       Start           End       Blocks   Id  System
/dev/sdb1   *         2048        526335       262144    7  NTFS
/dev/sdb2           526336   92342323199  46170898432    7  NTFS
Unpartitioned  92342323200  234076243969  70866960384

I could create a virtual disk from this entire physical disk with the command:

cat /dev/sdg | VBoxManage convertfromraw stdin OutPutFile.vdi 117038121985

This would create a virtual disk with the two NTFS partitions and another 66 GB of empty space. As I didn't want the empty space, all I had to do was to specify the NUMBEROFBYTES to be the two partitions I needed (plus I added a little extra to be on the safer side). This command:

cat /dev/sdg | VBoxManage convertfromraw stdin OutPutFile.vdi 46171161600

would create the virtual disk with just the two partitions.

You must log in to answer this question.

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