InformationNested Virtualization means that user can enable Hyper-V on existing virtual machines, and run virtual machines and Windows Sandbox on them.
To make Nested Virtualization to work, it and MAC Address Spoofing or NAT networking must be enabled separately for each first level host VM. The script in this tutorial will use MAC Spoofing.
Wikipedia:
MAC spoofing is a technique for changing a factory-assigned Media Access Control (MAC) address of a network interface on a networked device. The MAC address that is hard-coded on a network interface controller (NIC) cannot be changed. However, many drivers allow the MAC address to be changed. Additionally, there are tools which can make an operating system believe that the NIC has the MAC address of a user's choosing. The process of masking a MAC address is known as MAC spoofing. Essentially, MAC spoofing entails changing a computer's identity, for any reason, and it is relatively easy.
To be honest, this is a feature that only interests real virtualization enthusiasts. One practical use is to run emulators or other software that requires regular restarts on a second level nested VM on first level VM, to avoid restarting host.
I use Nested Virtualization to save current state of Windows Sandbox. Because Sandbox will be completely reset when shut down / turned off, running it on a virtual machine is the most practical way to save its state by using Hyper-V Production Checkpoints.
If you want to enable Hyper-V on your Hyper-V virtual machines, this tutorial shows how to do it with a simple PowerShell script.
1) The script to enable Nested Virtualization:
Code:########################################################## # # Nested.ps1 # # A PS Script to enable nested virtualization on a VM. # # You are free to edit & share this script as long as # source TenForums.com is mentioned. # # *** Twitter.com/TenForums *** Facebook.com/TenForums *** # # Script by Kari # - TenForums.com/members/kari.html # - Twitter.com/KariTheFinn # - YouTube.com/KariTheFinn # - https://Win10.guru # # 'Use-RunAs' function to check if script was launched # in normal user mode and elevating it if necessary by # Matt Painter (Microsoft TechNet Script Center) # https://gallery.technet.microsoft.com/scriptcenter/ # ########################################################## ########################################################## # Checking if PS is running elevated. If not, elevating it ########################################################## function Use-RunAs { # Check if script is running as Administrator and if not elevate it # Use Check Switch to check if admin param([Switch]$Check) $IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()` ).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") if ($Check) { return $IsAdmin } if ($MyInvocation.ScriptName -ne "") { if (-not $IsAdmin) { try { $arg = "-file `"$($MyInvocation.ScriptName)`"" Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList $arg -ErrorAction 'stop' } catch { Write-Warning "Error - Failed to restart script elevated" break } exit } } } Use-RunAs ########################################################## # Show short instructions to user ########################################################## cls Write-Host Write-Host ' This script will enable nested virtualization on a virtual machine. ' Write-Host ' When nested virtualization is enabled, you can use Hyper-V on a VM' Write-Host ' to run virtual machines on it.' Write-Host Write-Host ' Nested virtualization also allows running Windows Sandbox container' Write-Host ' on a VM (Windows 10 build 18305 or later required).' Write-Host Write-Host ' Notice that Hyper-V and Sandbox are not available in W10 Home edition.' Write-Host ' ' Write-Host Write-Host ' ' -NoNewline pause cls Write-Host Write-Host ' Found following virtual machines:' #Write-Host Get-VM | Format-Table -Property VMName #Write-Host Write-Host ' Please enter the name of the virtual machine on which you want' Write-Host ' nested virtualization to be enabled.' Write-Host $VM = Read-Host -Prompt ' Virtual machine name ' Set-VMProcessor -VMName $VM -ExposeVirtualizationExtensions $true Get-VMNetworkAdapter -VMName $VM | Set-VMNetworkAdapter -MacAddressSpoofing On cls Write-Host Write-Host ' Nested virtualization on virtual machine'$VM 'enabled. You can' Write-Host ' now enable and setup Hyper-V and / or Windows Sandbox on it.' Write-Host Write-Host ' More Windows 10 tips, tricks, videos & tutorials on' Write-Host Write-Host ' https://www.TenForums.com' -ForegroundColor Yellow Write-Host Write-Host ' * Twitter.com/TenForums * Facebook.com/TenForums * ' -ForegroundColor Yellow Write-Host Write-Host ' Script by Kari' Write-Host ' - TenForums.com/members/kari.html' Write-Host ' - Twitter.com/KariTheFinn' Write-Host ' - YouTube.com/KariTheFinn' write-Host ' - https://Win10.guru' Write-Host Write-Host Write-Host ' ' -NoNewline pause
You can download the script from my OneDrive:
Download
As always with downloaded content, be sure to unblock downloaded file before using it!
2) Check that running local scripts in PowerShell is enabled (tutorial):
3) Be sure the virtual machine on which you want to allow nested virtualization is turned off. Run the script by right clicking it and selecting Run with PowerShell:
Alternatively, if using PowerShell ISE, open the script from File menu and press F5 to run it:
4) If PowerShell warns you about Execution Policy change, press Y to accept it:
5) Running the script, it will auto elevate (switch to admin mode if started in normal user mode), and lists all current Hyper-V virtual machines on your host:
6) Type or Copy & Paste the name of the virtual machine on which you want to enable nested virtualization, press Enter.
TipIn PowerShell (and in Command Prompt), you cannot copy using context menu (mouse right click, select Copy). Also, by default Copy & Paste with keyboard shortcuts is disabled, although it can be enabled in PowerShell (and Command Prompt) Properties in Options tab.
Instead, mark the string you want to copy with mouse, in this case name of a VM. To mark a string, press and hold down mouse left button on top of first character, and move to end of the string you want to copy. Release the mouse button, press Enter to copy.
Pasting is done with right mouse button.
7) That's it. Nested virtualization on selected VM is now enabled:
8) Start the VM, setup Hyper-V on it (tutorial). In screenshot I am running Windows 7 on a Hyper-V VM on Windows 10 Hyper-V VM running on my host computer:
Happy virtualization, geeks!
Kari