{"id":333,"date":"2024-01-18T17:08:16","date_gmt":"2024-01-18T15:08:16","guid":{"rendered":"https:\/\/amsd.go.ro\/wordpress\/?p=333"},"modified":"2024-01-18T17:08:16","modified_gmt":"2024-01-18T15:08:16","slug":"start-a-virtualbox-vm-on-boot-with-systemd","status":"publish","type":"post","link":"https:\/\/amsd.go.ro\/wordpress\/?p=333","title":{"rendered":"Start a VirtualBox VM on boot with Systemd"},"content":{"rendered":"\n<p>1. Add your user to vboxusers group.<\/p>\n\n\n\n<p><code>sudo usermod -a -G vboxusers $USER<\/code><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>2. Systemd template unit to start and stop VirtualBox VMs<\/p>\n\n\n\n<p>The systemd template unit to start and stop a VirtualBox VM when booting up and down a PC looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[Unit]\nDescription=VirtualBox VM %I\nAfter=network.target vboxdrv.service\nBefore=runlevel2.target shutdown.target\n\n[Service]\nUser=admin\nGroup=vboxusers\nType=forking\nRestart=no\nTimeoutSec=5min\nIgnoreSIGPIPE=no\nKillMode=process\nGuessMainPID=no\nRemainAfterExit=yes\n\nExecStart=\/usr\/bin\/VBoxManage startvm %i --type headless\nExecStop=\/usr\/bin\/VBoxManage controlvm %i acpipowerbutton\n\n[Install]\nWantedBy=multi-user.target<\/pre>\n\n\n\n<p>As a final step to complete the installation of the systemd service unit, we need to edit the file to change the <em>User<\/em> setting. The first line in the <em>Service<\/em> section now reads:<\/p>\n\n\n\n<p><code>User=admin<\/code><\/p>\n\n\n\n<p>Save the file with this path and name:<\/p>\n\n\n\n<p><code>\/etc\/systemd\/system\/vbox_vm@.service<\/code><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>3. Enable the Systemd service for your VirtualBox VM<\/p>\n\n\n\n<p>With the systemd template unit in place, we can enable the systemd service for a particular VirtualBox VM. All we need is the name of the VirtualBox VM. You can open up VirtualBox and read the name of the VM on the main screen. Alternatively, you can run the following command in the terminal to obtain a list with available VMs:<\/p>\n\n\n\n<p><code>VBoxManage list vms<\/code><\/p>\n\n\n\n<p>To enable the systemd service unit for this VM, based on our systemd template unit, we can use this command syntax:<\/p>\n\n\n\n<p><code>sudo systemctl enable vbox_vm@&lt;name of VM><\/code><\/p>\n\n\n\n<p>We just need to replace <code>&lt;name of VM><\/code> with the name of our VM.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>4. Verify that Systemd started your VirtualBox VM<\/p>\n\n\n\n<p>After rebooting your PC, Systemd should have started your VirtualBox VM, but how to verify this? If your VirtualBox VM runs an SSH server you could of course attempt to connect with it. Alternatively, you can open up the VirtualBox user interface, which indicates if a VM runs or not.<\/p>\n\n\n\n<p>Executing the <code>systemctl<\/code> command from the terminal offers another method, which provides more information. Its format is:<\/p>\n\n\n\n<p><code>sudo systemctl status vbox_vm@&lt;name of VM><\/code><\/p>\n\n\n\n<p>So pretty much a similar command syntax as for enabling and disabling the systemd service. Just to check the status you can run this command:<\/p>\n\n\n\n<p><code>sudo systemctl status vbox_vm@&lt;name of VM><\/code><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Enjoy!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Add your user to vboxusers group. sudo usermod -a -G vboxusers $USER 2. Systemd template unit to start and stop VirtualBox VMs The systemd template unit to start and stop a VirtualBox VM when booting up and down a [&hellip;]<\/p>\n<div class=\"link-more\"><a href=\"https:\/\/amsd.go.ro\/wordpress\/?p=333#more-333\" class=\"more-link\">Continue reading &#10142; <span class=\"screen-reader-text\">Start a VirtualBox VM on boot with Systemd<\/span><\/a><\/div>","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10,19,11,12,30],"class_list":["post-333","post","type-post","status-publish","format-standard","hentry","category-technology","tag-ps_32","tag-ps_60","tag-ps_57","tag-ps_17","tag-virtualbox"],"_links":{"self":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=333"}],"version-history":[{"count":1,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/333\/revisions"}],"predecessor-version":[{"id":334,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/333\/revisions\/334"}],"wp:attachment":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}