Jump to content

Scripting VM Start / Stop?

3 posts in this topic Last Reply

Recommended Posts

Posted (edited)

So, we can boot UnRaid in GUI mode and then boot into a VM on the same GPU.

However, when the VM quits, we don't get the unRaid GUI back (so we're 'stuck')


I'm wondering if there's a way to 'script' a sequence so that booting up a different VM could be achieved from within a VM?


Consider a single GPU server;

1. User boots to unRAID GUI

2. User launches Windows 10 VM from unRAID UI

3. Within Windows VM, users runs script to launch OSX VM (could be on desktop, could be part of unRaid browser UI)

4. Script shuts down Windows VM, waits a few seconds, then launches OSX VM

5. Voila, user sees OSX boot on same system/screen


Any thoughts, pointers?


(I guess I'm thinking about some kind of VM Switcher functionality)

Edited by meep

Share this post

Link to post

It's pretty easy.



virsh stop <windows vm name>

sleep 10

virsh start <macos vm name>


Share this post

Link to post
Posted (edited)

A few more notes:

  • To run the script from desktop, you can use Putty and a bat file to automatically SSH into the server and execute the script. Normally, the SSH password is in plain text in the bat file which is a security risk so you might want to set up a public key login (can't remember how I did it but remember there was a post on the forum so you will need a bit of searching).
  • Win10 VM generally co-operates with virsh stop but I have found OSX VM to be less co-operative. So what I have done in the past is to lengthen the wait time (i.e. longer than a typical shutdown) and then use virsh destroy to guarantee the OSX VM shutdown (virsh destroy is equivalent of turning off the power)
  • If VM name has space then use double quote. You can also use uuid.

So assuming the typical shutdown time is 10s then I'll add 5s to the wait time just to be safe. Script will be something like this:

virsh stop "VM1 name"
sleep 15s
virsh destroy "VM1 name"
virsh start "VM2 name"


Edited by testdasi

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.