Questo contenuto non è disponibile nella lingua selezionata.

Chapter 3. Creating virtual machines


To create a virtual machine (VM) in RHEL 10, you can use the command line or the RHEL 10 web console.

3.1. Creating virtual machines by using the command line

To create a virtual machine (VM) on your RHEL 10 host, you can use the virt-install utility.

Prerequisites

  • Virtualization is enabled on your host system. For instructions, see Preparing RHEL to host virtual machines.
  • You have a sufficient amount of system resources to allocate to your VMs, such as disk space, RAM, or CPUs. The recommended values might vary significantly depending on the intended tasks and workload of the VMs.
  • An operating system (OS) installation source is available locally or on a network. This can be one of the following:

    • An ISO image of an installation medium
    • A disk image of an existing VM installation

      Warning

      Installing from a host CD-ROM or DVD-ROM device is not possible in RHEL 10. If you select a CD-ROM or DVD-ROM as the installation source when using any VM installation method available in RHEL 10, the installation will fail. For more information, see the Red Hat Knowledgebase.

      Also note that Red Hat provides support only for a limited set of guest operating systems.

  • To create a VM that uses the system connection of libvirt, you must have root privileges or be in the libvirt user group on the host. For more information, see User-space connection types for virtualization.
  • Optional: A Kickstart file can be provided for faster and easier configuration of the installation.

Procedure

  • To create a VM and start its OS installation, use the virt-install command, along with the following mandatory arguments:

    --name
    the name of the new machine
    --memory
    the amount of allocated memory
    --vcpus
    the number of allocated virtual CPUs
    --disk
    the type and size of the allocated storage
    --cdrom or --location
    the type and location of the OS installation source
    --osinfo

    the OS type and version that you intend to install

    Note

    To list all available values for the --osinfo argument, run the virt-install --osinfo list command.

    For more details, you can also run the osinfo-query os command. However, you might need to install the libosinfo-bin package first.

    Based on the chosen installation method, the necessary options and values can vary. See the following examples for more details.

  • Create a VM and install an OS from a local ISO file:

    • The following command creates a VM named demo-guest1 that installs the Windows 10 OS from an ISO image locally stored in the /home/username/Downloads/Win10install.iso file. This VM is also allocated with 2048 MiB of RAM and 2 vCPUs, and an 80 GiB qcow2 virtual disk is automatically configured for the VM.

      # virt-install \
          --name demo-guest1 --memory 2048 \
          --vcpus 2 --disk size=80 --osinfo win10 \
          --cdrom /home/username/Downloads/Win10install.iso
  • Create a VM, install an OS from a live CD, and do not create a permanent disk:

    • The following command creates a VM named demo-guest2 that uses the /home/username/Downloads/rhel10.iso image to run a RHEL 10 OS from a live CD. No disk space is assigned to this VM, so changes made during the session will not be preserved. In addition, the VM is allocated with 4096 MiB of RAM and 4 vCPUs.

      # virt-install \
          --name demo-guest2 --memory 4096 --vcpus 4 \
          --disk none --livecd --osinfo rhel10.0 \
          --cdrom /home/username/Downloads/rhel10.iso
  • Create a VM and import an existing disk image:

    • The following command creates a RHEL 10 VM named demo-guest3 that connects to an existing disk image, /home/username/backup/disk.qcow2. This is similar to physically moving a hard drive between machines, so the OS and data available to demo-guest3 are determined by how the image was handled previously. In addition, this VM is allocated with 2048 MiB of RAM and 2 vCPUs.

      # virt-install \
          --name demo-guest3 --memory 2048 --vcpus 2 \
          --osinfo rhel10.0 --import \
          --disk /home/username/backup/disk.qcow2

      Note that you must use the --osinfo option when importing a disk image. If it is not provided, the performance of the created VM will be negatively affected.

  • Create a VM and install an OS from a remote URL:

    • The following command creates a VM named demo-guest4 that installs from the http://example.com/OS-install URL. For the installation to start successfully, the URL must contain a working OS installation tree. In addition, the OS is automatically configured by using the /home/username/ks.cfg kickstart file. This VM is also allocated with 2048 MiB of RAM, 2 vCPUs, and a 160 GiB qcow2 virtual disk.

      # virt-install \
          --name demo-guest4 --memory 2048 --vcpus 2 --disk size=160 \
          --osinfo rhel10.0 --location http://example.com/OS-install \
          --initrd-inject /home/username/ks.cfg --extra-args="inst.ks=file:/ks.cfg console=tty0 console=ttyS0,115200n8"
  • Create a VM and install an OS in a text-only mode:

    • The following command creates a VM named demo-guest5 that installs from a RHEL10.iso image file in text-only mode, without graphics. It connects the guest console to the serial console. The VM has 16384 MiB of memory, 16 vCPUs, and 280 GiB disk. This kind of installation is useful when connecting to a host over a slow network link.

      # virt-install \
          --name demo-guest5 --memory 16384 --vcpus 16 --disk size=280 \
          --osinfo rhel10.0 --location RHEL10.iso \
          --graphics none --extra-args='console=ttyS0'
  • Create a VM and install an OS in graphical mode:

    • The following command creates a VM named demo-guest-6, which has the same configuration as demo-guest5, but provides the host device pci_0003_00_00_0 for networking and configures graphics for a graphical installation.

      # virt-install \
          --name demo-guest6 --memory 16384 --vcpus 16 --disk size=280 \
          --os-info rhel10.0 --location RHEL10.iso --graphics vnc,listen=0.0.0.0,5901 \
          --input keyboard,bus=virtio --input mouse,bus=virtio \
          --hostdev pci_0003_00_00_0 --network none

      Note that the name of the host device available for installation can be retrieved by using the virsh nodedev-list --cap pci command. To use the installation GUI, you can connect any VNC viewer to the host’s IP at VNC port 5901 when the installation starts. However, you might have to open this port in the firewall first, for example:

      # firewall-cmd --add-port 5901/tcp
  • Create a VM on a remote host:

    • The following command creates a VM named demo-guest7, which has the same configuration as demo-guest5, but resides on the 192.0.2.1 remote host.

      # virt-install \
          --connect qemu+ssh://root@192.0.2.1/system --name demo-guest7 --memory 16384 \
          --vcpus 16 --disk size=280 --osinfo rhel10.0 --location RHEL10.iso \
          --graphics none --extra-args='console=ttyS0'
  • Create a VM on a remote host and use a DASD mediated device as storage:

    • The following command creates a VM named demo-guest-8, which has the same configuration as demo-guest5, but for its storage, it uses a DASD mediated device mdev_30820a6f_b1a5_4503_91ca_0c10ba12345a_0_0_29a8, and assigns it device number 1111.

      # virt-install \
          --name demo-guest8 --memory 16384 --vcpus 16 --disk size=280 \
          --osinfo rhel10.0 --location RHEL10.iso --graphics none \
          --disk none --hostdev mdev_30820a6f_b1a5_4503_91ca_0c10ba12345a_0_0_29a8,address.type=ccw,address.cssid=0xfe,address.ssid=0x0,address.devno=0x1111,boot-order=1 \
          --extra-args 'rd.dasd=0.0.1111'

      Note that the name of the mediated device available for installation can be retrieved by using the virsh nodedev-list --cap mdev command.

  • For additional options and examples of virt-install commands, see the virt-install (1) man page on your system.

