笔者在Ubuntu系统中安装了virtalbox,然后再virtualbox中安装了虚拟机(假设虚拟机名为abc),希望在Ubuntu系统开机后,virtualbox中的虚拟机能够自动启动。则相关的修改操作如下:
vim /etc/systemd/system/abc.service
[Unit]
Description=abc
After=network.target virtualbox.service
Before=runlevel2.target shutdown.target
[Service]
User=root
Group=vboxusers
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/usr/bin/VBoxManage startvm abc --type headless
ExecStop=/usr/bin/VBoxManage controlvm abc acpipowerbutton
[Install]
WantedBy=multi-user.target
上述代码保存之后,使用如下命令启用生效:
sudo systemctl daemon-reload
sudo systemctl start abc
sudo systemctl status abc