Project

General

Profile

VirtualBox

Introduction

Here are miscellaneous techniques used on Debian VirtualBox hosts

Storage

Fix Linux guest file system full

Increasing the size of the .vdi is routine. The challenge is re-partitioning to use the extra space. Most solutions found on the Internet have the guest booting a gparted .iso. A more convenient solution uses qemu's nbd.

  • Ensure the qemu-utils package is installed
  •  
    modprobe nbd
    
  • Ensure the .vdi is not in use
  • Create the network block device (NBD)
    qemu-nbd -c /dev/nbd0 <path of .vdi file>
    
  • Adjust the partition table. Example
    parted /dev/nbd0
    ...
    (parted) print free
    ...
    (parted) resizepart 4 100%
    ...
    
  • If growing the file system on the host instead of the guest, example for partition 4
    e2fsck -f /dev/nbd0p4
    ...
    resize2fs /dev/nbd0p4
    ...
    
  • Disconnect the NBD
    qemu-nbd -d /dev/nbd0
    

Migrating Xen DomU (un-partitioned LV for /) to VirtualBox

Scenario: a Xen DomU using an un-partitioned LV for its / file system and booting via pygrub was to be migrated to VirtualBox.

Converting to .vdi was easy using VBoxManage convertfromraw <path of LV image> <path of output .vdi> --format VDI but no way was found to make VirtualBox boot the .vdi

The workaround was:
  • Add a new .vdi to the VM definition
  • Fresh OS installation to the new .vdi thus creating a conventional bootable partitioned layout
  • Boot the VM from standalone media
  • Sync files from the conversion output .vdi to the new .vdi

systemd: start VMs at host boot and shut down during host shutdown

Script

/usr/local/bin/shut_down_vbox_vm.sh

/etc/systemd/system/vboxvmservice@.service

This is specific to the User= user

[Unit]
Description=VBox Virtual Machine %i Service
Requires=systemd-modules-load.service
After=systemd-modules-load.service

[Service]
User=c
Group=vboxusers
ExecStart=/usr/bin/VBoxManage startvm %i --type headless
ExecStop=/usr/local/bin/shut_down_vbox_vm.sh %i
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Instantiation

Example, for user c's VM aems3.iciti.av

# systemctl enable vboxvmservice@aems3.iciti.av