VirtualBox - split partitioned VDI into separate VDIs

2

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.

mathematical.coffee

Posted 2012-09-04T01:57:54.507

Reputation: 248

Answers

2

Based off @AnsgarWiecher's comment of not being aware of a way to split the file, I did the following:

In virtualbox:

  • select the VM
  • select 'Clone' and 'Full Clone' to create a new .vdi file (it is 25GB though, and contains the dual-boot setup).
  • Boot into this new machine into Arch, and delete the Ubuntu partitions.
  • Resize the .vdi to contain just the Arch partition(s)

This is the new arch-only machine.

Now I can boot up into the original (non-clone) dual-boot machine, and remove Arch from it similarly so that I end up with an Ubuntu-only machine.

mathematical.coffee

Posted 2012-09-04T01:57:54.507

Reputation: 248

3

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

Ansgar Wiechers

Posted 2012-09-04T01:57:54.507

Reputation: 4 860

Thanks - I ended up finding a roundabout/simliar way to do it through VirtualBox – mathematical.coffee – 2012-09-04T03:35:13.880