Trying to make VM start at start of OS.

Just about everything is virtual these days. Topics relating to virutalization go here.

Moderator: Lillian.W@AST

Post Reply
Jarod24
Posts: 8
youtube meble na wymiar Warszawa
Joined: Mon Jun 13, 2016 8:49 pm

Trying to make VM start at start of OS.

Post by Jarod24 »

Originally posted in: Apps Unlimited ‹ Official ASUSTOR Apps ‹ VirtualBox (http://forum.asustor.com/viewtopic.php?f=124&t=7990)


I'm trying to make the VM start up automatically at launch of the ASUSTOR server.
I'm using a AS6204T running ADM version 2.6.1.R5H1

I'm brand new to Linux, but I gathered that I would need to create a script under /usr/local/etc/init.d/ that does this
(ref: http://forum.asustor.com/viewtopic.php?f=49&t=1681)

Using ln I setup this symblink file:

Code: Select all

lrwxr-xr-x    1 root     root            52 Jun 13 17:58 S99MyServer.sh -> /volume1/Software/_VirtualBox/S99MyServer.sh*

On my old windows server I used this:

Code: Select all

@REM Restore to current snapshot, ignoring any changes
"%VBOX_MSI_INSTALL_PATH%\VBoxManage.exe" snapshot "MyServer" restorecurrent
@REM Start the VirtualBox in headless mode
"%VBOX_MSI_INSTALL_PATH%VBoxHeadless.exe" --startvm "Myserver"

I've tried these lines in the script but that didn't work; also I assume that using sudo with 'root' is pointless and/or bad. Would you want/need to run Virtualbox under root or some other user?
Any help getting this thing work is greatly appreciated.

Code: Select all

#!/bin/sh -e

# Startup Virtualbox on system startup.
# Windows code
# @REM Restore current snapshot
# "%VBOX_MSI_INSTALL_PATH%\VBoxManage.exe" snapshot "MyServer" restorecurrent
# @REM Start the VirtualBox in headless mode
# "%VBOX_MSI_INSTALL_PATH%VBoxHeadless.exe" --startvm "MyServer"

VMUSER="root"
VMNAME="MyServer" 

echo "===Reset changes back to snapshot==="
sudo -H -u $VMUSER VBoxManage snapshot "$VMNAME" restorecurrent
sleep 10

echo "===Starting VirtualBox VM==="
sudo -H -u $VMUSER VBoxHeadless startvm "$VMNAME"
# sudo -H -u $VMUSER VBoxManage startvm "$VMNAME" --type headless
sksbir
Posts: 395
Joined: Tue Aug 25, 2015 9:23 pm

Re: Trying to make VM start at start of OS.

Post by sksbir »

Hi
I'm searching on my side to do the same.

First of all, VBoxManage is not in the path.

so try it with
/volume1/.@plugins/AppCentral/virtualbox/bin/VBoxManage

eg running this with root : /volume1/.@plugins/AppCentral/virtualbox/bin/VBoxManage list vms
Jarod24
Posts: 8
Joined: Mon Jun 13, 2016 8:49 pm

Re: Trying to make VM start at start of OS.

Post by Jarod24 »

So I changed the script to this:

Code: Select all

#!/bin/sh -e
# Startup Virtualbox on system startup.
VMNAME="MyServer" #also you can put UUID in this variable

echo "===Reset changes back to snapshot==="
/volume1/.@plugins/AppCentral/virtualbox/bin/VBoxManage snapshot "$VMNAME" restorecurrent
sleep 10

echo "===Starting VirtualBox VM==="
/volume1/.@plugins/AppCentral/virtualbox/bin/VBoxManage startvm "$VMNAME"
When run the lines in SSH directly they work, but when I try running the script from SSH it outputs the following:
(also; the script has no effect when the server is rebooted)

Code: Select all

root@MyDataServer:/volume1/.@root # /usr/local/etc/init.d/S99MyServer.sh
/bin/sh: illegal option -
root@MyDataServer:/volume1/.@root #
Jarod24
Posts: 8
Joined: Mon Jun 13, 2016 8:49 pm

Re: Trying to make VM start at start of OS.

Post by Jarod24 »

Ok so after another round of fiddling around my final script looks like this:

The 'restorecurrent' option will not run no matter what I try: adding single or double quotes in various permuations, single, double space, etc, etc. It will always trow an error.
The 'startvm' line does work however and that is the important bit.

Also to run the script from bash I needed to type ". /usr/local/etc/init.d/S99MyServer.sh" (period infront)
If the server goes into power save mode, the VM will resume automatically so there is no need to do anything extra for that.

Code: Select all

#!/bin/sh -e

# Startup MyServer Virtualbox on system startup.
#  Windows code
#   @REM Restore current snapshot
#   "%VBOX_MSI_INSTALL_PATH%\VBoxManage.exe" snapshot "MyServer" restorecurrent
#   @REM Start the VirtualBox in headless mode
#   "%VBOX_MSI_INSTALL_PATH%VBoxHeadless.exe" --startvm "MyServer"

/opt/VirtualBox/VBoxManage snapshot MyServer restorecurrent 

# echo "===Starting VirtualBox VM==="
/opt/VirtualBox/VBoxManage startvm MyServer 

sksbir
Posts: 395
Joined: Tue Aug 25, 2015 9:23 pm

Re: Trying to make VM start at start of OS.

Post by sksbir »

Jarod24 wrote:....
The 'restorecurrent' option will not run no matter what I try: adding single or double quotes in various permuations, single, double space, etc, etc. It will always trow an error.....
Yes, by chance. This option will try to restore your VM at the time you took a snapshot. You must have taken at least one snapshot of your VM with the "snapshot take" option


My solution : [HOWTO] start and stop VM with your NAS.
Post Reply

Return to “Virtualization”