Enabling Nested Virtualization
By enabling nested virtualization, you can run virtual machines (VMs) within other VMs. This option is only available for VMs created in dedicated groups. For more information, see About Dedicated Groups.
This technical guide explains how to enable and use nested virtualization on Rocky Linux and Windows Server 2019.
In this example procedure, the image used for the nested VM is based on a live CD. The operating system will be loaded directly into the nested VM’s memory. |
Enabling Nested Virtualization on Linux
-
Create a dedicated VM, for example using the following parameters:
$ osc-cli api CreateVms \ --profile "default" \ --VmType "tinav4.c16r32p2" \ --ImageId "ami-e58ac287" \ --KeypairName "MyKeyPair" \ --NestedVirtualization True \ --Placement '{"Tenancy": "dedicated"}' --BlockDeviceMappings '[ { "Bsu": {"VolumeSize": 50}, "DeviceName": "/dev/sda1" } ]'
This command contains the following attributes that you need to specify:
-
(optional)
profile
: The named profile you want to use, created when configuring OSC CLI. For more information, see Installing and Configuring OSC CLI. -
VmType
: The type of the VM. -
ImageId
: The ID of the OMI to use to create the VM. For more information, see Official OMIs Reference. -
KeypairName
: The name of your keypair. -
NestedVirtualization
: Must be set totrue
to enable nested virtualization. -
Placement
: The tenancy option for the VM. Must be set todedicated
. For more information, see About VMs > VM Tenancy and Dedicated VMs. -
BlockDeviceMappings
: One or more block device mappings. For more information, see Defining Block Device Mappings.Make sure your host VM has enough memory and cores to run nested VMs.
-
-
Access your VM. For more information, see Accessing a Linux VM.
-
Run the following command to update the existing system packages:
$ sudo dnf update
-
(optional) Make sure nested virtualization is enabled:
$ cat /proc/cpuinfo | egrep "vmx|svm"
You must get
vmx
orsvm
in the result, depending on if your VM has an Intel or an AMD CPU. -
Install required packages:
$ sudo dnf install @virt virt-top libguestfs-tools virt-install
-
Start and enable the libvirtd daemon:
$ sudo systemctl enable --now libvirtd
-
Download the Linux virtual image you want to run.
In this example, we are downloading Debian 11:$ curl -O https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/debian-11.5.0-amd64-DVD-1.iso
-
Make sure QEMU can access and read your file:
$ sudo cp /home/outscale/debian-11.5.0-amd64-DVD-1.iso /var/lib/libvirt/images/debian-11.5.0-amd64-DVD-1.iso
-
Create a virtual hard drive:
$ sudo qemu-img create -f qcow2 /var/lib/libvirt/images/debian.qcow2 30G
This command contains the following attributes that you need to specify:
-
debian
: The name of the virtual hard drive you want to create. -
30
: The space you want to assign to the virtual hard drive.
-
-
Create a VM within your VM:
$ sudo virt-install \ --virt-type kvm \ --name Debian11 \ --ram 2024 \ --disk /var/lib/libvirt/images/debian.qcow2 \ --network network=default \ --graphics vnc,listen=0.0.0.0 \ --noautoconsole \ --os-type=linux \ --os-variant=generic \ --cdrom=/var/lib/libvirt/images/debian-11.5.0-amd64-DVD-1.iso
This command contains the following attributes that you need to specify:
-
name
: The name you want to give to your VM -
ram
: The amount of memory you want to assign your VM, in megabytes (MB) -
disk
: The path of the virtual hard drive created -
cd-rom
: The path of the ISO file you want to use to install the VM
-
|
Enabling Nested Virtualization on Windows Server 2019
-
Create a dedicated VM, for example using the following parameters:
$ osc-cli api CreateVms \ --profile "default" \ --VmType "tinav4.c16r32p2" \ --ImageId "ami-f4901add" \ --KeypairName "MyKeyPair" \ --NestedVirtualization True \ --Placement '{"Tenancy": "dedicated"}'
This command contains the following attributes that you need to specify:
-
(optional)
profile
: The named profile you want to use, created when configuring OSC CLI. For more information, see Installing and Configuring OSC CLI. -
VmType
: The type of the VM. -
ImageId
: The ID of the OMI to use to create the VM. For more information, see Official OMIs Reference. -
KeypairName
: The name of your keypair. -
NestedVirtualization
: Must be set totrue
to enable nested virtualization. -
Placement
: The tenancy option for the VM. Must be set todedicated
. For more information, see About VMs > VM Tenancy and Dedicated VMs.Make sure your host VM has enough memory, cores, and volume space to run nested VMs.
-
-
Access your VM. For more information, see Accessing a Windows VM.
-
Click the Start menu and type Turn Windows features on or off.
-
The Add Roles and Features Wizard window opens.
-
Select the installation type you prefer.
Click Next. -
Select the destination on which to install roles and features.
Click Next. -
Make sure Hyper-V is checked.
A window opens. Make sure Include management tools (if applicable) is checked. -
Click Add Features.
-
Continue the installation.
-
Restart your VM.
-
Open Hyper-V Manager from the Start menu.
-
Select your device name.
-
Click New then Virtual Machine in the right action menu.
You can also click Quick Create and select one of the operating system images available.
-
Type a name for your VM.
Click Next. -
Select Generation 1.
Click Next. -
Make sure to allocate at least 4096 MB of startup memory.
Click Next. -
(optional) Select a network adapter.
Click Next. -
Select Create a virtual hard disk. Make sure the size is less than 400 GB.
Click Next. -
Select Install an operating system from a bootable CD/DVD-ROM > Image file (.iso), and import the image of the operating system you want to run.
-
Select Next then Finish.
-
Right-click your newly created VM and select Start.
Repeat the operation then select Connect.
Related Pages