12.1.14

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.  http://builder.virt-tools.org/artifacts/libvirt-virshcmdref/html/sect-attach-disk.html 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. 


2 comments:

  1. Hiện nay rất nhiều bạn quan tâm đến z1000 giá về việt nam bao nhiêutác dụng của ic xe máy. Được nghỉ một thời gian dài nhiều người đang xem xétcó nên đi nam du không
    Bạn có đang tìm hiểu về giới tính của mình, mình có phải là ô môi không dầu hiệu nhận biết ô môi và mình có phải là gay hay không Dấu hiệu nhận biết một chàng gay.
    HIện nay một số DJ rất được săn đón, các thông tin như SlimV sinh năm bao nhiêu hay là DJ gin tên thật là gì
    Nhiều phụ huynh đang băn khoăn mua xe cho con học đai học nên mua xe tay ga nào hiện nay và thắc mắc về có nên thay vỏ xe không ruột? hay muốn biết bugi xe máy loại nào tốt
    Cũng rất được quan tâm hiên này là giỗ tổ hùng vương ở sài gòn nên đi đâu?

    ReplyDelete
  2. > but the sdX (scsi) approach for me results in a "Unable to determine model for scsi controller" error...

    you probably forgot to add a scsi controller first, it's another step before attaching the disk

    ReplyDelete