So I had an idea to make creating VMs a little easier for me instead of clicking a handful of buttons and powering up the VM then waiting for it to install. I found a blog post intended for Mac VMs that was inspired from a now deleted site’s blog post by a guy who needed to make a bunch of them quicker so I forked Tamas’s script (the original one I think) and modified it to create Ubuntu VMs. :) I also added a few scripts of my own that would tell me if a VM was ready and another to give me the IP. I may try to integrate those two at some point.
How does it work?⌗
Glad you asked. wink Basically, you give the script some parameters and it does it’s thing, it mainly needs the name of the VM; the rest is optional. Details on that is in the readme file.
The script has a list of defaults you can set so all you need is a name. From those defaults, there’s a list of loops that check for an input and do some error checks then if none is provided, it uses the defaults. It also checks if the datastore and vm name provided exists. If everything checks out, it proceeds to create the directory, VM Disk Image, and the VM file (.vmx) itself populated with a bunch of stuff the hypervisor needs. Once that is done, it then registers and powers on the VM and prints out the config details.
Following all that, I have two scripts to check if it’s ready and print the ip to the console. All the scripts need is the VM ID outputted from the create.sh script.
What I added to the create.sh script⌗
I added support for multiple datastores and put the network name in a variable if one needed to change it for a single instance or something. I also changed the original RAM and VDISK values to suit my needs as well as the guestOS type for the vmx file it makes and set the location to my ISO file.
Feel free to read all the code and compare with the other guy’s repo. I think this script ought to do just nicely. :)
Moving the script from it’s home in the primary datastore to
/usr/bin and run
auto-backup.sh on the host itself.
Setup windows (via the win10 linux subsystem unless you can make it work with putty or powershell) to create VMs from a cmd or powershell prompt. All you’d need to do is add your public ssh key to
/etc/ssh/keys-root/authorized_keys on the host and run the aforementioned backup script. If that backup script isn’t ran, any changes outside of the datastores and what is usually backed up will be lost upon reboot.
I think that’s all. It’s a cool script, props to the guy who made it. I just improved it some. ;) Cheers.