VirtualBox – split partitioned VDI into separate VDIs

partitioningvirtualbox

I'm very new to VirtualBox. I set up an Arch Linux VM and a Ubuntu VM (Ubuntu host), both sharing the same .vdi like so (I had in my mind a dual-boot situation):

VDI file (25GB)
|- /dev/sda1: 5GB (Arch Linux)
|- /dev/sda2:  [Ubuntu]
    |- /dev/sda5 (swap, 1GB)
    |- /dev/sda6 Ubuntu /, 9GB
    |- /dev/sda7 Ubuntu /home, 10GB

I've now realised that I don't want a dual-boot-type setup, I'd rather boot each machine independently (my initial thought was to share /home between Ubunto and Arch).

So, my question: Can I split /dev/sda1 and /dev/sda2 each to their own .vdi files so I can use them as completely separate machines? I'd rather not have to re-install either Arch (because it took me ages to work it out!) or Ubuntu (because I've already done a few GB of updates and don't want to redo them).

I haven't been able to find anything about this – most questions I see are about converting a .vdi to a partition on the host, or splitting a .vdi into multiple smaller files (that are not independent), or converting a partition on the host to a .vdi file.

cheers.

Best Answer

I'm not aware of a way to split the file, but you could try creating new virtual disks and then rsync the files or dd the blocks from old to new partition. Like this:

modprobe nbd max_part=16

qemu-nbd -c /dev/nbd0 /PATH/TO/YOUR/old.vdi
qemu-nbd -c /dev/nbd1 /PATH/TO/YOUR/new.vdi

dd if=/dev/nbd0p1 of=/dev/nbd1p1 bs=512

qemu-nbd -d /dev/nbd1
qemu-nbd -d /dev/nbd0

rmmod nbd
Related Question