13.4. Attaching storage to virtual machines


To add storage to a virtual machine (VM), you can attach a storage resource to the VM as a virtual disk. Similarly to physical storage devices, virtual disks are independent from the VMs that they are attached to, and can be moved to other VMs.

You can use multiple types of storage resources to add a virtual disk to a VM.

To provide local storage for a virtual machine, the easiest option typically is to attach a file-based virtual disk with the .qcow2 or .raw format.

To do so on the command line, you can use one of the following methods:

  • Create a file-based storage volume in a directory-based storage pool managed by libvirt. This requires multiple steps, but provides better integration with the hypervisor.

    Note that a default directory-based storage volume is created automatically when creating the first VM on your RHEL 10 host. The name of this storage pool is based on the name of the directory in which you save the disk image. For example, by default, in the system session of libvirt, the disk image is saved in the /var/lib/libvirt/images/ directory and the storage pool is named images.

  • Use the qemu-img command to create a virtual disk as a file on the host file system. This is a faster method, but does not provide integration with libvirt.

    As a result, virtual disks created by using qemu-img are more difficult to manage after creation.

注意

A file-based virtual disk can also be created and attached when creating a new VM on the command line. To do so, use the --disk option with the virt-install utility. For detailed instructions, see Creating virtual machines.

Procedure

  1. Optional: If you want to create a virtual disk as a storage volume, but you do not want to use the default images storage pool or another existing storage pool on the host, create and set up a new directory-based storage pool.

    1. Configure a directory-type storage pool. For example, to create a storage pool named guest_images_dir that uses the /guest_images directory:

      # virsh pool-define-as guest_images_dir dir --target "/guest_images"
      Pool guest_images_dir defined
    2. Create a target path for the storage pool based on the configuration you previously defined.

      # virsh pool-build guest_images_dir
        Pool guest_images_dir built
    3. Start the storage pool.

      # virsh pool-start guest_images_dir
        Pool guest_images_dir started
    4. Optional: Set the storage pool to start on host boot.

      # virsh pool-autostart guest_images_dir
        Pool guest_images_dir marked as autostarted
    5. Optional: Verify that the storage pool is in the running state. Check if the sizes reported are as expected and if autostart is configured correctly.

      # virsh pool-info guest_images_dir
        Name:           guest_images_dir
        UUID:           c7466869-e82a-a66c-2187-dc9d6f0877d0
        State:          running
        Persistent:     yes
        Autostart:      yes
        Capacity:       458.39 GB
        Allocation:     197.91 MB
        Available:      458.20 GB
  2. Create a file-based virtual disk. To do so, use one of the following methods:

    • To quickly create a file-based VM disk not managed by libvirt, use the qemu-img utility.

      For example, the following command creates a qcow2 disk image named test-image with the size of 30 gigabytes:

      # qemu-img create -f qcow2 test-image 30G
      
      Formatting 'test-image', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=32212254720 lazy_refcounts=off refcount_bits=16
    • To create a file-based VM disk managed by libvirt, define the disk as a storage volume based on an existing directory-based storage pool.

      For example, the following command creates a 20 GB qcow2 volume named vm-disk1 and based on the guest_images_dir storage pool:

      # virsh vol-create-as --pool guest_images_dir --name vm-disk1 --capacity 20GB --format qcow2
      
      Vol vm-disk1 created
  3. Locate the virtual disk that you created:

    • For a VM disk created with qemu-img, this is typically your current directory.
    • For a storage volume, examine the storage pool that the volume belongs to:

      # virsh vol-list --pool guest_images_dir --details
      
       Name        Path                          Type   Capacity    Allocation
      --------------------------------------------------------------------------
       vm-disk1    /guest-images/vm-disk1      file   20.00 GiB   196.00 KiB
  4. Find out which target devices are already used in the VM to which you want to attach the disk:

    # virsh domblklist --details <vm-name> Type Device Target Source ---------------------------------------------------------------- file disk *vda      /home/VirtualMachines/vm-name.qcow2
     file   cdrom    vdb      -
  5. Optional: Check the consistency of the disk, to avoid issues with data corruption or disk fragmentation. For instructions, see Checking the consistency of a virtual disk.
  6. Attach the disk to a VM by using the virsh attach-disk command. Provide a target device that is not in use in the VM.

    For example, the following command attaches the previously created test-disk1 as the vdc device to the testguest1 VM:

    # virsh attach-disk testguest1 /guest-images/vm-disk1 vdc --persistent

