Shutdown problem in Virtual box with a running virtual machine

Status
Not open for further replies.

Marc Allard

Explorer
Joined
Mar 16, 2014
Messages
56
Hello,

I have installed a jail with virtual box.
After that I have installed a virtual machine (Nanoboot) and I have seen that when the virtual machine is running, when I shut down the host, the host will not shutdown but restart.
If I shut down the virtual machine before I click on the shutdown button all is fine.

I have tried with the method /etc/rc.conf
listed here http://wiki.sysconfig.org.uk/display/howto/VirtualBox On FreeBSD
and it doesn't work too.
The virtual machine crashes when I shut down the host.
So I guess something doesn't happen when I shutdown the host (the jail isn't aware or something like that.

I have also made a shell script in the jail (mnt/VHD/shutdown.sh) with a chmod 777 (simpler for debug)
and the script has the following lines
#!bin/sh
su vbox -c "VBoxManage controlvm NanobootXPEnology savestate"

When I execure it in a shell session (as root) there is no problem. (the machine stops normally)
When I execute it in a script (shutdown script) with the following command

jexec 1 /mnt/VHD/shutdown.sh
It doesn't work too.
Can you please tell me how I can let the host sleep when I want it down (or better)
Can you please tell me if there is a way to shut down the virtual machine automatically when I shut down the host so the host stays down and the machine closes normally?
Thank you
Marc


EDIT : Found a workaround
After some investigation
I have seen a workaround (not very good)
The problems seems to be because when there is a shutdown, the jails want to unmount the filesystem (I have seen a message telling impossible to unmount VHD as it is in use) before stopping the virtual machine.When it happens, the host crashes.
I have created a script on the jail that closes the running machine (you must not use the command directly
I do a
mount -uw / (to be able to change the /conf...

In the /conf/base/etc/rc.shutdown (and also /etc/rc.shutdown)
I add the following in the beginning of the file

/usr/sbin/jexec 1 /mnt/VHD/shutdown.sh
sleep 10

I am not sure if the sleep 10 is important but I prefer to be safe than sorry.


And my shutdown script in the jail must be
#!bin/sh
su vbox -c "/usr/local/bin/VBoxManage controlvm NanobootXPEnology savestate"


Without the /usr/local/bin/ the script works perfectly but not when I shutdown the jail)

I have to see a way to use the script without hardcoding the number 1 in jexec

Marc
 

SkitzoTek

Cadet
Joined
May 18, 2015
Messages
4
Thanks for this script, it solves exactly what I was looking for.

BTW: jexec can use either a number, or the name of the jail:
/usr/sbin/jexec vbox /mnt/BHD/shutdown.sh
 

Marc Allard

Explorer
Joined
Mar 16, 2014
Messages
56
Hello,
With this method, the file is overwriten every time you update Freenas.
So, I have tried to do it another way :
Inside the jail you must edit the file
/etc/rc.shutdown

and add in the beginning of the file (just after the comments and before the line stty status '^T' 2> /dev/null)
/mnt/VHD/shutdown.sh

So it will execute the file before starting the shutdown process.

The script is still the same, but the /etc/rc.shutdown will survive the updates of FreeNas

BTW : Thank you for the tip I was always using jexec -n vbox (I didn't know that the -n was useless)
/usr/sbin/jexec vbox /mnt/VHD/shutdown.sh
Marc
 

Doc Chacha

Dabbler
Joined
Sep 18, 2016
Messages
28
Status
Not open for further replies.
Top