Proper shutdown of Ubuntu in bhyve VM

Silvan Burch

Explorer
Joined
May 1, 2016
Messages
65
Hey guys

I'm tinkering around with VMs, trying to setup Ubuntu / Docker together. Actually no problems so far with that.
What I noticed tough after adding my Samba/CIFS shares in the VM is that the VM didnt shutdown anymore when I press the switch in the VM menu of FreeNAS. (What happens is that it cannot umount the Samba shares, tries it for about 90 seconds and then is basically shutdown, except that the VM is not turned off ... I tried a lot of the common solutions found via google but I think this really is a problem with a wrong way of sending the 'shutdown' command)
I saw that it has a problem with umount of the Samba shares so naturally my first reaction was to search for a reason there.
However, at one point I used the 'halt'-command in the console of the VM rather than the switch of the FreeNAS UI and it worked.

So my question is: does anybody know which command exactly is sent to the VM when pressing the "state" switch in the FreeNAS UI to turn off a VM and further, is there a possiblity to change the shutdown procedure to use the 'halt'-command instead?

Edit:
I just checked through the commands: shutdown, poweroff, halt, reboot from within the VM, no problem at all. Just happens when the command is issued from outside, i.e. using the FreeNAS UI buttons.

Edit 2:
I tried now using NFS and the exact same thing happens, too

Edit 3:
well, I tried whatever I found on the net:
* different mounting options in fstab for CIFS and NFS3/4
* using systemd scripts (in /lib/systemd/system and /etc/systemd/system) for CIFS and NFS3/4
* my own scripts that should independently from systemd start and stop CIFS and NFS
whatever I do, in the end while shutting down Ubuntu VM over the FreeNAS switch/stop, it is not properly unmounting or trying it again...

my wild guess is that FreeNAS kills the network adapter before it can close the connections to the mounts properly...

any suggestions are welcome, thanks! :)

Thanks and best regards
 
Last edited:

Silvan Burch

Explorer
Joined
May 1, 2016
Messages
65
Hello again

By now I tried to update to FreeNAS 11.3-U1 to see if anything changes ... still the same Issue.

Anybody else at least having the same problem or - even better - has a solution to it?

Thanks and v/r
 

Silvan Burch

Explorer
Joined
May 1, 2016
Messages
65
well it seems not to be a common problem...
i'll push it a last time with this answer and leave it till i find more myself! :)
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
The "stop" function in the menu on the right (in contrast to "power off") seems to do the right thing here. For FreeNAS shutdowns/reboots I have this script:
Code:
#! /bin/sh

PAUSE="10"

test -t 1 && echo "Sending SIGTERM to bhyve processes."
/usr/bin/killall -TERM bhyve

test -t 1 && echo -n "Waiting for processes to exit ... "
while /usr/bin/killall -0 bhyve >/dev/null 2>&1
do
    sleep "${PAUSE}"
done
test -t 1 && echo "done."

exit 0
 

Silvan Burch

Explorer
Joined
May 1, 2016
Messages
65
Hello Patrick

Thanks for the answer, I really appreciate it

1st of all: if I use the "stop" function, the problem occurs ... however if I ssh into the ubuntu installation and stop it with the 'halt' command, it works perfectly fine

2nd: the command "/usr/bin/killall -TERM bhyve" works when issued from a FreeNAS shell! thank you so much!

can you tell me where you added these lines in FreeNAS so they do get executed when I shutdown / restart FreeNAS?

again, thanks for your help, I really do appreciate it
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
I put them into a script: /mnt/hdd/scripts/shutdown-bhyve.sh and added that as a shutdown task in the UI. Just put anywhere on your data zpool.
 

Silvan Burch

Explorer
Joined
May 1, 2016
Messages
65
so I did that, put the script up and added it for shutdown ... now the problem seems to be that the script is not issued first but only after FreeNAS already issued a shutdown command for the VMs ...
I don't know ... maybe I should just switch to a different OS on the VM and see if that works XD
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
This seems to work here and cleanly shutdown the VMs whenever I shutdown or reboot FreeNAS.
1584200692088.jpeg
 

Silvan Burch

Explorer
Joined
May 1, 2016
Messages
65
well I tried again now it seems to do okay ... first time i did restart and this time shutdown

however I cannot confirm the script is actually running since the output is nowhere to be seen on screen ...

if i run script from shell it works like a charm with output and all

checked /var/log/messages ... no sign of the script being executed
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
It is intentionally written in a way to not produce any output when not connected to a terminal. But you can ssh into your FreeNAS and run top. Then issue the shutdown or reboot via the UI. You should see the byhve process(es) increase in CPU usage, then vanish from the top display just before the system reboots ...

HTH,
Patrick
 
Top