Verification

  1. Inspect the XML configuration of the VM to which you attached the disk to see if the configuration is correct.

    # virsh dumpxml testguest1
    
    ...
        <disk type='file' device='disk'>
          <driver name='qemu' type='qcow2' discard='unmap'/>
          <source file='/guest-images/vm-disk1' index='1'/>
          <backingStore/>
          <target dev='vdc' bus='virtio'/>
          <alias name='virtio-disk2'/>
          <address type='drive' controller='0' bus='0' target='0' unit='0'/>
        </disk>
    ...
  2. In the guest operating system of the VM, confirm that the disk image has become available as an un-formatted and un-allocated disk.

To provide local storage for a virtual machine, the easiest option typically is to attach a file-based virtual disk with the .qcow2 or .raw format.

To do so, create a file-based storage volume in a directory-based storage pool managed by libvirt. A default directory-based storage volume is created automatically when creating the first VM on your RHEL 10 host. The name of this storage pool is based on the name of the directory in which you save the disk image. For example, by default, in the system session of libvirt, the disk image is saved in the /var/lib/libvirt/images/ directory and the storage pool is named images.

注意

A file-based virtual disk can also be created and attached when creating a new VM in the web console. To do so, use the Storage option in the Create virtual machine dialog. For detailed instructions, see creating virtual machines by using the web console.

Prerequisites

Procedure

  1. Log in to the RHEL 10 web console.
  2. Optional: If you do not want to use the default images storage pool to create a new virtual disk, create a new storage pool.

    1. Click Storage Pools at the top of the Virtual Machines interface. Create storage pool.
    2. In the Create Storage Pool dialog, enter a name for the storage pool.
    3. In the Type drop-down menu, select Filesystem directory.
    4. Enter the following information:

      • Target path - The location of the storage pool.
      • Startup - Whether or not the storage pool starts when the host boots.
    5. Click Create.

      The storage pool is created, the Create Storage Pool dialog closes, and the new storage pool appears in the list of storage pools.

  3. Create a new storage volume based on an existing storage pool.

    1. In the Storage Pools window, click the storage pool from which you want to create a storage volume. Storage Volumes Create volume.
    2. Enter the following information in the Create Storage Volume dialog:

      • Name - The name of the storage volume.
      • Size - The size of the storage volume in MiB or GiB.
      • Format - The format of the storage volume. The supported types are qcow2 and raw.
    3. Click Create.
  4. Optional: Check the consistency of the disk, to avoid issues with data corruption or disk fragmentation. For instructions, see Checking the consistency of a virtual disk.
  5. Add the created storage volume as a disk to a VM.

    1. In the Virtual Machines interface, click the VM for which you want to create and attach the new disk.

      A new page opens with an Overview section with basic information about the selected VM and a Console section to access the VM’s graphical interface.

    2. Scroll to Disks.
    3. In the Disks section, click Add disk.
    4. In the Add disks dialog, select Use existing.
    5. Select the storage pool and storage volume that you want to use for the disk.
    6. Select whether or not the disk will be persistent

      注意

      Transient disks can only be added to VMs that are running.

    7. Optional: Click Show additional options and adjust the cache type, bus type, and disk identifier of the storage volume.
    8. Click Add.

Verification

  • In the guest operating system of the VM, confirm that the disk image has become available as an unformatted and un-allocated disk.

To provide local storage for a virtual machine (VM), you can use a disk-based disk image. This type of disk image is based on a disk partition on your host and uses the .qcow2 or .raw format.

To attach disk-based storage to a VM by using the command line, use one of the following methods:

  • When creating a new VM, create and attach a new disk as a part of the virt-install command, by using the --disk option. For detailed instructions, see Creating virtual machines.
  • For an existing VM, create a disk-based storage volume and attach it to the VM. For instructions, see the following procedure.

