Ubuntu18.04如何auto start VirtualBox client機?
近日把家中的電腦重裝並上了 Ubuntu 18.04.3 LTS,並把VirtualBox 的其中一個vm設定為開Host機後自動啟動,以下為一些筆記方便以後查閱。
先在 /etc/systemd/system/ 建立一個文件
我把它命名為autostartvbox.service
sudo nano /etc/systemd/system/autostartvbox.service
autostartvbox.service 內容如下
(我都係從網上抄抄貼貼):
[Unit]
Description=Auto Start VM lfhkusvr03vpn
After=network.target vboxdrv.service
Before=runlevel2.target shutdown.target
[Service]
User=rogerli
Group=vboxusers
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/usr/bin/VBoxManage startvm lfhkusvr03vpn --type headless
ExecStop=/usr/bin/VBoxManage controlvm lfhkusvr03vpn acpipowerbutton
[Install]
WantedBy=multi-user.target
然後輸入:
sudo systemctl enable autostartvbox.service
如果中途修改了內容,要先輸入:
sudo systemctl daemon-reload
要測試一下 autostartvbox.service,可執行:
sudo systemctl start autostartvbox.service
再執行以下去查看有沒有Error:
sudo systemctl status autostartvbox.service
備註:
Ubuntu 18.04.3 LTS
VirtualBox 5.2.34