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
systemsession oflibvirt, the disk image is saved in the/var/lib/libvirt/images/directory and the storage pool is namedimages.Use the
qemu-imgcommand to create a virtual disk as a file on the host file system. This is a faster method, but does not provide integration withlibvirt.As a result, virtual disks created by using
qemu-imgare 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
Optional: If you want to create a virtual disk as a storage volume, but you do not want to use the default
imagesstorage pool or another existing storage pool on the host, create and set up a new directory-based storage pool.Configure a directory-type storage pool. For example, to create a storage pool named
guest_images_dirthat uses the/guest_imagesdirectory:# virsh pool-define-as guest_images_dir dir --target "/guest_images" Pool guest_images_dir definedCreate a target path for the storage pool based on the configuration you previously defined.
# virsh pool-build guest_images_dir Pool guest_images_dir builtStart the storage pool.
# virsh pool-start guest_images_dir Pool guest_images_dir startedOptional: Set the storage pool to start on host boot.
# virsh pool-autostart guest_images_dir Pool guest_images_dir marked as autostartedOptional: Verify that the storage pool is in the
runningstate. 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
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 theqemu-imgutility.For example, the following command creates a
qcow2disk 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=16To 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
qcow2volume namedvm-disk1and based on theguest_images_dirstorage pool:# virsh vol-create-as --pool guest_images_dir --name vm-disk1 --capacity 20GB --format qcow2 Vol vm-disk1 created
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
-
For a VM disk created with
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 -- 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.
Attach the disk to a VM by using the
virsh attach-diskcommand. Provide a target device that is not in use in the VM.For example, the following command attaches the previously created
test-disk1as thevdcdevice to thetestguest1VM:# virsh attach-disk testguest1 /guest-images/vm-disk1 vdc --persistent
Verification
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> ...- 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
You have installed the RHEL 10 web console.
For instructions, see Installing and enabling the web console.
- The web console VM plugin is installed on your system.
Procedure
- Log in to the RHEL 10 web console.
Optional: If you do not want to use the default
imagesstorage pool to create a new virtual disk, create a new storage pool.-
Click
Storage Poolsat the top of the Virtual Machines interface.Create storage pool. - In the Create Storage Pool dialog, enter a name for the storage pool.
- In the Type drop-down menu, select Filesystem directory.
Enter the following information:
- Target path - The location of the storage pool.
- Startup - Whether or not the storage pool starts when the host boots.
Click .
The storage pool is created, the Create Storage Pool dialog closes, and the new storage pool appears in the list of storage pools.
-
Click
Create a new storage volume based on an existing storage pool.
-
In the Storage Pools window, click the storage pool from which you want to create a storage volume.
Storage VolumesCreate volume. 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
qcow2andraw.
- Click .
-
In the Storage Pools window, click the storage pool from which you want to create a storage volume.
- 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.
Add the created storage volume as a disk to a VM.
In the 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.
- Scroll to .
- In the Disks section, click .
- In the Add disks dialog, select .
- Select the storage pool and storage volume that you want to use for the disk.
Select whether or not the disk will be persistent
注意Transient disks can only be added to VMs that are running.
- Optional: Click and adjust the cache type, bus type, and disk identifier of the storage volume.
- Click .
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-installcommand, by using the--diskoption. 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-proberfunction. To do so, edit the/etc/default/grubfile and apply one of the following configurations:Disable
os-prober.GRUB_DISABLE_OS_PROBER=truePrevent
os-proberfrom 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
libvirtbeing used, dedicating a disk to a storage pool may reformat and erase all data currently stored on the disk device.
Procedure
Create and set up a new disk-based storage pool, if you do not already have one.
Define and create a disk-type storage pool. The following example creates a storage pool named
guest_images_diskthat 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 definedCreate 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 builtOptional: Verify that the pool was created.
# virsh pool-list --all Name State Autostart ----------------------------------------- default active yes guest_images_disk inactive noStart the storage pool.
# virsh pool-start guest_images_disk Pool guest_images_disk started注意The
virsh pool-startcommand is only necessary for persistent storage pools. Transient storage pools are automatically started when they are created.Optional: Turn on autostart.
By default, a storage pool defined with
virshis not set to automatically start each time virtualization services start. Use thevirsh pool-autostartcommand to configure the storage pool to autostart.# virsh pool-autostart guest_images_disk Pool guest_images_disk marked as autostarted
Create a disk-based storage volume. For example, the following command creates a 20 GB
qcow2volume namedvm-disk1and based on theguest_images_diskstorage pool:# virsh vol-create-as --pool guest_images_disk --name sdb1 --capacity 20GB --format extended Vol vm-disk1 createdAttach the storage volume as a virtual disk to a VM.
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 GiBFind 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 -- 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.
Attach the disk to a VM by using the
virsh attach-diskcommand. Provide a target device that is not in use in the VM.For example, the following command attaches the previously created
vm-disk1as thevdcdevice to thetestguest1VM:# virsh attach-disk testguest1 /dev/sdb1 vdc --persistent
Verification
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> ...- 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
Storageoption in theCreate virtual machinedialog. 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
You have installed the RHEL 10 web console.
For instructions, see Installing and enabling the web console.
- The web console VM plugin is installed on your system.
Procedure
- Log in to the RHEL 10 web console.
Create and set up a new disk-based storage pool, if you do not already have one.
-
Click
Storage Poolsat the top of the Virtual Machines interface.Create storage pool. - In the Create Storage Pool dialog, enter a name for the storage pool.
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.
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.
Click .
The storage pool is created, the Create Storage Pool dialog closes, and the new storage pool appears in the list of storage pools.
-
Click
Create a new storage volume based on an existing storage pool.
-
In the Storage Pools window, click the storage pool from which you want to create a storage volume.
Storage VolumesCreate volume. 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.
- Click .
-
In the Storage Pools window, click the storage pool from which you want to create a storage volume.
- 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.
Add the created storage volume as a disk to a VM.
In the 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.
- Scroll to .
- In the Disks section, click .
- In the Add disks dialog, select .
- Select the storage pool and storage volume that you want to use for the disk.
Select whether or not the disk will be persistent
注意Transient disks can only be added to VMs that are running.
- Optional: Click and adjust the cache type, bus type, and disk identifier of the storage volume.
- Click .
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
Storageoption in theCreate virtual machinedialog. 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
virshutility, 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
virshcommands, 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
Create and set up a new LVM-based storage pool, if you do not already have one.
Define an LVM-type storage pool. For example, the following command defines a storage pool named
guest_images_lvmthat uses thelvm_vgvolume group and is mounted on the/dev/lvm_vgdirectory:# virsh pool-define-as guest_images_lvm logical --source-dev /dev/sdb --target /dev/lvm_vg Pool guest_images_lvm definedCreate a storage pool based on the configuration you previously defined.
# virsh pool-build guest_images_lvm Pool guest_images_lvm builtOptional: Verify that the pool was created.
# virsh pool-list --all Name State Autostart ------------------------------------------- default active yes guest_images_lvm inactive noStart the storage pool.
# virsh pool-start guest_images_lvm Pool guest_images_lvm started注意The
virsh pool-startcommand is only necessary for persistent storage pools. Transient storage pools are automatically started when they are created.Optional: Turn on autostart.
By default, a storage pool defined with
virshis not set to automatically start each time virtualization services start. Use thevirsh pool-autostartcommand to configure the storage pool to autostart.# virsh pool-autostart guest_images_lvm Pool guest_images_lvm marked as autostarted
Create an LVM-based storage volume. For example, the following command creates a 20 GB
qcow2volume namedvm-disk1and based on theguest_images_lvmstorage pool:# virsh vol-create-as --pool guest_images_lvm --name vm-disk1 --capacity 20GB --format qcow2 Vol vm-disk1 createdAttach the storage volume as a virtual disk to a VM.
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 KiBFind 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 -- 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.
Attach the disk to a VM by using the
virsh attach-diskcommand. Provide a target device that is not in use in the VM.For example, the following command attaches the previously created
vm-disk1as thevdcdevice to thetestguest1VM:# virsh attach-disk testguest1 /dev/guest_images_lvm/vm-disk1 vdc --persistent
Verification
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> ...- 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
Storageoption in theCreate virtual machinedialog. 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
virshutility, 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
virshcommands, 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
You have installed the RHEL 10 web console.
For instructions, see Installing and enabling the web console.
- The web console VM plugin is installed on your system.
- An LVM volume group exists on your host. For instructions on creating one, see Creating an LVM volume group.
Procedure
- Log in to the RHEL 10 web console.
Create and set up a new directory-based storage pool, if you do not already have one.
-
Click
Storage Poolsat the top of the Virtual Machines interface.Create storage pool. - In the Create Storage Pool dialog, enter a name for the storage pool.
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.
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.
Click .
The storage pool is created, the Create Storage Pool dialog closes, and the new storage pool appears in the list of storage pools.
-
Click
Create a new storage volume based on an existing storage pool.
-
In the Storage Pools window, click the storage pool from which you want to create a storage volume.
Storage VolumesCreate volume. 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
qcow2andraw.
- Click .
-
In the Storage Pools window, click the storage pool from which you want to create a storage volume.
- 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.
Add the created storage volume as a disk to a VM.
In the 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.
- Scroll to .
- In the Disks section, click .
- In the Add disks dialog, select .
- Select the storage pool and storage volume that you want to use for the disk.
Select whether or not the disk will be persistent
注意Transient disks can only be added to VMs that are running.
- Optional: Click and adjust the cache type, bus type, and disk identifier of the storage volume.
- Click .
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
Storageoption in theCreate virtual machinedialog. 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
Create and set up a new NFS-based storage pool, if you do not already have one.
Define and create an NFS-type storage pool. For example, to create a storage pool named
guest_images_netfsthat uses an NFS server with IP111.222.111.222mounted on the server directory/home/net_mountby 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 definedCreate a storage pool based on the configuration you previously defined.
# virsh pool-build guest_images_netfs Pool guest_images_netfs builtOptional: Verify that the pool was created.
# virsh pool-list --all Name State Autostart ------------------------------------------- default active yes guest_images_netfs inactive noStart the storage pool.
# virsh pool-start guest_images_netfs Pool guest_images_netfs startedOptional: Turn on autostart.
By default, a storage pool defined with
virshis not set to automatically start each time virtualization services start. Use thevirsh pool-autostartcommand to configure the storage pool to autostart.# virsh pool-autostart guest_images_netfs Pool guest_images_netfs marked as autostarted
Create an NFS-based storage volume. For example, the following command creates a 20 GB
qcow2volume namedvm-disk1and based on theguest_images_netfsstorage pool:# virsh vol-create-as --pool guest_images_netfs --name vm-disk1 --capacity 20GB --format qcow2 Vol vm-disk1 createdAttach the storage volume as a virtual disk to a VM.
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 KiBFind 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 -- 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.
Attach the disk to a VM by using the
virsh attach-diskcommand. Provide a target device that is not in use in the VM.For example, the following command attaches the previously created
vm-disk1as thevdcdevice to thetestguest1VM:# virsh attach-disk testguest1 /var/lib/libvirt/images/nfspool/vm-disk1 vdc --persistent
Verification
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> ...- 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
Storageoption in theCreate virtual machinedialog. 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
You have installed the RHEL 10 web console.
For instructions, see Installing and enabling the web console.
- The web console VM plugin is installed on your system.
Procedure
- Log in to the RHEL 10 web console.
Create and set up a new NFS-based storage pool, if you do not already have one.
-
Click
Storage Poolsat the top of the Virtual Machines interface.Create storage pool. - In the Create Storage Pool dialog, enter a name for the storage pool.
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.
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.
Click .
The storage pool is created, the Create Storage Pool dialog closes, and the new storage pool appears in the list of storage pools.
-
Click
Create a new storage volume based on an existing storage pool.
-
In the Storage Pools window, click the storage pool from which you want to create a storage volume.
Storage VolumesCreate volume. 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
qcow2andraw.
- Click .
-
In the Storage Pools window, click the storage pool from which you want to create a storage volume.
- 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.
Add the created storage volume as a disk to a VM.
In the 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.
- Scroll to .
- In the Disks section, click .
- In the Add disks dialog, select .
- Select the storage pool and storage volume that you want to use for the disk.
Select whether or not the disk will be persistent
注意Transient disks can only be added to VMs that are running.
- Optional: Click and adjust the cache type, bus type, and disk identifier of the storage volume.
- Click .
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.