About

The procedure described in the resize guide does not apply to storage pools. Any attempt to resize a logical volume used by virsh will result in the error:

error: this function is not supported by the connection driver: storage pool does not support changing of volume capacity

Solutions include dumping the entire domain to an image file and then resizing that image by creating an additional new image. Unfortunately, that is not always an option, given domains with a very large allocated storage space.

Preparations

The first thing to do is to shut down the domain using virsh:

virsh -c qemu:/// shutdown mydomain.db

where:

  • mydomain.db is the domain for which to resize the storage space.

Resizing the Logical Volume

The command lvs can be used to list the logical volumes:

lvs

which should output all logical volumes accounted for, amongst which the libvirt pool. For instance, given a libvirt storage pool named vms, a logical volume named mydomain.db, the command should output:

mydomain.db    vms    -wi-ao---- 10.00g     

The domain and logical volume carry the same following the image file migration guide.

To extend the mydomain.db logical volume by, say, another 10GiB, issue:

lvresize /dev/vms/mydomain.db -L +10G

where:

  • /dev/vms/mydomain.db is the path to the logical volume device,
  • -L +10G increases the storage size by 10GiB.

Now that the logical volume has been extended with free space, the partition must be resized.

Extending the Partition

One "ease-of-mind" tool to use is GParted that provides a graphical interface to resize partitions. Otherwise, extending the partition can be done manually using fdisk.

First, inspect the partition layout:

virt-filesystems --long -h --all -a /dev/vms/mydomain.db

which should list something along the following:

Name       Type        VFS   Label  MBR  Size  Parent
/dev/sda1  filesystem  ext4  -      -    10G   -
/dev/sda1  partition   -     -      83   10G   /dev/sda
/dev/sda   device      -     -      -    20G   -

The root filesystem is most likely on /dev/sda1 (this can be double-checked when the domain is running). /dev/sda1 has a 10GiB size, which is what the lvs command had shown in the previous section. The entire disk however, is 20GiB, meaning that the disk has had free space added using lvsresize as per the previous section.

Fortunately, there is no swap space in the partition table, nor is there any dedicated /boot partition, which should make resizing /dev/sda1 much easier. Issue:

fdisk /dev/vms/mydomain.db

which should enter partitioning mode. To inspect the partition table, press P and the current layout should be listed. For the case in this guide, the output will be:

Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/vms/mydomain.db: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x4f8733d0

Device                  Boot Start      End  Sectors Size Id Type
/dev/vms/mydomain.db1 *     2048 20969471 20967424  10G 83 Linux

Command (m for help):

The disk size is confirmed to be 20GiB by Disk /dev/vms/mydomain.db: 20 GiB and the first partition /dev/vms/mydomain.db1 has 10GiB. Since there are no other partitions on the disk, it is just a matter of deleting the partition (whilst minding the start sector and end sector) and recreating a new one with the same start sector.

The partition can be deleted by pressing D, which should be confirmed by fdisk with:

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Next, the partition is recreated by pressing N:

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 

Created a new partition 1 of type 'Linux' and of size 20 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: n

The most important prompt is to select n when fdisk asks whether to remove the ext4 filesystem signature. Otherwise, the start sector will still be 2048 and the end sector will extend in the free space added with lvsresize.

Finally, exit fdisk using W. In case fdisk reports that the changes have not been taken into account, partprobe can be issued to sync the new partition table:

partprobe

Swapspace Trick

Free space will be added by lvsresize at the end of the disk and Linux creates swap space at the end too. If that is the case, then the /dev/vms/mydomain.db1 partition could not just have been deleted and recreated due to the swap partition being in the way.

Since swap space is expendable, one trick consists in:

  1. deleting the swap partition,
  2. recreating the root partition using the same procedure but leaving some free space for a new swap partition,
  3. creating a new swap partition

The procedure will work fine from the partitions point of view but newer Linux distributions use UUIDs to identify partitions such that by deleting the swap space and re-creating it, the /etc/fstab file inside the root partition might contain a dangling reference to some swap partition that does not exist. Furthermore, Linux may enter maintenance mode when it cannot find the referenced swap partition.

The problem can be easily remedied by connecting to the virtual machine via VNC and editing /etc/fstab in maintenance mode to reference the new swap partition by using blkid to determine the new UUID.

Note that /boot partitions are traditionally kept at the start of the device such that the /boot partition will not pose a problem.

Extending the Filesystem

The final step is to extend the ext4 filesystem - this can be performed using the guestfish tool. Issue:

guestfish

which should lead to an interactive prompt.

First, the device should be loaded:

add /dev/vms/mydomain.db

and run should be executed:

run

Now, the existing filesystems can be listed:

list-filesytems

which should result in something similar to:

/dev/sda1: ext4

It is a good idea to run e2fsck on the filesystem before resizing it, so issue:

e2fsck-f /dev/sda1

Next, extend the filesystem using the resize2fs command:

resize2fs /dev/sda1

and perform another e2fsck:

e2fsck-f /dev/sda1

That is it for the filesystem, guestfish can be exited by sending EOT (press Ctrl+D) or by typing exit.

Booting the Domain

With logical volume extended, the partition resized and the filesystem resized, the domain can be started back up again:

virsh -c qemu:///system start mydomain.db

unix/virtual_machines/resize_lvm_storage_pool_domain.txt ยท Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.