Skip to content

Instantly share code, notes, and snippets.

@oxagast
Last active December 30, 2025 17:53
Show Gist options
  • Select an option

  • Save oxagast/223d49b45eff08dd92a2faa162e49410 to your computer and use it in GitHub Desktop.

Select an option

Save oxagast/223d49b45eff08dd92a2faa162e49410 to your computer and use it in GitHub Desktop.
Systemd service that starts and stops VirtualBox VMs gracefully.
##
# Place this file in
# /usr/lib/systemd/system/[email protected]
##
[Unit]
Description= Guest VM %I
After=network.target vboxdrv.service
Before=runlevel2.target shutdown.target
[Service]
User=marshall
Group=vboxusers
Type=forking
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment