[SOLVED] kvm: simulated disk removal via virsh

General support questions
Post Reply
dkoleary
Posts: 51
Joined: 2013/01/07 19:18:14
Contact:

[SOLVED] kvm: simulated disk removal via virsh

Post by dkoleary » 2013/03/22 18:08:47

... or, another way of asking: how do I remove an IDE disk device from a domain using virsh?

I'm trying to review processes for recovering from disk failures. While I know KVM isn't exactly like physical boxes, it's boatloads cheaper than working on expensive production systems.

What I"m trying to simulate is a disk drive going south. On a physical box, I'd just go yank the thing out of the chassis. On the KVM, I'm having issues:

[code]
# virsh detach-disk guest /var/lib/libvirt/images/guest\-2.img
error: Failed to detach disk
error: unsupported configuration: This type of disk cannot be hot unplugged
[/code]
I got that when the domain was running. I shut it down and reran it and got:

[code]
# virsh detach-disk guest /var/lib/libvirt/images/guest\-2.img
error: Failed to detach disk
error: Requested operation is not valid: cannot do live update a device on inactive domain
[/code]
Interesting. I can't kill the disk when the system's live or dead... So, I'm apparently missing something.

I can remove the device through the virt-manager gui, but I'm working on this remotely and X11 is a pig over the net.

Can anyone clue me in on what I'm missing or how I could force a disk failure. Extra helping of eternal gratitude if there's a way to do it while the system's live so I can record lvm and mdadm errors...

Thanks.

Doug O'Leary

User avatar
jlehtone
Posts: 4523
Joined: 2007/12/11 08:17:33
Location: Finland

Re: kvm: simulated disk removal via virsh

Post by jlehtone » 2013/03/22 18:22:22

Is your target-name as it should be?

See http://builder.virt-tools.org/artifacts/libvirt-virshcmdref/html/sect-detach-disk.html

dkoleary
Posts: 51
Joined: 2013/01/07 19:18:14
Contact:

Re: kvm: simulated disk removal via virsh

Post by dkoleary » 2013/03/22 18:48:19

Hey, thanks for the reply.

Apparently not, based on that example. however, I can't seem to get it working using the examples from your link and others. This is the disk I'm trying to make go away:

[code]
# h
guest
# fdisk -l /dev/sdc

Disk /dev/sdc: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[/code]
Unless I'm misreading that link, the target is supposed to be as the guest sees the device. ...

never mind, maybe not. That's not real clear, but I don't think it's from the guest perspective.

So, let's take a step back: I have a 10 gig 'disk' that's assigned to a guest system via a logical volume on the host. In the guest.xml file, I see:

[code]
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<source file='/var/lib/libvirt/images/guest-2.img'/>
<target dev='hdd' bus='ide'/>
<address type='drive' controller='0' bus='1' target='0' unit='1'/>
</disk>
[/code]
That's the guy I want to have a real or simulated failure. I just saw the hdd device so I tried that. I got the same errors re 'not hot swapable' and can't remove from a stopped domain.

There's a small but growing whisper that says detach-disk isn't the right virsh command.

Thanks for any hints/tips/suggestions.

Doug

dkoleary
Posts: 51
Joined: 2013/01/07 19:18:14
Contact:

Re: kvm: simulated disk removal via virsh

Post by dkoleary » 2013/03/22 19:23:08

Got it...

Apparently, I had to add the --persistent, use the right device (from the xml file) and use the correct argument order. The right command line is:

[code]
virsh # detach-disk guest hdd --persistent
Disk detached successfully
[/code]
Thanks

Doug O'Leary

User avatar
AlanBartlett
Forum Moderator
Posts: 9345
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk
Contact:

[SOLVED] kvm: simulated disk removal via virsh

Post by AlanBartlett » 2013/03/23 02:23:52

Thank you for reporting back with the solution.

On your behalf and for posterity, this thread is now marked [SOLVED].

Post Reply