美文网首页
linux下 安装virtualbox,并开机自动启动虚拟机

linux下 安装virtualbox,并开机自动启动虚拟机

作者: 一剑无血冯稀饭 | 来源:发表于2022-04-18 18:34 被阅读0次

Linux

Ubuntu 20.04

  • VMNAME : 这个是虚拟机的名字,注意下面出现的需要替换成你自己的
  • UserName : 这个是用户名,你同样需要替换成你的

运行以下命令

sudo gedit /etc/default/virtualbox

将以下内容填写到文件中

#AutoStarting VMs
VBOXAUTOSTART_DB=/etc/vbox
VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg

运行以下命令

sudo nano /etc/systemd/system/VMNAME.service

将以下内容填写到文件中

[Unit]
Description=vm1
After=network.target virtualbox.service
Before=runlevel2.target shutdown.target
[Service]
User=UserName
Group=vboxusers
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/usr/bin/VBoxManage startvm VMNAME --type headless
ExecStop=/usr/bin/VBoxManage controlvm VMNAME acpipowerbutton
[Install]
WantedBy=multi-user.target

重启daemon

sudo systemctl daemon-reload

测试启动虚拟机,输入完后查看你的虚拟机是否启动

sudo systemctl start VMNAME

启动自动启动虚拟机服务,重启后系统会自动启动虚拟机

sudo systemctl enable VMNAME

如果不需要,禁用自动启动服务

sudo systemctl disable VMNAME

相关文章

网友评论

      本文标题:linux下 安装virtualbox,并开机自动启动虚拟机

      本文链接:https://www.haomeiwen.com/subject/hpndertx.html