AutoStart VirtualBox VM

Status
Not open for further replies.

MarcvdB

Cadet
Joined
Jul 9, 2014
Messages
3
I've installed FreeNAS 9.2.1.6 with the VirtualBox jail and I was wondering if there is a possibility to autostart the VM's I've created in VirtualBox?

Also when I enter the jail (jexec 1 /bin/tcsh) and execute this command:
upload_2014-7-11_9-16-13.png


I get nothing back, but I have created 1 virtual machine on the php website and I'm able to start that virtual machine in the php website.
 

MarcvdB

Cadet
Joined
Jul 9, 2014
Messages
3
The command VBoxManage list vms works when logging into the jail via SSH as the user vbox.
But when I issue the command VBoxManage startvm WinXP then I get this error:
upload_2014-7-11_11-0-45.png

So something is still not correct...
 

MarcvdB

Cadet
Joined
Jul 9, 2014
Messages
3
Ok, I found out another thing.
when using the commandline VBoxManage startvm WinXP you also have to specify the type, so when I issue the command:
VBoxManage startvm WinXP --type headless the virtual machine starts up.

So the remaining question is how to autostart this VM when FreeNAS appliance is started?
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Sorry, I'm not in a position to check on this. I'll try to remember to try this out this weekend.
 

Slacker

Cadet
Joined
Mar 20, 2014
Messages
3
Much googling and trial/error yielded this for autostarting VMs when the jail starts:
In the vbox jail, edit /etc/rc.local and add
su -l vbox -c 'VBoxManage startvm "VMname" --type headless'


I would say to add this for a graceful shutdown, but it doesn't seem to run when the jail is stopped...
in /etc/rc.local.shutdown:
su -l vbox -c 'VBoxManage controlvm "VMname" acpipowerbutton'
 

Marc Allard

Explorer
Joined
Mar 16, 2014
Messages
56
Hello,

Here is what I did (and it is working perfectly at the moment)
vi /etc/rc.conf

I have put the following in the file


# this is required for networking (replaces loading remaining modules manually)
vboxnet_enable="YES"

# start VirtualBox
vboxheadless_enable="YES"

# VMs to start (whitespace-separated list):
vboxheadless_machines="NanobootXPEnology"

# definition for VM with acronym "NanobootXPEnology":
vboxheadless_NanobootXPEnology_name="NanobootXPEnology"
vboxheadless_NanobootXPEnology_user="vbox"
vboxheadless_NanobootXPEnology_stop="poweroff"

This way, the virtual machine will automatically start and stop with the jail.


As my virtual machine uses the bridged networking, I have seen that freenas host will always crash when it is "shut downed" or "restarted". I have reported it as a bug (5263). The only way I saw to solve the problem was to force a shutdown of the virtual machine before the vboxheadless shot downs the machine. So I do

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 (just after the comments)

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

I put jexec 1 because I have no idea about how to find the id of a jail from its name and the jail always has an ID of 1
Without the sleep I have a crash of freenas

