Milestone 12 HyperV Linked Clones and Automation 1 - Oliver-Mustoe/Oliver-Mustoe-Tech-Journal GitHub Wiki
This page journals content related to SYS-350 milestone 12.
Table of contents:
Ubuntu Base VM setup
First I downloaded the needed ISO:
(New-Object System.Net.WebClient).DownloadFile('http://192.168.7.241/isos/ubuntu-22.04-live-server-amd64.iso','F:\ISO\ubuntu-22.04-live-server-amd64.iso')
Then I setup a Ubuntu VM with the ISO:
New-VM -Name "ubuntu-22.04-base" -MemoryStartupBytes 2GB -Path "F:\VM_FILES\ubuntu-22.04-base" -NewVHDPath "F:\VM_FILES\ubuntu-22.04-base\ubuntu-22.04-base.vhdx" -NewVHDSizeBytes 16GB -Generation 2 -SwitchName "LAN-INTERNAL"
Set-VMProcessor "ubuntu-22.04-base" -Count 2
Add-VMDvdDrive -VMName "ubuntu-22.04-base" -Path "F:\ISO\ubuntu-22.04-live-server-amd64.iso"
Set-VMFirmware -VMName "ubuntu-22.04-base" -BootOrder $(Get-VMHardDiskDrive -VMName "ubuntu-22.04-base"), $(Get-VMDvdDrive -VMName "ubuntu-22.04-base")
Set-VMFirmware -VMName "ubuntu-22.04-base" -EnableSecureBoot Off
Start-VM "ubuntu-22.04-base"
I would select and fullscreen my Ubuntu VM, it automatically selected to install Ubuntu server after a time:
I would go through the Ubuntu server installation with the following settings (pressed the done or next button on each step after settings is appropriately):
Selected English > continued without updating:
English keyboard selected > installed regular Ubuntu server:
Did not configure networking (it got a DHCP address after a time):
No Proxy address > default mirrors > used the entire disk:
Filesystem summary:
Confirmed the destructive action:
Entered the following profile information (password entered but is hidden):
Selected to install OpenSSH server:
Nothing else:
Then the installer started to install:
Full log:
After the installer went through, I selected to reboot now:
Then I pressed enter when prompted:
Then I was met with a login (was stuck for a second and needed to press Enter):
Then I logged in:
I would then use the following in the ubuntu-22.04-base VMs command line to download and run the installer script (would answer yes to any prompts and I ran the following as root):
wget https://raw.githubusercontent.com/gmcyber/480share/master/hyperv-ubuntu-sealer.sh
sudo bash ./hyperv-ubuntu-sealer.sh
(Also pressed Enter on this)
(Had to do this twice)
Then I removed the script and shutdown the box (in the ubuntu terminal):
rm hyperv-ubuntu-sealer.sh
shutdown now
Cloning Ubuntu VM
In Powershell on my Windows server I ran the following to snapshot my Ubuntu base VM:
Checkpoint-VM -Name "ubuntu-22.04-base" -SnapshotName "Base"
And then the following to make the vhdx for the Ubuntu VM read only:
Set-ItemProperty -Path "F:\VM_FILES\ubuntu-22.04-base\ubuntu-22.04-base.vhdx" -Name IsReadOnly -Value $true
After I created a new sonofubuntu VM folder:
mkdir "F:\VM_FILES\sonofubuntu"
Then made a new virtual difference disk for a sonofubuntu VM:
New-VHD -ParentPath "F:\VM_FILES\ubuntu-22.04-base\ubuntu-22.04-base.vhdx" -Path "F:\VM_FILES\sonofubuntu\sonofubuntu.vhdx" -Differencing
And created a sonofubuntu VM:
New-VM -Name "sonofubuntu" -MemoryStartupBytes 2GB -Path "F:\VM_FILES\sonofubuntu" -VHDPath "F:\VM_FILES\sonofubuntu\sonofubuntu.vhdx" -Generation 2 -SwitchName "LAN-INTERNAL"
Set-VMFirmware -VMName "sonofubuntu" -EnableSecureBoot Off
As well I started it:
Start-VM "sonofubuntu"
VM booted and working:
Rocky Base VM Setup
I would create a new Rocky base VM:
# Download the ISO
(New-Object System.Net.WebClient).DownloadFile('http://192.168.7.241/isos/Rocky-8.6-x86_64-minimal.iso','F:\ISO\rocky-8.6-base.iso')
# Setup the VM
New-VM -Name "rocky-8.6-base" -MemoryStartupBytes 2GB -Path "F:\VM_FILES\rocky-8.6-base" -NewVHDPath "F:\VM_FILES\rocky-8.6-base\rocky-8.6-base.vhdx" -NewVHDSizeBytes 16GB -Generation 2 -SwitchName "LAN-INTERNAL"
Set-VMProcessor "rocky-8.6-base" -Count 2
Add-VMDvdDrive -VMName "rocky-8.6-base" -Path "F:\ISO\rocky-8.6-base.iso"
Set-VMFirmware -VMName "rocky-8.6-base" -BootOrder $(Get-VMHardDiskDrive -VMName "rocky-8.6-base"), $(Get-VMDvdDrive -VMName "rocky-8.6-base")
Set-VMFirmware -VMName "rocky-8.6-base" -EnableSecureBoot Off
Start-VM "rocky-8.6-base"
After selecting the VM and connecting to it > selected English has the language:
Which greeted me with this:
In the "User Creation" section I created a user like the following then pressed "Done":
In the "Installation Destination" section I did nothing but enter the menu and press "Done":
Completed screen:
I would then press "Begin Installation" which would begin the installation:
Installation completed (did get stuck and I had to click in the installer to get it to wake up):
I then pressed the "Reboot System" button which rebooted the system:
Rocky base system rebooted:
I could then login as rangeuser > and then use nmtui
:
(NOTE: Originally I temporarily activated the interface > sysprepped > created a clone. At the realization the clone's networking wouldn't be activated I went back and activated the interface like the following > sysprepped. I moved this step here, retook all of the screenshots (even the ones after the interface) as this is what was done the final time.)
I would then press "Edit a connection" > selected eth0 with Enter > scrolled done to "Automatically connect" and set it to true with Space:
Before:
After:
I then pressed "Ok" > "Back" > finally "Quit" on the main nmtui
menu.
With this set I would receive a DHCP address:
I would then use the following command in my Rocky VM to sysprep my Rocky VM:
sudo -i
curl https://raw.githubusercontent.com/gmcyber/480share/master/rhel8sealer.sh -o rhel8sealer.sh
chmod +x rhel8sealer.sh
./rhel8sealer.sh
This would poweroff the VM:
I would then create a snapshot of the VM:
Checkpoint-VM -Name "rocky-8.6-base" -SnapshotName "Base"
Cloning Rocky VM
I would create a clone of the Rocky base VM in the same way I did for the sonofubuntu VM:
# Create Folder for VM
mkdir "F:\VM_FILES\rockyclone01"
# Create differential VHD for VM
New-VHD -ParentPath "F:\VM_FILES\rocky-8.6-base\rocky-8.6-base.vhdx" -Path "F:\VM_FILES\rockyclone01\rockyclone01.vhdx" -Differencing
# Create VM with settings
New-VM -Name "rockyclone01" -MemoryStartupBytes 2GB -Path "F:\VM_FILES\rockyclone01" -VHDPath "F:\VM_FILES\rockyclone01\rockyclone01.vhdx" -Generation 2 -SwitchName "LAN-INTERNAL"
Set-VMFirmware -VMName "rockyclone01" -EnableSecureBoot Off
I would then start the VM:
Start-VM -Name "rockyclone01"
Rockyclone01 VM started and its VHDX properties showing that its parent is the Rocky base VM:
Reflection
Compared to adhoc pyvmomi, Hyper-V Powershell as SIGNIFICANTLY EASIER. I have been using Powershell since last lab with Hyper-V and it has been an incredibly well implemented. A particular external feature that improves the Powershell Hyper-V experience is the Microsoft documentation. The documentation gives great explanations of each flag with examples showing common usage which I could quickly adapt for my own needs. This puts it an arm and a leg over pyvmomi for me as I would find myself for pyvmomi having to scrounge for documentation about why x did y, while with Hyper-V Powershell I could easily do all of the operations I needed to!