Milestone12:HyperVLinkedClones - echadbourne/SYS-350 GitHub Wiki

Prep

I started by making a new vm with the ubuntu iso from the class web server, with the following things:

  • Gen 2
  • 4096 MB (4GB)
  • Network Hyper-V-WAN
  • Ubuntu iso
  • Secure boot off

I installed ubuntu on the vm (which took forever) and then ran the script provided here which also took forever. I then shut down the vm, and made a snapshot of it. (Called checkpoint, under start)

image

I then located the vhd file for the vm, which I got from copying the file path for the hard drive in the settings of the vm, and set it to read only to protect it and all of its other potential children.

image

image

I then created a new virtual hard disk, and in the disk type chose "disk differencing" for use in a parent-child relationship

image

image

Specify the parent vhd as the parent vhd

image

I then made another ubuntu vm with the child disk, keeping all the same specs

image

I then turned it on, and it was originally 4mb, and is now 100 mb

image

Automation

3 of the deliverables I did in the form of a script, because I initially read the requirement wrong and I've been making powershell scripts in another class this semester. That script can be found in this github. It can do the following:

  • Stop sonofubuntu
  • Start sonofubuntu
  • Snapshot sonofubuntu

There is functionality for changing the network of sonofubuntu, but the commands don't display the same and I had neither the time nor energy to try and fix it. So this is essentially what the script would do to change the network of sonofubuntu:

{77C2A2C5-E631-4F48-BCAC-7D9FD67C6A8C}

The command do swap networks is: `Get-VM -Name sonofubuntu | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName "[name of switch]"

This script could be repurposed for any or all vms, I just kept it simple by hardcoding sonofubuntu as the target of everything. But it would be very easy to add a blanket get vms in there to get and control all of them, or add a field to specify the name of one, similar to how I did it in pyvmomi

Kali

Next was to create a new vm with a new os (I of course chose kali) and automate the creation of a linked clone. To start with I needed a new vm, which got these specifications:

  • Gen 2
  • 4096 MB (4GB)
  • Network Hyper-V-WAN
  • Kali iso
  • Secure boot off

I set it up with the Administrator account, and finished the install. The kali child script will also be available in this github

So I created a script that should make a linked clone the same way we did manually, but it doesn't want to work, and there is not a lot of documentation specifically on linked clones. I got to the point of creating a vm that has the cloned vhd attached, but it won't boot from that vhd. I have no idea why, but I cam pretty darn close, and I'm willing to leave it at that. My resources for this can be found below, and my script can be found here.

https://4sysops.com/archives/set-and-remove-the-read-only-file-attribute-with-powershell/

https://itasapassion.wordpress.com/2014/05/13/change-vm-boot-order-in-powershell/

https://www.techtarget.com/searchitoperations/tip/Enable-and-disable-Hyper-V-secure-boot-with-PowerShell

https://www.batorfi.nl/2017/02/linked-clones-in-hyper-v.html

Reflection

I honestly think that overall, the concepts and logic of automating vms are very similar with pyvmomi and powershell. The basic idea is the same: specify an action and a vm, and it will do that action. The main difference I noticed was the calling of the actions. With pyvmomi we needed to specify a function or a value database style, like an attribute of this, and this and this and so on. With powershell, it was Do-ThisThing, like Get-VM -Name [name] gets the vm with that name. Powershell was way easier for me than pyvmomi, but that may have been just because I was working with it in another class this semester and am overall more familiar with Powershell than with Python. Overall, I could definitely see a similarity with the basic concept, and it was much easier to script with hyper-v because I had that foundation.