13.3.2. Adding Hard Drives and Other Block Devices to a Guest
Procedure 13.2. Adding physical block devices to guests
- This procedure describes how to add a hard drive on the host physical machine to a guest. It applies to all physical block devices, including CD-ROM, DVD and floppy devices.Physically attach the hard disk device to the host physical machine. Configure the host physical machine if the drive is not accessible by default.
- Do one of the following:
- Create the additional storage by writing a
diskelement in a new file. In this example, this file will be known as
NewStorage.xml. The following example is a configuration file section which contains an additional device-based storage container for the host physical machine partition
<disk type='block' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source dev='/dev/sr0'/> <target dev='vdc' bus='virtio'/> </disk>
- Follow the instruction in the previous section to attach the device to the guest virtual machine. Alternatively, you can use the
virsh attach-diskcommand, as shown:
# virsh attach-disk Guest1 /dev/sr0 vdcNote that the following options are available:
virsh attach-diskcommand also accepts the
--modeoptions, as shown:
virsh attach-disk Guest1 /dev/sr0 vdc --config --type cdrom --mode readonly
--type diskin cases where the device is a hard drive.
- The guest virtual machine now has a new hard disk device called
/dev/vdcon Linux (or something similar, depending on what the guest virtual machine OS chooses) or
D: drive(for example) on Windows. You can now initialize the disk from the guest virtual machine, following the standard procedures for the guest virtual machine's operating system. Refer to Procedure 13.1, “Adding file-based storage” and Procedure 13.1, “Adding file-based storage” for an example.
WarningWhen adding block devices to a guest, make sure to follow security considerations. This information is discussed in more detail in the Red Hat Enterprise Linux Virtualization Security Guide which can be found at https://access.redhat.com/site/documentation/.
ImportantGuest virtual machines should not be given write access to whole disks or block devices (for example,
/dev/sdb). Guest virtual machines with access to whole block devices may be able to modify volume labels, which can be used to compromise the host physical machine system. Use partitions (for example,
/dev/sdb1) or LVM volumes to prevent this issue.