The file shutdown.sh content (it must be in the jail as jexec works in the jail):
I must do a su vbox as phpvirtualbox works as vbox.
Don't forget the chmod 777 /mnt/VHD/shutdown.sh
(777 is perhaps a bit too much.
#!bin/sh
su vbox -c "/usr/local/bin/VBoxManage controlvm NanobootXPEnology savestate"
 

Slacker

Cadet
Joined
Mar 20, 2014
Messages
3
Hello,

Here is what I did (and it is working perfectly at the moment)
vi /etc/rc.conf

<snip>


I just went ahead and added the jexec save command to /etc/rc.shutdown directly, saving the extra step of creating the file.
jexec 3 su vbox -c "/usr/local/bin/VBoxManage controlvm VMNAME savestate"

Thanks for the tips!

I run a Debian x32 VM, bridged, and have no issues rebooting or shutting the thing down, btw.

EDIT: Also, the rc.conf method seemed to have added a large boot delay, so I stuck with mine to start the VM.
 
Last edited:

andyclimb

Contributor
Joined
Aug 17, 2012
Messages
101
Cheers I've been wondering how to do this!


Sent from my iPad using Tapatalk
 

loki_racer

Dabbler
Joined
Jan 2, 2014
Messages
23
This doesn't appear to work for me. The jail still starts, but the VM doesn't automatically start. Just throwing my two cents into the ring.
 

Marc Allard

Explorer
Joined
Mar 16, 2014
Messages
56
Hello,

Did you edit the /etc/rc.conf in the jail (so jexec 1 csh...)
The machine name (NanobootXPEnology) must be the name of the machine on your computer. so you should have 5 times XXX (name of the machine). I don't think the one in the comment is usefull

# VMs to start (whitespace-separated list):
vboxheadless_machines="XXXX"

# definition for VM with acronym "XXXX":
vboxheadless_XXXX_name="XXXX"
vboxheadless_XXXX_user="vbox"
vboxheadless_XXXX_stop="poweroff"
 

petr

Contributor
Joined
Jun 13, 2013
Messages
142
Hello,
...
/usr/sbin/jexec 1 /mnt/VHD/shutdown.sh
sleep 10
...

Thank you for the tip with the sleep - I've got a question.. is the 10s in any way correlated to the time it takes for your VM to shut down? My take a tad longer and I am experiencing interesting issue - if the jail takes too long to shut down, a shutdown watchdog aborts the machine shutdown, leaving it semi-shutdown state, which if far from ideal!

Any hints?
 

Marc Allard

Explorer
Joined
Mar 16, 2014
Messages
56
Hello,

I tried 5 sec and it didn't work so I took 60 and it worked. After that I tried to reduce and I took 30 ==> 15 ==> 10 :oops:
and all was fine so I didn't try anything else.
 

Dudleydogg

Explorer
Joined
Aug 30, 2014
Messages
50
Much googling and trial/error yielded this for autostarting VMs when the jail starts:
In the vbox jail, edit /etc/rc.local and add
su -l vbox -c 'VBoxManage startvm "VMname" --type headless'


I would say to add this for a graceful shutdown, but it doesn't seem to run when the jail is stopped...
in /etc/rc.local.shutdown:
su -l vbox -c 'VBoxManage controlvm "VMname" acpipowerbutton'


This was the only solution that Actually Works
 

Osiris

Contributor
Joined
Aug 15, 2013
Messages
148
The VM autostarts indeed, using Marc Allard's method.
However, the webgui of virtualbox isn't accessible anymore.
Did anyone else encounter this issue?

The service did start and httpd did too.
I also see this:
/usr/local/lib/virtualbox/VBoxSVC --auto-shutdown

EDIT: I had to reboot the host to fix it all. Weird.
 

Attachments

  • auto-shutdown.jpg
    auto-shutdown.jpg
    89.4 KB · Views: 302
Last edited:

Dudleydogg

Explorer
Joined
Aug 30, 2014
Messages
50
I have all this working but due to the VIMAGE problem I disabled auto start of the Jails, VIMAGE will gag and bring down the entire server and you end up with multiboot hang which can be annoying.
I was going to check my startup Options and reply back to you but I cannot ssh to my box due to VIMAGE Hang.
 

Dudleydogg

Explorer
Joined
Aug 30, 2014
Messages
50
Do you have the Apache Line in your rc.conf ?

root@Vcenter_Server:/ # more /etc/rc.conf
apache22_enable="YES"
sshd_enable="YES"
vboxwebsrv_user="vbox"
vboxwebsrv_enable="YES"
inet6_enable="YES"
ip6addrctl_enable="YES"
# this is required for networking (replaces loading remaining modules manually)
vboxnet_enable="YES"
# start VirtualBox
vboxheadless_enable="YES"
# VMs to start (whitespace-separated list):
vboxheadless_machines="vcenter"
vboxheadless_vcenter_name="Vcenter-2016"
vboxheadless_vcenter_user="vbox"
vboxheadless_vcenter_stop="savestate"
 
Status
Not open for further replies.
Top