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

     

    Tags

    .net .net-framework .net-framework-3.5 agile ajax ajax-control-toolkit ampq ansible apache asp.net asp.net-mvc axum bash benchmark blog blog-engine bootstrap buildout c# cache centos chrome ci cinder ckan cli cloud codeplex community debugger deface development-environment devstack devtime django dlr dns docker dockerimage dos easy_install elmah encoding environment-variables error event events exception exceptions fabrik firefox foreach forms gae gcc git github go google google-app-engine hack hacked hardware headless horizon html hugo iaas ienumerable iis internet iptables iron-python ironic iscsi java-script javascript jenkins jquery js kharkivpy kombu kvm kyiv lettuce libvirt linux lio loci logging mac-os mercurial microsoft microsoft-sync-framework mobile mono ms-office msbuild networking news nginx offtopic open-xml opensource openstack openvswitch os packages paraller-development patterns--practices php pika pip pnp podcast popup postgresql profiler project protocols pycamp pycharm pycon pykyiv pylint pypi python python-3 qcow quantum qumy rabbitmq rar react refactoring rfc rhel search-engine security selenium server shell silverlight socket source-control sourcegear-vault sql sql-server sql-server-express sqlalchemy ssh svg tests tgt tipfy tornado typescript uapycon ui uneta unit-tests usability virtualenv visual-studio vm vue.js vuejs web-development web-server web-service webpack windows windows-live word-press x32 x64 xcode xml xss xvfb интернет-магазин книги

    Recent posts

    Docker Image Collection

    Not a DNS Server for Libvirt

    Diskimage-builder in Docker

    Everything as a Code

    Vue.js, global variables and TypeScript


    Archives

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