ubuntu上使用systemd开机启动某个虚拟机
1、首先“sudo apt install xvfb”安装界面工具
2、“sudo vim vmwarestart.sh”,创建启动shell脚本,填写以下内容
#!/bin/bash export DISPLAY=:1 Xvfb :1 -screen 0 1024x768x16 & sleep 1 vmrun start "/home/user/vmware/Debian 10.x 64-bit/Debian 10.x 64-bit.vmx" nogui
3、“sudo chmod +x vmwarestart.sh”授予权限
4、“sudo vim vmwarestop.sh”,创建停止shell脚本,填写以下内容
#!/bin/bash vmrun stop "/home/user/vmware/Debian 10.x 64-bit/Debian 10.x 64-bit.vmx" nogui
5、“sudo chmod +x vmwarestop.sh”授予权限
6、“sudo vim /etc/systemd/system/auto_run_vmwarestart.service”创建服务,填写以下内容
[Unit] Description=Run a VMware Script at Startup After=network.target vmware.service [Service] Type=forking ExecStart=/home/user/vmwarestart.sh ExecStop=/home/user/vmwarestop.sh [Install] WantedBy=default.target
7、"sudo systemctl daemon-reload" 刷新服务
8、“sudo systemctl enabled auto_run_vmwarestart.service”设置为开机自动启动