How to exdend your VM's drive size in 8 steps

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 **` 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:

    - **Create backup of your virtual drive** (E.g. `cp /var/lib/libvirt/images/devstack.img /var/lib/libvirt/images/devstack.img.bak`)!!!!
  3. 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 /var/lib/libvirt/images/devstack.img**
  4. - Boot VM: `**sudo virsh start **` - **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 - Mount drive to your VM:
    **sudo mount /dev/sdb1 /mnt/data** - Create filesystem:
    **sudo resize2fs /dev/vda3** - In case, if you use something else like parted instead of fdisk, you could just extend filesystem size:
    **sudo mkfs.ext3 /dev/sdb1**

  • Shutdown VM:
      1. **sudo shutdown -p now** inside VM 1. **sudo virsh shutdown <vm_name>** on my host
  • 1. Find QCOW file to change it:
    Be default, it’s located at /var/lib/libvirt/images
    **virsh dumpxml dsvm1 | grep file**
    Find something like:

    1. Create backup of your virtual drive (E.g. cp /var/lib/libvirt/images/devstack.img /var/lib/libvirt/images/devstack.img.bak)!!!!
  • Change QCOW image size: **sudo qemu-img resize /var/lib/libvirt/images/devstack.img +10G**  - this command increases size with 10 GB more
      1. 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 /var/lib/libvirt/images/devstack.img
  • 1. Boot VM: **sudo virsh start <vm_name>** 1. 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 1. Mount drive to your VM:
    sudo mount /dev/sdb1 /mnt/data 1. Create filesystem:
    sudo resize2fs /dev/vda3 1. In case, if you use something else like parted instead of fdisk, you could just extend filesystem size:
    sudo mkfs.ext3 /dev/sdb1

     



    Archives

    2018 (2)
    2017 (3)
    2016 (2)
    2015 (3)
    2014 (5)
    2013 (17)
    2012 (22)
    2011 (35)
    2010 (25)
    2009 (35)
    2008 (32)
    2007 (2)