VirtualBox Systemd

Run systemctl edit vbox@.service –full –force and paste the following content in, updating User and Group to your username.

[Unit]
Description=Virtual Box Guest %I
After=network.target vboxdrv.service
Before=runlevel2.target shutdown.target

[Service]
User=USERNAME
Group=GROUPNAME
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes

ExecStart=/usr/bin/VBoxManage startvm %i --type headless
ExecStop=/usr/bin/VBoxManage controlvm %i acpipowerbutton

[Install]
WantedBy=multi-user.target
Reload systemd: systemctl daemon-reload

Get a list of your VM’s VBoxManage list vms:

VBoxManage list vms
"Ubuntu" {1ba32309-d4c4-420a-a9c8-a38177f00bc4}
"Windows" {573df054-0e33-4389-896a-1234f10e25ad}

Use the name returned in step 3 to manage the VM via systemd. For example, to manage the “Ubuntu” VM you would run:

sudo systemctl start vbox@Ubuntu     # Start the VM
sudo systemctl enable vbox@Ubuntu    # Start the VM on boot