How-to resize volume images and import them as HVMs

As mentioned in another thread I would like to provide a short how-to for resizing images of vulnerable VMs which then can be used in Qubes as HVMs.

In your non-Qubes host system:

  1. download the current build of gparted-live (GParted -- Download)
  2. in virtualbox attach the gparted-live.iso as CD to your VM and boot into gparted-live on that VM
  3. resize the VM’s root partition to 6GB, 8GB or what seems feasable, most vulnerable machines should be smaller than 10GB
  4. shutdown VM and make it’s .vdi accessible to Qubes-OS (i.e. on dual-boot systems shutdown non-Qubes host and fire up Qubes-OS)

In your QubesOS:

  1. choose an AppVM with enough storage, attach your block-device which contains the volume with the .vdi, cryptsetup and mount volume i.e. to /mnt
  2. install qemu-img in your AppVM if not present
  3. then
[user@sourceVM ~]$ qemu-img convert -O qcow2 /mnt/home/offsec/virtualbox/binaryVM/binary-disk001.vdi binary.qcow2
[user@sourceVM ~]$ qemu-img resize --shrink binary.qcow2 10G
[user@sourceVM ~]$ qemu-img convert -O raw binary.qcow2 binary.raw

I chose to convert to qcow2 first since I had a few failed attempts with shrinking raw images. This detour might not be necessary.

[user@dom0 ~]$ qvm-run --pass-io sourceVM 'cat "/home/user/binary.raw"' > ./binary.raw
[user@dom0 ~]$ qvm-create -P poolhd0_qubes --property=virt_mode=hvm --property=memory=4096 --property=kernel='' --label blue --standalone --root-move-from /home/user/binary.raw binaryVM
  1. fire up your new HVM, install gparted if not present and expand your HVM’s root partition to 10GB. this can usually be done even if the root partition is mounted.

The entire procedure can (or must) be done with .vdmks (qcow2s and so forth), with different filepaths, with different label, with --root-copy-from instead of --root-move-from and/or without poolhd0_qubes, respectively. Adjust stuff to your environment.