How to upgrade an XFS file system hosted on KVM

In our example, hosts are named host.example.com_ip_address but you might well be using a different convention.

Shut down the host

SSH the hypervisor

Check all running VMs

virsh list

Check the running VM’s block list and identify the disk name (name of the file of the VM)

virsh domblklist host.example.com_ip_address
Target Source
vda /var/lib/libvirt/images/
hda -

Stop the running VM

virsh shutdown host.example.com_ip_address
Domain host.example.com_ip_address is being shutdown

Wait a while. virsh list should tell you once it’s finally shutdown. It goes from running to in shutdown and then it’s off the list.

Make the host hypervisor disk bigger:

qemu-img resize +50G
Image resized.

Start the host again

virsh start host.example.com_ip_address
Domain host.example.com_ip_address started

Log into the VM (SSH to the VM)

Examine the disk layout. There are too many commands to do this, and here is a subset. Examining the disk is just so that you can orientate yourself around the file system. Is it an LVM partition? Is it plain old EXT4? Maybe start off with lsblk but here are some other ones as well:

fdisk -l / lsblk / pvdisplay / pvs / vgs / vgdisplay

Run all the disk resizing commands

  • parted /dev/vda
    • resizepart
    • 100%
  • pvresize /dev/vda2
    • You should see `1 physical volume(s) resized or updated`
  • xfs_growfs /
  • lvextend -r -l +100%FREE /dev/mapper/cl-root
    • You should see `Size of logical volume cl/root changed from 245.02 GiB (62726 extents) to 295.02 GiB (75526 extents).`

If it’s LVM

  • Generally these disk resizes always start with parted. Here, you are working on the entire disk e.g. /dev/vda`
  • Next, you need to do this: pvresize /dev/vda2. Here, you are working on the specific partition number that you’ve resized using parted.
  • Then you do need to use lvextend. Kind of makes sense since you’re using lvm, but nevertheless.
    • When I tried this, vextend -r -l +100%FREE /dev/mapper/centos_mail-root, I got this:
lvextend -r -l +100%FREE /dev/mapper/centos_mail-root
Size of logical volume centos_mail/root changed from <491.12 GiB (125726 extents) to 541.12 GiB (138527 extents).
Logical volume centos_mail/root successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/centos_mail-root is mounted on /; on-line resizing required
old_desc_blocks = 62, new_desc_blocks = 68
resize2fs: Permission denied to resize filesystem
fsadm: ext4 resize failed.
/usr/sbin/fsadm failed: 1

The problem is that -r switch. I am not allow to use -r on this file system! From the help:

Resize underlying filesystem together with the LV using fsadm(8).

This is due to file system errors. You should be able to see them with dmesg. This is the output, be careful there are 100s of lines but it’s at the end:

[ 2.832651] sr 0:0:0:0: Attached scsi CD-ROM sr0
[ 4.075389] EXT4-fs (dm-0): mounted filesystem with ordered data mode. Opts: (null)
[ 8.479747] EXT4-fs (dm-0): warning: mounting fs with errors, running e2fsck is recommended
[ 8.517457] EXT4-fs (dm-0): re-mounted. Opts: quota,grpquota,usrquota,data=ordered
[ 10.226820] Adding 8257532k swap on /dev/mapper/centos_mail-swap. Priority:-2 extents:1 across:8257532k FS
[ 10.418840] EXT4-fs (vda1): mounting ext3 file system using the ext4 subsystem
[ 10.422061] EXT4-fs (vda1): mounted filesystem with ordered data mode. Opts: (null)
[ 10.886601] type=1305 audit(1714525138.547:3): audit_pid=578 old=0 auid=4294967295 ses=4294967295 res=1
[ 15.067184] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 80.072028] EXT4-fs warning (device dm-0): ext4_resize_begin:45: There are errors in the filesystem, so online resizing is not allowed

If this is a root partition, you’ll have to boot with a live CD ISO and then use e2fsck -y /dev/testvg/testlv to fix the problem.

See here:


Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top