Verification

  • If the VM is created successfully, a virt-viewer window opens with a graphical console of the VM and starts the guest OS installation.

Troubleshooting

  • If virt-install fails with a cannot find default network error:

    • Ensure that the libvirt-daemon-config-network package is installed:

      # dnf info libvirt-daemon-config-network
      Installed Packages
      Name         : libvirt-daemon-config-network
      [...]
    • Verify that the libvirt default network is active and configured to start automatically:

      # virsh net-list --all
       Name      State    Autostart   Persistent
      --------------------------------------------
       default   active   yes         yes
    • If it is not, activate the default network and set it to auto-start:

      # virsh net-autostart default
      Network default marked as autostarted
      
      # virsh net-start default
      Network default started
      • If activating the default network fails with the following error, the libvirt-daemon-config-network package has not been installed correctly.

        error: failed to get network 'default'
        error: Network not found: no network with matching name 'default'

        To fix this, re-install libvirt-daemon-config-network:

        # dnf reinstall libvirt-daemon-config-network
      • If activating the default network fails with an error similar to the following, a conflict has occurred between the default network’s subnet and an existing interface on the host.

        error: Failed to start network default
        error: internal error: Network is already in use by interface ens2

        To fix this, use the virsh net-edit default command and change the 192.0.2.* values in the configuration to a subnet not already in use on the host.

3.2. Creating virtual machines by using the web console

To create virtual machines (VMs) in a GUI on a RHEL 10 host, you can use the web console.

3.2.1. Creating new virtual machines by using the web console

You can create a new virtual machine (VM) on a previously prepared host machine by using the RHEL 10 web console.

Prerequisites

