Hello to everyone.
I like to play with the bhyve virtual machines in FreeBSD a lot. As you probably know,sometime when the OS loaded by the virtual machine is halted,the bhyve virtual machine is not killed. Now,I would like to create a script to kill the "dead" virtual machines that are still listed when I do a "ps ax | grep bhyve",but that can't be used anymore. Let's take the example below :
in this case I have one bhyve virtual machine running called vm4 without the corresponding vnc session number,that should be 4,but,instead it is NULL. It means that I've closed the bhyve virtual machine and the vncviewer window but it didn't do properly what I wanted so the bhyve vm is still listed between the running process and it should be killed.
To be clear,I want to show you how is the script that I usually use to launch a bhyve vm :
now,since there isn't any easy method to know if a virtual machine is a ghost or if it is running,I've thought that grepping the vncviewer session number is the most secure method to determine which virtual machine is really running because I never close the vncviewer window but I minimize its window and since I've associated the same number to the virtual machine and to the vncviewer session,if the vnc-viewer-session number is the same as the bhyve-session-number,I'm sure that vm4 is still USABLE. When I will halt the vm4,the corresponding vnc session should be closed for sure. But sometimes it does not happens. Now,what I want to do is to create a script that should assign the correct value to vnc-session and bhyve-session using a string manipulation script that I want to create. In this case the values are :
Later I will complete the script like this :
if "vnc-session-number" is different than the "bhyve-session-number",then
I like to play with the bhyve virtual machines in FreeBSD a lot. As you probably know,sometime when the OS loaded by the virtual machine is halted,the bhyve virtual machine is not killed. Now,I would like to create a script to kill the "dead" virtual machines that are still listed when I do a "ps ax | grep bhyve",but that can't be used anymore. Let's take the example below :
Code:
mario@marietto:/home/marietto/bhyve # ps ax | grep vnc
14893 3 S+ 0:00.00 grep vnc
mario@marietto:/home/marietto/bhyve # ps ax | grep bhyve
14880 - Is 0:00.00 bhyve: system.pwd (bhyve)
14881 - Is 0:00.00 bhyve: system.grp (bhyve)
14875 3 SC 0:38.48 bhyve: vm4 (bhyve)
14898 3 S+ 0:00.00 grep bhyve
in this case I have one bhyve virtual machine running called vm4 without the corresponding vnc session number,that should be 4,but,instead it is NULL. It means that I've closed the bhyve virtual machine and the vncviewer window but it didn't do properly what I wanted so the bhyve vm is still listed between the running process and it should be killed.
To be clear,I want to show you how is the script that I usually use to launch a bhyve vm :
Code:
bhyve -S -c sockets=2,cores=2,threads=2 -m 8G -w -H -A \
-s 0,hostbridge \
-s 1,nvme,/dev/nvd0,bootindex=1 \
-s 2,virtio-blk,/dev/$vmdisk4 \
-s 3,virtio-blk,/dev/$vmdisk8 \
-s 4,virtio-blk,/dev/$vmdisk11 \
-s 10,virtio-net,tap4 \
-s 11,virtio-9p,sharename=/ \
-s 12,hda,play=/dev/dsp,rec=/dev/dsp \
-s 29,fbuf,tcp=0.0.0.0:5904,w=1600,h=950 \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_BHF_CODE.fd \
vm4 < /dev/null & sleep 2 && vncviewer 0:4
now,since there isn't any easy method to know if a virtual machine is a ghost or if it is running,I've thought that grepping the vncviewer session number is the most secure method to determine which virtual machine is really running because I never close the vncviewer window but I minimize its window and since I've associated the same number to the virtual machine and to the vncviewer session,if the vnc-viewer-session number is the same as the bhyve-session-number,I'm sure that vm4 is still USABLE. When I will halt the vm4,the corresponding vnc session should be closed for sure. But sometimes it does not happens. Now,what I want to do is to create a script that should assign the correct value to vnc-session and bhyve-session using a string manipulation script that I want to create. In this case the values are :
Code:
$vnc-session-number=NULL
$bhyve-session-number=4
Later I will complete the script like this :
if "vnc-session-number" is different than the "bhyve-session-number",then
Code:
bhyvectl --vm=$bhyve-session-number --force-reset
bhyvectl --vm=$bhyve-session-number --destroy