It’s my first try to blog in English. Feel free to comment for any typo, grammar errors, etc.

There are nothing new, nothing innovative below. There are just a step-by-step guide to not forget and to not google each time when I need it.

Usually, on my dev environment, I’ve got KVM instances with disk images in QCOW format. So time to time I need to extend my virtual disks to get more free space.

  1. Shutdown VM:
    • `sudo shutdown -p now` inside VM
    • `sudo virsh shutdown <vm_name>` on my host
  2. Find QCOW file to change it:
    Be default, it’s located at `/var/lib/libvirt/images`
    `virsh dumpxml dsvm1 | grep file`
    Find something like:
    <disk type='file' device='disk'>
    <source file='/var/lib/libvirt/images/devstack.img'/>
  3. Create backup of your virtual drive (E.g. `cp /var/lib/libvirt/images/devstack.img /var/lib/libvirt/images/devstack.img.bak`)!!!!
  4. Change QCOW image size: `sudo qemu-img resize /var/lib/libvirt/images/devstack.img +10G`  - this command increases size with 10 GB more
    • If image has snapshots, you need to delete them first:
      sudo qemu-img snapshot -l /var/lib/libvirt/images/devstack.img
      sudo qemu-img snapshot -d <snapshot_id> /var/lib/libvirt/images/devstack.img
  5. Boot VM: `sudo virsh start <vm_name>`
  6. NOTE: I don’t care about disk data in this example. But I have backup (see #3) and can restore all needed data.
    Create new partition table with fdisk. fdisk can’t change partition size, we need to delete and create a new one:
    sudo fdisk /dev/sdb
    ‘d’ - delete partitions(s)
    ‘p’ - create new partition(s)
    ‘w’ - write changes
  7. Mount drive to your VM:
    sudo mount /dev/sdb1 /mnt/data
  8. Create filesystem:
    sudo resize2fs /dev/vda3
  9. In case, if you use something else like parted instead of fdisk, you could just extend filesystem size:
    sudo mkfs.ext3 /dev/sdb1