Prerequisites

  • Ensure your hypervisor supports disk-based storage pools:

    # virsh pool-capabilities | grep "'disk' supported='yes'"

    If the command displays any output, disk-based pools are supported.

  • Prepare a device on which you will base the storage pool. For this purpose, prefer partitions (for example, /dev/sdb1) or LVM volumes. If you provide a VM with write access to an entire disk or block device (for example, /dev/sdb), the VM will likely partition it or create its own LVM groups on it. This can result in system errors on the host.

    However, if you require using an entire block device for the storage pool, Red Hat recommends protecting any important partitions on the device from GRUB’s os-prober function. To do so, edit the /etc/default/grub file and apply one of the following configurations:

    • Disable os-prober.

      GRUB_DISABLE_OS_PROBER=true
    • Prevent os-prober from discovering the partition that you want to use. For example:

      GRUB_OS_PROBER_SKIP_LIST="5ef6313a-257c-4d43@/dev/sdb1"
  • Back up any data on the selected storage device before creating a storage pool. Depending on the version of libvirt being used, dedicating a disk to a storage pool may reformat and erase all data currently stored on the disk device.

Procedure

  1. Create and set up a new disk-based storage pool, if you do not already have one.

    1. Define and create a disk-type storage pool. The following example creates a storage pool named guest_images_disk that uses the /dev/sdb device and is mounted on the /dev directory.

      # virsh pool-define-as guest_images_disk disk --source-format=gpt --source-dev=/dev/sdb --target /dev
      Pool guest_images_disk defined
    2. Create a storage pool target path for a pre-formatted file-system storage pool, initialize the storage source device, and define the format of the data.

      # virsh pool-build guest_images_disk
        Pool guest_images_disk built
    3. Optional: Verify that the pool was created.

      # virsh pool-list --all
      
        Name                 State      Autostart
        -----------------------------------------
        default              active     yes
        guest_images_disk    inactive   no
    4. Start the storage pool.

      # virsh pool-start guest_images_disk
        Pool guest_images_disk started
      注意

      The virsh pool-start command is only necessary for persistent storage pools. Transient storage pools are automatically started when they are created.

    5. Optional: Turn on autostart.

      By default, a storage pool defined with virsh is not set to automatically start each time virtualization services start. Use the virsh pool-autostart command to configure the storage pool to autostart.

      # virsh pool-autostart guest_images_disk
        Pool guest_images_disk marked as autostarted
  2. Create a disk-based storage volume. For example, the following command creates a 20 GB qcow2 volume named vm-disk1 and based on the guest_images_disk storage pool:

    # virsh vol-create-as --pool guest_images_disk --name sdb1 --capacity 20GB --format extended
    
    Vol vm-disk1 created
  3. Attach the storage volume as a virtual disk to a VM.

    1. Locate the storage volume that you created. To do so, examine the storage pool that the volume belongs to:

      # virsh vol-list --pool guest_images_disk --details
      
       Name        Path                      Type   Capacity    Allocation
      ---------------------------------------------------------------------
       sdb1      /dev/sdb1                  block   20.00 GiB   20.00 GiB
    2. Find out which target devices are already used in the VM to which you want to attach the disk:

      # virsh domblklist --details <vm-name> Type Device Target Source ---------------------------------------------------------------- file disk *vda      /home/VirtualMachines/vm-name.qcow2
       file   cdrom    vdb      -
    3. Optional: Check the consistency of the disk, to avoid issues with data corruption or disk fragmentation. For instructions, see Checking the consistency of a virtual disk.
    4. Attach the disk to a VM by using the virsh attach-disk command. Provide a target device that is not in use in the VM.

      For example, the following command attaches the previously created vm-disk1 as the vdc device to the testguest1 VM:

      # virsh attach-disk testguest1 /dev/sdb1 vdc --persistent

Verification

  1. Inspect the XML configuration of the VM to which you attached the disk to see if the configuration is correct.

    # virsh dumpxml testguest1
    
    ...
      <disk type="block" device="disk">
        <driver name="qemu" type="raw"/>
        <source dev="/dev/sdb1" index="2"/>
        <backingStore/>
        <target dev="vdc" bus="virtio"/>
        <alias name="virtio-disk2"/>
        <address type="pci" domain="0x0000" bus="0x07" slot="0x00" function="0x0"/>
      </disk>
    ...
  2. In the guest operating system of the VM, confirm that the disk image has become available as an un-formatted and un-allocated disk.

To provide local storage for a virtual machine, the easiest option typically is to attach a file-based virtual disk with the .qcow2 or .raw format.

To attach disk-based storage to a VM by using the web console, use one of the following methods:

  • When creating a new VM, create and attach a new disk by using the Storage option in the Create virtual machine dialog. For detailed instructions, see Creating virtual machines by using the web console.
  • For an existing VM, create a disk-based storage volume and attach it to the VM. For instructions, see the following procedure.

