13.6. Managing virtual optical drives
When using a virtual machine (VM), you can access information stored in an ISO image on the host. To do so, attach the ISO image to the VM as a virtual optical drive, such as a CD drive or a DVD drive.
The following sections provide information about using the command line to:
- Attach a drive and an ISO image to a VM
- Replace an ISO image in a virtual optical drive
- Remove an ISO image from a virtual optical drive
- Remove a drive from the VM
13.6.1. Attaching optical drives to virtual machines
To attach an ISO image as a virtual optical drive, edit the XML configuration file of the virtual machine (VM) and add the new drive.
Conditions préalables
- You must store the ISO image on the local host.
- You must know the path to the ISO image.
Procédure
Use the
virt-xml
utility with the--add-device
argument.For example, the following command attaches the
Doc10
ISO image, stored in the/MC/tank/
directory, to theDN1
VM.# virt-xml DN1 --add-device --disk /MC/tank/Doc10.iso,device=cdrom Domain 'DN1' defined successfully.
Vérification
- Run the VM and test if the device is present and works as expected.
Ressources supplémentaires
-
The
man virt-xml
command - Attaching devices to virtual machines
13.6.2. Replacing ISO images in virtual optical drives
To replace an ISO image attached as a virtual optical drive to a virtual machine (VM), edit the XML configuration file of the VM and specify the replacement.
Conditions préalables
- You must store the ISO image on the local host.
- You must know the path to the ISO image.
Procédure
Locate the target device where the CD-ROM is attached to the VM. You can find this information in the VM’s XML configuration file.
For example, the following command displays the
DN1
VM’s XML configuration file, where the target device for CD-ROM issda
.# virsh dumpxml DN1 ... <disk> ... <source file='/MC/tank/Doc10.iso'/> <target dev='sda' bus='sata'/> ... </disk> ...
Use the
virt-xml
utility with the--edit
argument.For example, the following command replaces the
Doc10
ISO image, attached to theDN1
VM at targetsda
, with theDrDN
ISO image stored in the/Dvrs/current/
directory.# virt-xml DN1 --edit target=sda --disk /Dvrs/current/DrDN.iso Domain 'DN1' defined successfully.
Vérification
- Run the VM and test if the device is replaced and works as expected.
Ressources supplémentaires
-
The
man virt-xml
command
13.6.3. Removing ISO images from virtual optical drives
To remove an ISO image from a virtual optical drive attached to a virtual machine (VM), edit the XML configuration file of the VM.
Procédure
Locate the target device where the CD-ROM is attached to the VM. You can find this information in the VM’s XML configuration file.
For example, the following command displays the
DN1
VM’s XML configuration file, where the target device for CD-ROM issda
.# virsh dumpxml DN1 ... <disk> ... <source file='/Dvrs/current/DrDN'/> <target dev='sda' bus='sata'/> ... </disk> ...
Use the
virt-xml
utility with the--edit
argument.For example, the following command removes the
DrDN
ISO image from the CD drive attached to theDN1
VM.# virt-xml DN1 --edit target=sda --disk path= Domain 'DN1' defined successfully.
Vérification
- Run the VM and check that image is no longer available.
Ressources supplémentaires
-
The
man virt-xml
command
13.6.4. Removing optical drives from virtual machines
To remove an optical drive attached to a virtual machine (VM), edit the XML configuration file of the VM.
Procédure
Locate the target device where the CD-ROM is attached to the VM. You can find this information in the VM’s XML configuration file.
For example, the following command displays the
DN1
VM’s XML configuration file, where the target device for CD-ROM issda
.# virsh dumpxml DN1 ... <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <target dev='sda' bus='sata'/> ... </disk> ...
Use the
virt-xml
utility with the--remove-device
argument.For example, the following command removes the optical drive attached as target
sda
from theDN1
VM.# virt-xml DN1 --remove-device --disk target=sda Domain 'DN1' defined successfully.
Vérification
- Confirm that the device is no longer listed in the XML configuration file of the VM.
Ressources supplémentaires
-
The
man virt-xml
command