HowTO: VM start on boot

Install virtual machines on your TNAS;
Locked
User avatar
Bipe
Posts: 9
Joined: 31 Jul 2023, 19:26

HowTO: VM start on boot

Post by Bipe »

Hi all!

Here are steps that will allow you to run VM on system boot.

Requirements:
[*] SSH connection to NAS
[*] VirtualBox VM that's up and running

Steps:
  1. Connect to your NAS via SSH.
  2. Now, you need to find your VM ID, simple ps command with grep will do:

    Code: Select all

     ps -eo command | grep VBoxHeadless
    Output will look something like this:

    Code: Select all

    [bipe@TNAS ~]# ps -eo command | grep VBoxHeadless
    /usr/lib/virtualbox/VBoxHeadless --comment shuttle-vm --startvm 90c1bd38-5a6d-40d0-a0b8-a97e3da6b777 --vrde config
    grep VBoxHeadless
    [bipe@TNAS ~]#
    I have only one VM running, named "shuttle-vm", if you have more than one VM, you should see all of them listed.
  3. Connect to NAS via web GUI
  4. Open Control panel
  5. Open Scheduled Tasks under General settings
  6. Create new Triggered Scheduled Tasks
  7. Give it some name, eg. vm-autostart and click next (leave user as is, trigger should be Power on by default)
  8. In Custom command script field enter:

    Code: Select all

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/Volume1/@apps/virtualbox/lib
    /usr/lib/virtualbox/VBoxHeadless --comment shuttle-vm --startvm 90c1bd38-5a6d-40d0-a0b8-a97e3da6b777 --vrde config
    First line is adding path to required libs dir, second line is full command you have received in step 2
  9. Next, Create and that's it ;)
Create multiple scheduled jobs if you have more than one VM you need / want to start on system boot.
Each scheduled job should contain only one VBoxHeadless command.
User avatar
sharekhan
Posts: 1
Joined: 30 Aug 2023, 20:41

Re: HowTO: VM start on boot

Post by sharekhan »

Thank you @Bipe for the excellent article to auto-start VM on boot, do you by any chance also know how to perform a VM auto shutdown before the NAS power down ?
Thanks!
User avatar
Bipe
Posts: 9
Joined: 31 Jul 2023, 19:26

Re: HowTO: VM start on boot

Post by Bipe »

well, you could create scheduled job that will run on NAS Power off, with custom script something like this:

Code: Select all

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/Volume1/@apps/virtualbox/lib
/usr/lib/virtualbox/VBoxManage controlvm <vmid> acpipowerbutton
use the same vmid that you used for auto start

from VirtualBox doco:
VBoxManage controlvm <vm> acpipowerbutton: Sends an ACPI shutdown signal to the VM, as if the power button on a real computer had been pressed. So long as the VM is running a fairly modern guest operating system providing ACPI support, this should trigger a proper shutdown mechanism from within the VM.
please note that TOS will not wait for VM to shutdown and it might kill it before it has fully turned off
Locked

Return to “Virtual Machines”