Prerequisites

Procedure

  1. Log in to the RHEL 10 web console.
  2. Create and set up a new disk-based storage pool, if you do not already have one.

    1. Click Storage Pools at the top of the Virtual Machines interface. Create storage pool.
    2. In the Create Storage Pool dialog, enter a name for the storage pool.
    3. In the Type drop-down menu, select Physical disk device.

      注意

      If you do not see the Physical disk device option in the drop-down menu, then your hypervisor does not support disk-based storage pools.

    4. Enter the following information:

      • Target Path - The path specifying the target device. This will be the path used for the storage pool.
      • Source path - The path specifying the storage device. For example, /dev/sdb.
      • Format - The type of the partition table.
      • Startup - Whether or not the storage pool starts when the host boots.
    5. Click Create.

      The storage pool is created, the Create Storage Pool dialog closes, and the new storage pool appears in the list of storage pools.

  3. Create a new storage volume based on an existing storage pool.

    1. In the Storage Pools window, click the storage pool from which you want to create a storage volume. Storage Volumes Create volume.
    2. Enter the following information in the Create Storage Volume dialog:

      • Name - The name of the storage volume.
      • Size - The size of the storage volume in MiB or GiB.
      • Format - The format of the storage volume.
    3. Click Create.
  4. Optional: Check the consistency of the disk, to avoid issues with data corruption or disk fragmentation. For instructions, see Checking the consistency of a virtual disk.
  5. Add the created storage volume as a disk to a VM.

    1. In the Virtual Machines interface, click the VM for which you want to create and attach the new disk.

      A new page opens with an Overview section with basic information about the selected VM and a Console section to access the VM’s graphical interface.

    2. Scroll to Disks.
    3. In the Disks section, click Add disk.
    4. In the Add disks dialog, select Use existing.
    5. Select the storage pool and storage volume that you want to use for the disk.
    6. Select whether or not the disk will be persistent

      注意

      Transient disks can only be added to VMs that are running.

    7. Optional: Click Show additional options and adjust the cache type, bus type, and disk identifier of the storage volume.
    8. Click Add.

Verification

  • In the guest operating system of the VM, confirm that the disk image has become available as an un-formatted and un-allocated disk.

To provide local storage for a virtual machine (VM), you can use an LVM-based storage volume. This type of disk image is based on an LVM volume group, and uses the .qcow2 or .raw format.

To attach LVM-based storage to a VM by using the command line, use one of the following methods:

  • When creating a new VM, create and attach a new disk by using the Storage option in the Create virtual machine dialog. For detailed instructions, see Creating virtual machines by using the web console.
  • For an existing VM, create an LVM-based storage volume and attach it to the VM. For instructions, see the following procedure.
重要

Note that LVM-based storage volumes have the following limitations:

  • LVM-based storage pools do not provide the full flexibility of LVM.
  • LVM-based storage pools are volume groups. You can create volume groups by using the virsh utility, but this way you can only have one device in the created volume group. To create a volume group with multiple devices, use the LVM utility instead, see How to create a volume group in Linux with LVM.
  • LVM-based storage pools require a full disk partition. If you activate a new partition or device by using virsh commands, the partition will be formatted and all data will be erased. If you are using a host’s existing volume group, as in the following procedure, nothing will be erased.

Prerequisites

  • Ensure your hypervisor supports LVM-based storage pools:

    # virsh pool-capabilities | grep "'logical' supported='yes'"

    If the command displays any output, LVM-based pools are supported.

  • Make sure an LVM volume group exists on your host. For instructions on creating one, see Creating an LVM volume group.
  • Back up any data on the selected storage device before creating a storage pool. Dedicating a disk partition to a storage pool will reformat and erase all data currently stored on the disk device.

