Table of Contents

VirtualBox

FIXME Upgrade VirtualBox 6.x to VirtualBox 7.x on Ubuntu/Debian

Host

Guest

Guest Additions

Guest Additions for a Debian 9 guest on a Debian 7 host

Autostart and Autostop

There are several options to autostart (and autostop) virtual machines. For a server environment with a Debian host the 1. option through rc.local is preferrable.

  1. through rc.local
  2. through X desktop
  3. through VirtualBox command line

through rc.local

startup

  1. install rc.local as a systemd service on your debian server. This emulates the SysVinit behavior of rc.local as Debian changed the default init system to systemd with Debian Jessie 8
  2. mount encrypted file systems through rc.local as explained in Encrypted partitions/folders with auto-mount
  3. start vms through rc.local headless. Since rc.local runs as root you need to use runuser to start the vm as the user who created the vm. You may also chose to put the startvm code into a script and add execution of the script to rc.local:
    runuser -l <user> -c "vboxmanage startvm <vm-name> --type headless"

shutdown

  1. put a symlink to the following script into /lib/systemd/system-shutdown:
    runuser -l <user> -c "ssh <vm-name> 'sudo systemctl poweroff </dev/null &>/dev/null &'"
    while [ "`runuser -l <user> -c 'vboxmanage list runningvms'`" != "" ]
    do
        echo waiting for VMs to shutdown
        sleep 5
    done
  2. allow <user> to execute command 'systemctl poweroff' in the vm (do not ssh into the VM as root - security!). Note that 'systemctl poweroff' is the systemd command, do not use poweroff or shutdown commands:
    sudo visudo
    <user> ALL=(root) NOPASSWD: /sbin/systemctl poweroff
  3. the scripts must be run as root so they can be executed through rc.local
  4. also, the server must be shut down with systemctl rather than reboot or shutdown for this to work

through XFCE Desktop

startup

shutdown

through VirtualBox command line

  1. Configuration
    sudo vim /etc/default/virtualbox
    VBOXAUTOSTART_DB=/etc/vbox
    VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg
    
    sudo vim /etc/vbox/autostart.cfg
    default_policy = deny
    # Create an entry for each user allowed to use autostart
    username = {
      allow = true
      startup_delay = 10
    }
    
    sudo chgrp vboxusers /etc/vbox
    sudo chmod 1775 /etc/vbox
    sudo usermod -aG vboxusers username
  2. Choose VMs to automatically start and stop
    VBoxManage setproperty autostartdbpath /etc/vbox # first time a user configures autostart only
    VBoxManage modifyvm <vmname> --autostart-enabled <on|off>
    VBoxManage modifyvm <vmname> --autostop-type <disabled|savestate|poweroff|acpishutdown>
  3. Restart VirtualBox autostart service
    sudo service vboxautostart-service restart

Start VM

vboxmanage startvm MachineName

Stop VM

vboxmanage controlvm MachineName acpipowerbutton

In xfce desktop, make sure the action on Power Button is set in Settings –> Power Manager

Stop VM before powering down host through NUT

Set different timeouts to the shutdown command used by NUT. For example, set +0 for the clients, and +1 for the host.

Check running VMs

One of the following commands:

VBoxManage list runningvms
vboxmanage list vms --long | grep -e "Name:" -e "State:"

Links

Update VirtualBox

Links

Manage VirtualBox through CLI

Extension Pack

Run VM

Hold back upgrade

Links