Procedure

  1. In the Virtual Machines interface of the web console, click Create VM.

    The Create new virtual machine dialog appears.

    Image displaying the Create new virtual machine dialog box.
  2. Enter the basic configuration of the VM you want to create.

    • Name - The name of the VM.
    • Connection - The level of privileges granted to the session. For more details, expand the associated dialog box in the web console.
    • Installation type - The installation can use a local installation medium, a URL, a PXE network boot, a cloud base image, or download an operating system from a limited set of guest operating systems.
    • Operating system - The guest operating system running on the VM. Note that Red Hat provides support only for a limited set of guest operating systems.

      Note

      To download and install Red Hat Enterprise Linux directly from web console, you must add an offline token in the Offline token field.

    • Storage - The type of storage.
    • Storage Limit - The amount of storage space.
    • Memory - The amount of memory.
  3. Create the VM:

    • If you want the VM to automatically install the operating system, click Create and run.
    • If you want to edit the VM before the operating system is installed, click Create and edit.
    Note

    If you do not want to install an operating system immediately after creating a VM, you can do it later by selecting the VM in the Virtual Machines interface and clicking the Install button.

3.2.2. Creating virtual machines by importing disk images with the web console

You can create a virtual machine (VM) by importing a disk image of an existing VM installation in the RHEL 10 web console.

Prerequisites

Procedure

  1. In the Virtual Machines interface of the web console, click Import VM.

    The Import a virtual machine dialog appears.

  2. Enter the basic configuration of the VM you want to create:

    • Name - The name of the VM.
    • Disk image - The path to the existing disk image of a VM on the host system.
    • Operating system - The operating system running on a VM disk. Note that Red Hat provides support only for a limited set of guest operating systems.
    • Memory - The amount of memory to allocate for use by the VM.
  3. Import the VM:

    • To install the operating system on the VM without additional edits to the VM settings, click Import and run.
    • To edit the VM settings before the installation of the operating system, click Import and edit.

By default, distro cloud images have no login accounts. However, by using the RHEL web console, you can now create a virtual machine (VM) and specify the root and user account login credentials, which are then passed to cloud-init.

Prerequisites

  • You have installed the RHEL 10 web console.

    For instructions, see Installing and enabling the web console.

  • The web console VM plug-in is installed on your system.
  • Virtualization is enabled on your host system.
  • You have a sufficient amount of system resources to allocate to your VMs, such as disk space, RAM, or CPUs. The recommended values may vary significantly depending on the intended tasks and workload of the VMs.

Procedure

  1. Log in to the RHEL 10 web console.
  2. In the Virtual Machines interface of the web console, click Create VM.

    The Create new virtual machine dialog appears.

  3. In the Name field, enter a name for the VM.
  4. On the Details tab, in the Installation type field, select Cloud base image.
  5. In the Installation source field, set the path to the image file on your host system.
  6. Enter the configuration for the VM that you want to create.

    • Operating system - The VM’s operating system. Note that Red Hat provides support only for a limited set of guest operating systems.
    • Storage - The type of storage with which to configure the VM.
    • Storage Limit - The amount of storage space with which to configure the VM.
    • Memory - The amount of memory with which to configure the VM.
  7. Click the Automation tab and set your cloud authentication credentials:

    • Root password - Enter a root password for your VM. Leave the field blank if you do not want to set a root password.
    • User login - Enter a cloud-init user login. Leave this field blank if you do not want to create a user account.
    • User password - Enter a password. Leave this field blank if you do not want to create a user account.
  8. Click Create and run.

    The VM is created.

3.3. Creating Windows virtual machines

You can create a fully-virtualized Windows machine on a RHEL 10 host, launch the graphical Windows installer inside the virtual machine (VM), and optimize the installed Windows guest operating system (OS).

To create the VM and to install the Windows guest OS, use the virt-install command or the RHEL 10 web console.

Prerequisites

  • A Windows OS installation source, which can be one of the following, and be available locally or on a network:

    • An ISO image of an installation medium
    • A disk image of an existing VM installation
  • A storage medium with the KVM virtio drivers.

    To create this medium, see Preparing virtio driver installation media on a host machine.

  • If you are installing Windows 11, the edk2-ovmf, swtpm and libtpms packages must be installed on the host.