Procedure

  1. Create and set up a new LVM-based storage pool, if you do not already have one.

    1. Define an LVM-type storage pool. For example, the following command defines a storage pool named guest_images_lvm that uses the lvm_vg volume group and is mounted on the /dev/lvm_vg directory:

      # virsh pool-define-as guest_images_lvm logical --source-dev /dev/sdb --target /dev/lvm_vg
      Pool guest_images_lvm defined
    2. Create a storage pool based on the configuration you previously defined.

      # virsh pool-build guest_images_lvm
        Pool guest_images_lvm built
    3. Optional: Verify that the pool was created.

      # virsh pool-list --all
      
        Name                   State      Autostart
        -------------------------------------------
        default                active     yes
        guest_images_lvm       inactive   no
    4. Start the storage pool.

      # virsh pool-start guest_images_lvm
        Pool guest_images_lvm started
      注意

      The virsh pool-start command is only necessary for persistent storage pools. Transient storage pools are automatically started when they are created.

    5. Optional: Turn on autostart.

      By default, a storage pool defined with virsh is not set to automatically start each time virtualization services start. Use the virsh pool-autostart command to configure the storage pool to autostart.

      # virsh pool-autostart guest_images_lvm
        Pool guest_images_lvm marked as autostarted
  2. Create an LVM-based storage volume. For example, the following command creates a 20 GB qcow2 volume named vm-disk1 and based on the guest_images_lvm storage pool:

    # virsh vol-create-as --pool guest_images_lvm --name vm-disk1 --capacity 20GB --format qcow2
    
    Vol vm-disk1 created
  3. Attach the storage volume as a virtual disk to a VM.

    1. Locate the storage volume that you created. To do so, examine the storage pool that the volume belongs to:

      # virsh vol-list --pool guest_images_lvm --details
      
       Name        Path                            Type   Capacity    Allocation
      -----------------------------------------------------------------------------
       vm-disk1   /dev/guest_images_lvm/vm-disk1   block   20.00 GiB   196.00 KiB
    2. Find out which target devices are already used in the VM to which you want to attach the disk:

      # virsh domblklist --details <vm-name> Type Device Target Source ---------------------------------------------------------------- file disk *vda      /home/VirtualMachines/vm-name.qcow2
       file   cdrom    vdb      -
    3. Optional: Check the consistency of the disk, to avoid issues with data corruption or disk fragmentation. For instructions, see Checking the consistency of a virtual disk.
    4. Attach the disk to a VM by using the virsh attach-disk command. Provide a target device that is not in use in the VM.

      For example, the following command attaches the previously created vm-disk1 as the vdc device to the testguest1 VM:

      # virsh attach-disk testguest1 /dev/guest_images_lvm/vm-disk1 vdc --persistent

Verification

  1. Inspect the XML configuration of the VM to which you attached the disk to see if the configuration is correct.

    # virsh dumpxml testguest1
    
    ...
        <disk type="block" device="disk">
          <driver name="qemu" type="raw"/>
          <source dev="/dev/guest_images_lvm/vm-disk1" index="3"/>
          <backingStore/>
          <target dev="vdc" bus="virtio"/>
          <alias name="virtio-disk2"/>
          <address type="pci" domain="0x0000" bus="0x07" slot="0x00" function="0x0"/>
        </disk>
    
    ...
  2. In the guest operating system of the VM, confirm that the disk image has become available as an un-formatted and un-allocated disk.

To provide local storage for a virtual machine (VM), you can use an LVM-based storage volume. This type of disk image is based on an LVM volume group, and uses the .qcow2 or .raw format.

To attach disk-based storage to a VM by using the web console, use one of the following methods:

  • When creating a new VM, create and attach a new disk by using the Storage option in the Create virtual machine dialog. For detailed instructions, see Creating virtual machines by using the web console.
  • For an existing VM, create an LVM-based storage volume and attach it to the VM. For instructions, see the following procedure.
重要

Note that LVM-based storage volumes have the following limitations:

  • LVM-based storage pools do not provide the full flexibility of LVM.
  • LVM-based storage pools are volume groups. You can create volume groups by using the virsh utility, but this way you can only have one device in the created volume group. To create a volume group with multiple devices, use the LVM utility instead, see How to create a volume group in Linux with LVM.
  • LVM-based storage pools require a full disk partition. If you activate a new partition or device by using virsh commands, the partition will be formatted and all data will be erased. If you are using a host’s existing volume group, as in the following procedure, nothing will be erased.

Prerequisites

