13.3.2. Adding Hard Drives and Other Block Devices to a Guest
System administrators have the option to use additional hard drives to provide increased storage space for a guest, or to separate system data from user data.
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
disk
element in a new file. In this example, this file will be known asNewStorage.xml
. The following example is a configuration file section which contains an additional device-based storage container for the host physical machine partition/dev/sr0:
<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-disk
command, as shown:# virsh attach-disk Guest1 /dev/sr0 vdc
Note that the following options are available:- The
virsh attach-disk
command also accepts the--config
,--type
, and--mode
options, as shown:#
virsh attach-disk Guest1 /dev/sr0 vdc --config --type cdrom --mode readonly
- Additionally,
--type
also accepts--type disk
in cases where the device is a hard drive.
- The guest virtual machine now has a new hard disk device called
/dev/vdc
on Linux (or something similar, depending on what the guest virtual machine OS chooses) orD: 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” for an example.Warning
When 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/.Important
Guest 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.