Posted On May 27, 2020

Hyper-V: Clone Linux Guest VM

kimconnect 0 comments
blog.KimConnect.com >> Virtualization >> Hyper-V: Clone Linux Guest VM

There are two methods of cloning an existing guest VM: Templating and Copying. Templating has the issue of the clone retaining the original file name of the source. Therefore, it’s cleaner to follow the copying path to recreate machines.

# Step 1: Copy the .vhdx file to a new destination with a new name

$goldVhdxFile="\\SOMESHERVER\goldImages\CentOS8.vhdx"
$newName='AREA051'
$newPath='\\SOMESHERVER'
$newVhdxFile="$newPath\$newName.vhdx"
New-Item -ItemType File -Path $newVhdxFile -Force # touch before copying contents
Copy-Item $goldVhdxFile -Destination $newVhdxFile

# Step 2: Create New VM using an existing .vhdx file

$memory='8GB'
$switch='ExternalSwitch'
New-VM -Name $newName -MemoryStartupBytes $memory -Generation 2 -Switch $switch  -BootDevice VHD -VHDPath $newVhdxFile -Path $newPath

# Step 3: start-up VM

Start-VM -Name $newName
VMConnect.exe $env:computername $newName

# Step 4: change machine settings

sudo rm -f /etc/udev/rules.d/70-persistent-net.rules # clear persistent net rules
sudo nmtui # set hostname, IP address, gateway, and DNS
sudo reboot # restart machine

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Fixing an Issue On Windows Server 2019 Hyper-V with Uneven Distribution of Available CPU Cores

Issue: When guest-VMs are being migrated between Hyper-V Hosts within a cluster, CPU core scheduling…

PowerShell: Get All Hyper-V Host Spectre Patch Versions

# getAllVmSpectrePatchVersions.ps1 function getHyperVHostsInForest{ function includeRSAT{ $ErrorActionPreference='stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #$rsatWindows7x32='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x86-RefreshPkg.msu' $rsatWindows7x64='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x64-RefreshPkg.msu' $rsatWindows81='https://download.microsoft.com/download/1/8/E/18EA4843-C596-4542-9236-DE46F780806E/Windows8.1-KB2693643-x64.msu' $rsat1709 =…

Project Servers Virtualization

Project Scope: The scope of this project is limited to stabilizing production environment by ensuring…
Other project: DragonCoin.com