Procedure

  1. Log in to the RHEL 10 web console.
  2. Create and set up a new directory-based storage pool, if you do not already have one.

    1. Click Storage Pools at the top of the Virtual Machines interface. Create storage pool.
    2. In the Create Storage Pool dialog, enter a name for the storage pool.
    3. In the Type drop-down menu, select LVM volume group.

      注意

      If you do not see the LVM volume group option in the drop-down menu, then your hypervisor does not support disk-based storage pools.

    4. Enter the following information:

      • Source volume group - The name of the LVM volume group that you wish to use.
      • Startup - Whether or not the storage pool starts when the host boots.
    5. Click Create.

      The storage pool is created, the Create Storage Pool dialog closes, and the new storage pool appears in the list of storage pools.

  3. Create a new storage volume based on an existing storage pool.

    1. In the Storage Pools window, click the storage pool from which you want to create a storage volume. Storage Volumes Create volume.
    2. Enter the following information in the Create Storage Volume dialog:

      • Name - The name of the storage volume.
      • Size - The size of the storage volume in MiB or GiB.
      • Format - The format of the storage volume. The supported types are qcow2 and raw.
    3. Click Create.
  4. Optional: Check the consistency of the disk, to avoid issues with data corruption or disk fragmentation. For instructions, see Checking the consistency of a virtual disk.
  5. Add the created storage volume as a disk to a VM.

    1. In the Virtual Machines interface, click the VM for which you want to create and attach the new disk.

      A new page opens with an Overview section with basic information about the selected VM and a Console section to access the VM’s graphical interface.

    2. Scroll to Disks.
    3. In the Disks section, click Add disk.
    4. In the Add disks dialog, select Use existing.
    5. Select the storage pool and storage volume that you want to use for the disk.
    6. Select whether or not the disk will be persistent

      注意

      Transient disks can only be added to VMs that are running.

    7. Optional: Click Show additional options and adjust the cache type, bus type, and disk identifier of the storage volume.
    8. Click Add.

Verification

  • In the guest operating system of the VM, confirm that the disk image has become available as an un-formatted and un-allocated disk.

To provide networke storage for a virtual machine (VM), you can use a storage volume based on a Network File Sytem (NFS) server.

To attach NFS-based storage to a VM by using the command line, use one of the following methods:

  • When creating a new VM, create and attach a new disk by using the Storage option in the Create virtual machine dialog. For detailed instructions, see Creating virtual machines by using the web console.
  • For an existing VM, create an NFS-based storage volume and attach it to the VM. For instructions, see the following procedure.

Prerequisites

  • Ensure your hypervisor supports NFS-based storage pools:

    # virsh pool-capabilities | grep "<value>nfs</value>"

    If the command displays any output, NFS-based pools are supported.

  • You must have an available NFS that you can use. For details, see Mounting NFS shares

Procedure

  1. Create and set up a new NFS-based storage pool, if you do not already have one.

    1. Define and create an NFS-type storage pool. For example, to create a storage pool named guest_images_netfs that uses an NFS server with IP 111.222.111.222 mounted on the server directory /home/net_mount by using the target directory /var/lib/libvirt/images/nfspool:

      # virsh pool-define-as --name guest_images_netfs \
         --type netfs --source-host='111.222.111.222' \
         --source-path='/home/net_mount' --source-format='nfs' \
         --target='/var/lib/libvirt/images/nfspool'
      
      Pool guest_images_netfs defined
    2. Create a storage pool based on the configuration you previously defined.

      # virsh pool-build guest_images_netfs
        Pool guest_images_netfs built
    3. Optional: Verify that the pool was created.

      # virsh pool-list --all
      
        Name                   State      Autostart
        -------------------------------------------
        default                active     yes
        guest_images_netfs     inactive   no
    4. Start the storage pool.

      # virsh pool-start guest_images_netfs
        Pool guest_images_netfs started
    5. Optional: Turn on autostart.

      By default, a storage pool defined with virsh is not set to automatically start each time virtualization services start. Use the virsh pool-autostart command to configure the storage pool to autostart.

      # virsh pool-autostart guest_images_netfs
        Pool guest_images_netfs marked as autostarted
  2. Create an NFS-based storage volume. For example, the following command creates a 20 GB qcow2 volume named vm-disk1 and based on the guest_images_netfs storage pool:

    # virsh vol-create-as --pool guest_images_netfs --name vm-disk1 --capacity 20GB --format qcow2
    
    Vol vm-disk1 created
  3. Attach the storage volume as a virtual disk to a VM.

    1. Locate the storage volume that you created. To do so, examine the storage pool that the volume belongs to:

      # virsh vol-list --pool guest_images_netfs --details
      
       Name        Path                                       Type   Capacity    Allocation
      -------------------------------------------------------------------------------------
       vm-disk1   /var/lib/libvirt/images/nfspool/vm-disk1    file  20.00 GiB   196.00 KiB
    2. Find out which target devices are already used in the VM to which you want to attach the disk:

      # virsh domblklist --details <vm-name> Type Device Target Source ---------------------------------------------------------------- file disk *vda      /home/VirtualMachines/vm-name.qcow2
       file   cdrom    vdb      -
    3. Optional: Check the consistency of the disk, to avoid issues with data corruption or disk fragmentation. For instructions, see Checking the consistency of a virtual disk.
    4. Attach the disk to a VM by using the virsh attach-disk command. Provide a target device that is not in use in the VM.

      For example, the following command attaches the previously created vm-disk1 as the vdc device to the testguest1 VM:

      # virsh attach-disk testguest1 /var/lib/libvirt/images/nfspool/vm-disk1 vdc --persistent

