Remote virtual machine control

Muffin.Monkey

Dabbler
Joined
Feb 2, 2019
Messages
13
Consider this use case:

I have a Raspberry Pi with an attached monitor within my network. This Raspberry Pi shall display the desktop of a Windows VM running on my TrueNAS to use some Windows only application. The Raspberry Pi will only run a few hours per week, so I do not want the VM to run 24/7, but only when the application is used. Is there a possibility to start and stop the VM from the Raspberry Pi?

Thanks for your answers in advance!
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,702
Pi desktop with a browser and RDP/VNC client on it... that's all that's needed.
 

Muffin.Monkey

Dabbler
Joined
Feb 2, 2019
Messages
13
That is my plan, but is there a possibility to start the VM before starting the RDP / VNC connection and stopping the VM after closing the connection by the Raspberry Pi?
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,702
That's what the browser is for. Connect to the GUI, start /stop the VM.
 

Muffin.Monkey

Dabbler
Joined
Feb 2, 2019
Messages
13
To sum this thread up:
There is no other possibility to start / stop the VMs, but the GUI. I have to let them run 24/7 if I do not want to login to the GUI before usage.
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,398
It is possible to start & stop a VM without the GUI, but you'll have to use API calls to do it. See
https://www.truenas.com/community/threads/backup-bhyve-windows-vm.85705/post-601264 for an example script @bal0an wrote to control a VM for backup.

This is for an on-box session, though. Remotely from a Pi, you'd have to generate an API key for root REST access, and use the REST API to start and stop the VM:

https://www.truenas.com/docs/core/api/ and note the Add button.

 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,702
Another alternative... I think maybe what you're getting at in that case...

You can set the VM to start on boot, but in the Devices, edit the VNC device to "Delay Boot until VNC device connects". Then the VM will only start once you connect to it with VNC from the PI.

In order to then disconnect and have it waiting to boot again, you need to "reboot" and immediately stop the VNC connection (so it goes back into the state of waiting for VNC to connect before the boot process starts again). I tested that and I can get it to work like that if I'm careful about disconnecting VNC quick enough.

Worst case, it will work once per reboot of TrueNAS. ;)

EDIT: additionally, you should know that the state of the VM in the GUI will always appear to be started even when it's not running (="running", but actually waiting for VNC)
 
Top