Score:0

How to use virsh attach-device without knowledge of target dev name

us flag

Is there a way to use virsh attach-device without using a target?

For example, I attach a disk by using an xml file which includes the target "sdc".

<disk type='block' device='disk'>
    <source dev='/dev/disk/by-label/mydisk' />
    <target dev='sdc' bus='scsi' />
</disk>

To speed the process I'd like to not specify a target device, only the bus. The reason for this is so I don't have to login to the guest, get the current devices used, then edit the host xml file to use a new "sdX" name, and finally then attach the disk. It would save a lot of steps to just let it attach to the next available disk device in the guest.

I'm moving enough disks in and out of the guest it's become annoying. Also, when I detach the disk, it leaves the sdX device used, so I have to edit the file and move up the letters until it works. I'd like to also be able to script this and that would be much easier if I didn't need to know what the next device available is in the guest.

If there's a way to get the next available in the guest using virsh or other kvm/qemu commands, that would be nice too.

I only use CLI - no virt manager.

EDIT: I just found "virsh domblklist", which lists the block devices on the guest, so I may look into changing to use virsh attach-disk. Just have to learn the arguments for that.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.