【发布时间】:2020-11-18 01:33:05
【问题描述】:
我正在尝试使用以下 while 循环来实现以下目标:
- 循环中的第一个命令是只运行一次安装。
- 第二条命令是在没有ISO文件的情况下正常运行VM。
你能告诉我实现这一目标的正确方法吗?
代码:
# The VM loop
while true; do # Start the installation
bhyve -Hw -c ${cpu} -m ${ram}G \
-s 0,hostbridge \
-s 1,virtio-net,${tap} \
-s 2,virtio-blk,/dev/zvol/zroot/VMs/${name}/disk0 \
-s 3,ahci-cd,${FreeBSD_ISO} \
-s 29,fbuf,tcp=0.0.0.0:${vnc},w=1024,h=768,wait \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/zroot/VMs/efi.fd \
${name}
exit=$?
if [ $exit -eq 0 ]; then
bhyve -Hw -c ${cpu} -m ${ram}G \
-s 0,hostbridge \
-s 1,virtio-net,${tap} \
-s 2,virtio-blk,/dev/zvol/zroot/VMs/${name}/disk0 \
-s 29,fbuf,tcp=0.0.0.0:${vnc},w=1024,h=768 \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/zroot/VMs/efi.fd \
${name}
elif [ $exit -ne 0 ]; then
break;
fi
done > /dev/null 2>&1 &
bhyve 的退出状态。
0 重启
1 关机
2 停止
3 三重故障
4 因错误退出
【问题讨论】:
-
请edit您的问题并添加更多详细信息:假设脚本不起作用,请描述实际发生的情况以及您希望发生的情况。复制并粘贴实际输出和/或错误消息,并显示预期的输出(如果有)。