13 Advanced storage topics #
This chapter introduces advanced topics about manipulating storage from the perspective of the VM Host Server.
13.1 Locking disk files and block devices with virtlockd
#
Locking block devices and disk files prevents concurrent writes to these resources from different VM Guests. It provides protection against starting the same VM Guest twice, or adding the same disk to two different virtual machines. This reduces the risk of a virtual machine's disk image becoming corrupted because of a wrong configuration.
The locking is controlled by a daemon called
virtlockd
. Since it operates
independently from the libvirtd
daemon, locks endure a crash or a
restart of libvirtd
. Locks even persist during an update of the
virtlockd
itself, since it can
re-execute itself. This ensures that VM Guests do
not need to be restarted upon a
virtlockd
update.
virtlockd
is supported for
KVM, QEMU, and Xen.
13.1.1 Enable locking #
Locking virtual disks is not enabled by default on SUSE Linux Enterprise Server. To enable and automatically start it upon rebooting, perform the following steps:
Edit
/etc/libvirt/qemu.conf
and setlock_manager = "lockd"
Start the
virtlockd
daemon with the following command:>
sudo
systemctl start virtlockdRestart the
libvirtd
daemon with:>
sudo
systemctl restart libvirtdMake sure
virtlockd
is automatically started when booting the system:>
sudo
systemctl enable virtlockd
13.1.2 Configure locking #
By default virtlockd
is
configured to automatically lock all disks configured for your
VM Guests. The default setting uses a “direct” lockspace,
where the locks are acquired against the actual file paths associated
with the VM Guest <disk> devices. For example,
flock(2)
is called directly on
/var/lib/libvirt/images/my-server/disk0.raw
when
the VM Guest contains the following <disk> device:
<disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/my-server/disk0.raw'/> <target dev='vda' bus='virtio'/> </disk>
The virtlockd
configuration can
be changed by editing the file
/etc/libvirt/qemu-lockd.conf
. It also contains
detailed comments with further information. Make sure to activate
configuration changes by reloading
virtlockd
:
>
sudo
systemctl reload virtlockd
13.1.2.2 Enable locking on LVM or iSCSI volumes #
When wanting to lock virtual disks placed on LVM or iSCSI volumes shared by several hosts, locking needs to be done by UUID rather than by path (which is used by default). Furthermore, the lockspace directory needs to be placed on a shared file system accessible by all hosts sharing the volume. Set the following options for LVM and/or iSCSI:
lvm_lockspace_dir = "/MY_LOCKSPACE_DIRECTORY" iscsi_lockspace_dir = "/MY_LOCKSPACE_DIRECTORY"
13.2 Online resizing of guest block devices #
Sometimes you need to change—extend or shrink—the size of the
block device used by your guest system. For example, when the disk space
originally allocated is no longer enough, it is time to increase its
size. If the guest disk resides on a logical volume,
you can resize it while the guest system is running. This is a big
advantage over an offline disk resizing (see the
virt-resize
command from the
Section 20.3, “Guestfs tools” package) as the service provided by
the guest is not interrupted by the resizing process. To resize a
VM Guest disk, follow these steps:
Inside the guest system, check the current size of the disk (for example
/dev/vda
).#
fdisk -l /dev/vda Disk /dev/sda: 160.0 GB, 160041885696 bytes, 312581808 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytesOn the host, resize the logical volume holding the
/dev/vda
disk of the guest to the required size, for example, 200 GB.#
lvresize -L 200G /dev/mapper/vg00-home Extending logical volume home to 200 GiB Logical volume home successfully resizedOn the host, resize the block device related to the disk
/dev/mapper/vg00-home
of the guest. You can find the DOMAIN_ID withvirsh list
.#
virsh blockresize --path /dev/vg00/home --size 200G DOMAIN_ID Block device '/dev/vg00/home' is resizedCheck that the new disk size is accepted by the guest.
#
fdisk -l /dev/vda Disk /dev/sda: 200.0 GB, 200052357120 bytes, 390727260 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
13.4 Using RADOS block devices with libvirt
#
RADOS Block Devices (RBD) store data in a Ceph cluster. They allow
snapshotting, replication and data consistency. You can use an RBD from
your libvirt
-managed VM Guests similarly to how you use other block
devices.
For more details, refer to the SUSE Enterprise Storage Administration Guide, chapter Using libvirt with Ceph. The SUSE Enterprise Storage documentation is available from https://documentation.suse.com/ses/.