Enabling Nested Virtualization

By enabling nested virtualization, you can run instances within other instances. This option is only available for dedicated instances.

This technical guide explains how to enable and use nested virtualization on Rocky Linux, Windows 10, and Windows Server 2019.

Enabling Nested Virtualization on Linux

  1. Create a dedicated instance, 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 instance.

    • ImageId: The ID of the OMI to use to launch the instance. For more information, see Official OMIs Reference.

    • KeypairName: The name of your keypair.

    • NestedVirtualization: Must be set to true to enable nested virtualization.

    • Placement: The tenancy option for the instance. Must be set to dedicated. For more information, see About Instances > Instance Tenancy.

    • BlockDeviceMappings: One or more block device mappings. For more information, see Defining Block Device Mappings.

      Make sure your host instance has enough memory and cores to run nested instances.

  2. Access your instance. For more information, see Accessing a Linux Instance from a Linux or macOS.

  3. Run the following command to update the existing system packages:

    $ sudo dnf update
  4. (optional) Make sure nested virtualization is enabled:

    $ cat /proc/cpuinfo | egrep "vmx|svm"

    You must get vmx or svm in the result, depending on if your instance has an Intel or an AMD CPU.

  5. Install required packages:

    $ sudo dnf install @virt virt-top libguestfs-tools virt-install
  6. Start and enable the libvirtd daemon:

    $ sudo systemctl enable --now libvirtd
  7. 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

    Nested instances can only be based on outside images (.iso files), not OUTSCALE machine images (OMIs).

  8. 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
  9. 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.

  10. Create an instance within your instance:

    $ 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 instance

    • ram: The amount of memory you want to assign your instance, 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 instance

  • Run the following command to list all running and stopped instances:

    $ sudo virsh list --all
  • You can now use SSH to connect to the nested instance.

Enabling Nested Virtualization on Windows 10

  1. Create a dedicated instance, for example using the following parameters:

    $ osc-cli api CreateVms \
        --profile "default" \
        --VmType "tinav4.c16r32p2" \
        --ImageId "ami-dd45b6b2" \
        --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 instance.

    • ImageId: The ID of the OMI to use to launch the instance. For more information, see Official OMIs Reference.

    • KeypairName: The name of your keypair.

    • NestedVirtualization: Must be set to true to enable nested virtualization.

    • Placement: The tenancy option for the instance. Must be set to dedicated. For more information, see About Instances > Instance Tenancy.

      Make sure your host instance has enough memory, cores, and volume space to run nested instances.

  2. Access your instance. For more information, see Accessing a Windows Instance.

  3. Click the Start menu, type Turn Windows features on or off, and open it.

  4. The Windows Features dialog box opens.
    Make sure Hyper-V and its subdirectories are selected.

  5. Click Ok.
    Restart your instance once you are asked to.

  6. Open Hyper-V Manager from the Start menu.

  7. Select your device name.

  8. 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.

  9. Type a name for your instance.
    Click Next.

  10. Select Generation 1.
    Click Next.

  11. Make sure to allocate at least 4096 MB of startup memory.
    Click Next.

  12. (optional) Select a network adapter.
    Click Next.

  13. Select Create a virtual hard disk. Make sure the size is less than 400 GB.
    Click Next.

  14. 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.

  15. Select Next then Finish.

  16. Right-click your newly created instance and select Start.
    Repeat the operation then select Connect.

Enabling Nested Virtualization on Windows Server 2019

  1. Create a dedicated instance, 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 instance.

    • ImageId: The ID of the OMI to use to launch the instance. For more information, see Official OMIs Reference.

    • KeypairName: The name of your keypair.

    • NestedVirtualization: Must be set to true to enable nested virtualization.

    • Placement: The tenancy option for the instance. Must be set to dedicated. For more information, see About Instances > Instance Tenancy.

      Make sure your host instance has enough memory, cores, and volume space to run nested instances.

  2. Access your instance. For more information, see Accessing a Windows Instance.

  3. Click the Start menu and type Turn Windows features on or off.

  4. The Add Roles and Features Wizard window opens.

  5. Select the installation type you prefer.
    Click Next.

  6. Select the destination on which to install roles and features.
    Click Next.

  7. Make sure Hyper-V is checked.
    A window opens. Make sure Include management tools (if applicable) is checked.

  8. Click Add Features.

  9. Continue the installation.

  10. Restart your instance.

  11. Open Hyper-V Manager from the Start menu.

  12. Select your device name.

  13. 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.

  14. Type a name for your instance.
    Click Next.

  15. Select Generation 1.
    Click Next.

  16. Make sure to allocate at least 4096 MB of startup memory.
    Click Next.

  17. (optional) Select a network adapter.
    Click Next.

  18. Select Create a virtual hard disk. Make sure the size is less than 400 GB.
    Click Next.

  19. 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.

  20. Select Next then Finish.

  21. Right-click your newly created instance and select Start.
    Repeat the operation then select Connect.

Related Pages