The Gluster Blog

Gluster blog stories provide high-level spotlights on our users all over the world

Adding new virtual disks to running virt images.


I always finding my self clicking UI’s and modifying command line incantations to create VMs with new virtual block devices.  This is probably pretty common to anyone who is using VMs to mimic a real world environment where there is a dedicated device for used by a particular program (in my case, its usually for creating a VM that tests a  gluster setup and needs a dedicated brick).

So here’s how to add a new disk image into a running kvm instance using virsh (the shell for libvirt) and qemu-img.

First, create your disk on the host:

qemu-img create -f raw /VirtualMachines/idh2.img 10G

Now, we want to attach it.  Attach takes a “–target” option – and its important to name the target deliberately. indicates that 
vdX -> becomes a virtio attachment
sdX -> becomes a scsi attchement
hdX -> becomes an IDE  attachment

So lets do virtio : I’m assuming its the easy way to attach devices for this scenario (i could be wrong) , but the sdX (scsi) approach for me results in a “Unable to determine model for scsi controller” error… So lets just go with vdx as the device name.  That will map to virtio: 

sudo virsh attach-disk rhs_21_gluster2 /VirtualMachines/idh2.img –target vda –driver qemu

        …(you might need the –subdriver qcow2 option, not sure)…
Okay ! Now, lets make sure we *(really)* have a 10 Gig disk in there: 

[root@idh1 ~]# fdisk -l | grep vd*
Disk /dev/vdc: 10.7 GB, 10737418240 bytes 

Yay it worked !  So its really easy using qemu and virsh attach-disk to add new disk images at runtime.  Now Im not sure why it got called “vdc” instead of “vdX”. But thats okay.  I now have my virtual block happily residing in my newly created VM… And I can easily automate stuff on top of this, and add more over time if I needed it without relying on the Virtual Machine Manager UI. 


  • 06 Dec 2020
    Looking back at 2020 – with g...

    2020 has not been a year we would have been able to predict. With a worldwide pandemic and lives thrown out of gear, as we head into 2021, we are thankful that our community and project continued to receive new developers, users and make small gains. For that and a...

    Read more
  • 27 Apr 2020
    Update from the team

    It has been a while since we provided an update to the Gluster community. Across the world various nations, states and localities have put together sets of guidelines around shelter-in-place and quarantine. We request our community members to stay safe, to care for their loved ones, to continue to be...

    Read more
  • 03 Feb 2020
    Building a longer term focus for Gl...

    The initial rounds of conversation around the planning of content for release 8 has helped the project identify one key thing – the need to stagger out features and enhancements over multiple releases. Thus, while release 8 is unlikely to be feature heavy as previous releases, it will be the...

    Read more