Procedure

  1. Create the VM. For instructions, see Creating virtual machines, but be aware of the following specifics.

    • If you are using the virt-install utility to create the VM, add the following options to the command:

      • The storage medium with the KVM virtio drivers. For example:

        --disk path=/usr/share/virtio-win/virtio-win.iso,device=cdrom
      • The Windows version you will install. For example, for Windows 10 and 11:

        --os-variant win10

        For a list of available Windows versions and the appropriate option, use the following command:

        # osinfo-query os
      • If you are installing Windows 11, enable Unified Extensible Firmware Interface (UEFI) and virtual Trusted Platform Module (vTPM):

        --boot uefi

    • If using the web console to create the VM, specify your version of Windows in the Operating system field of the Create new virtual machine window.

      • If you are installing earlier Windows versions than Windows 11 and Windows Server 2022, start the installation by clicking Create and run.
      • If you are installing Windows 11, or you want to use additional Windows Server 2022 features, confirm by clicking Create and edit and enable UEFI and vTPM using the CLI:

        1. Open the VM’s XML configuration:

          # virsh edit windows-vm
        2. Add the firmware='efi' option to the os element:

          <os firmware='efi'>
            <type arch='x86_64' machine='pc-q35-6.2'>hvm</type>
            <boot dev='hd'/>
          </os>
        3. Add the tpm device inside the devices element:

          <devices>
            <tpm model='tpm-crb'>
              <backend type='emulator' version='2.0'/>
            </tpm>
          </devices>
        4. Start the Windows installation by clicking Install in the Virtual machines table.
  2. Install the Windows OS in the VM.

    For information about how to install a Windows operating system, refer to the relevant Microsoft installation documentation.

  3. If you are using the web console to create the VM, attach the storage medium with virtio drivers to the VM by using the Disks interface.

    For instructions, see Attaching existing disks to virtual machines by using the web console.

  4. Configure KVM virtio drivers in the Windows guest OS. For details, see Installing KVM paravirtualized drivers for Windows virtual machines.
  5. Optional: Optimize the performance of the Windows VM. For details, see Optimizing Windows virtual machines.

3.4. Enabling QEMU Guest Agent features on your virtual machines

To use certain features on a virtual machine (VM) hosted on your RHEL 10 system, you must first configure the VM to use the QEMU Guest Agent (GA).

For a complete list of these features, see Virtualization features that require QEMU Guest Agent.

3.4.1. Enabling QEMU Guest Agent on Windows guests

To allow a RHEL host to perform a certain subset of operations on a Windows virtual machine (VM), you must enable the QEMU Guest Agent (GA).

To do so, add a storage device that contains the QEMU Guest Agent installer to an existing VM or when creating a new VM, and install the drivers on the Windows guest operating system.

  • To install the GA on a command line, use the Microsoft Windows Installer (MSI).
  • To install the Guest Agent (GA) by using the graphical interface, see the following procedure.

Prerequisites

Procedure

  1. In the Windows guest operating system, open the File Explorer application.
  2. Click This PC.
  3. In the Devices and drives pane, open the virtio-win medium.
  4. Open the guest-agent folder.
  5. Based on the operating system installed on the VM, run one of the following installers:

    • If using a 32-bit operating system, run the qemu-ga-i386.msi installer.
    • If using a 64-bit operating system, run the qemu-ga-x86_64.msi installer.
  6. Optional: If you want to use the para-virtualized serial driver (virtio-serial) as the communication interface between the host and the Windows guest, verify that the virtio-serial driver is installed on the Windows guest.

    For more information about installing virtio drivers, see: Installing virtio drivers on a Windows guest.

Verification

  1. On your Windows VM, navigate to the Services window.

    Computer Management > Services

  2. Ensure that the status of the QEMU Guest Agent service is Running.

3.4.2. Virtualization features that require QEMU Guest Agent

If you enable QEMU Guest Agent (GA) on a virtual machine (VM), you can use the following commands on your host to manage the VM:

virsh shutdown --mode=agent
This shutdown method is more reliable than virsh shutdown --mode=acpi, because virsh shutdown used with QEMU GA is guaranteed to shut down a cooperative guest in a clean state.
virsh domfsfreeze and virsh domfsthaw
Freezes the guest file system in isolation.
virsh domfstrim

Instructs the guest to trim its file system, which helps to reduce the data that needs to be transferred during migrations.

Important

If you want to use this command to manage a Linux VM, you must also set the following SELinux boolean in the guest operating system:

# setsebool virt_qemu_ga_read_nonsecurity_files on
virsh domtime
Queries or sets the guest’s clock.
virsh setvcpus --guest
Instructs the guest to take CPUs offline, which is useful when CPUs cannot be hot-unplugged.
virsh domifaddr --source agent
Queries the guest operating system’s IP address by using QEMU GA. For example, this is useful when the guest interface is directly attached to a host interface.
virsh domfsinfo
Shows a list of mounted file systems in the running guest.
virsh set-user-password
Sets the password for a given user account in the guest.
virsh set-user-sshkeys

Edits the authorized SSH keys file for a given user in the guest.

Important

If you want to use this command to manage a Linux VM, you must also set the following SELinux boolean in the guest operating system:

# setsebool virt_qemu_ga_manage_ssh on
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2026 Red Hat
Torna in cima