Verification

  1. Inspect the XML configuration of the VM to which you attached the disk to see if the configuration is correct.

    # virsh dumpxml testguest1
    
    ...
        <disk type='file' device='disk'>
          <driver name='qemu' type='qcow2' discard='unmap'/>
          <source file='/var/lib/libvirt/images/nfspool/vm-disk1' index='1'/>
          <backingStore/>
          <target dev='vdc' bus='virtio'/>
          <alias name='virtio-disk2'/>
          <address type='drive' controller='0' bus='0' target='0' unit='0'/>
        </disk>
    ...
  2. In the guest operating system of the VM, confirm that the disk image has become available as an un-formatted and un-allocated disk.

To provide networke storage for a virtual machine (VM), you can use a storage volume based on a Network File Sytem (NFS) server.

To attach NFS-based storage to a VM by using the web console, use one of the following methods:

  • When creating a new VM, create and attach a new disk by using the Storage option in the Create virtual machine dialog. For detailed instructions, see Creating virtual machines by using the web console.
  • For an existing VM, create an NFS-based storage volume and attach it to the VM. For instructions, see the following procedure.

Prerequisites

Procedure

  1. Log in to the RHEL 10 web console.
  2. Create and set up a new NFS-based storage pool, if you do not already have one.

    1. Click Storage Pools at the top of the Virtual Machines interface. Create storage pool.
    2. In the Create Storage Pool dialog, enter a name for the storage pool.
    3. In the Type drop-down menu, select Network file system.

      注意

      If you do not see the Network file system option in the drop-down menu, then your hypervisor does not support NFS-based storage pools.

    4. Enter the following information:

      • Target path - The path specifying the target. This will be the path used for the storage pool.
      • Host - The hostname of the network server where the mount point is located. This can be a hostname or an IP address.
      • Source path - The directory used on the network server.
      • Startup - Whether or not the storage pool starts when the host boots.
    5. Click Create.

      The storage pool is created, the Create Storage Pool dialog closes, and the new storage pool appears in the list of storage pools.

  3. Create a new storage volume based on an existing storage pool.

    1. In the Storage Pools window, click the storage pool from which you want to create a storage volume. Storage Volumes Create volume.
    2. Enter the following information in the Create Storage Volume dialog:

      • Name - The name of the storage volume.
      • Size - The size of the storage volume in MiB or GiB.
      • Format - The format of the storage volume. The supported types are qcow2 and raw.
    3. Click Create.
  4. Optional: Check the consistency of the disk, to avoid issues with data corruption or disk fragmentation. For instructions, see Checking the consistency of a virtual disk.
  5. Add the created storage volume as a disk to a VM.

    1. In the Virtual Machines interface, click the VM for which you want to create and attach the new disk.

      A new page opens with an Overview section with basic information about the selected VM and a Console section to access the VM’s graphical interface.

    2. Scroll to Disks.
    3. In the Disks section, click Add disk.
    4. In the Add disks dialog, select Use existing.
    5. Select the storage pool and storage volume that you want to use for the disk.
    6. Select whether or not the disk will be persistent

      注意

      Transient disks can only be added to VMs that are running.

    7. Optional: Click Show additional options and adjust the cache type, bus type, and disk identifier of the storage volume.
    8. Click Add.

Verification

  • In the guest operating system of the VM, confirm that the disk image has become available as an un-formatted and un-allocated disk.
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部