0

I tried lsof|grep *.qcow2 and got no results back (why is that? I definitely have VMs running using that disk format).

I also considered grepping qcow2 on *.xml within the config directory, but this wouldn't tell me which were in use necessarily.

Is there an easy way to determine which disk images are in use and by which domains/VMs?

Also, since lsof doesn't seem to do what I want, what is the method you all use to determine which files are accessed by which process?

Running Cent 6.3 with libvirt/kvm/qemu virsh 0.10.2

EDIT: See my comment, it was grep that was failing me, not lsof.. What is going on that I need to enable Extended regex to match '*.qcow2' ?

4
  • Apparently I needed to use egrep to find '*.qcow2' ?? Isn't that simply a glob/wildcard? Why do I need to have grep extended regex enabled to match that expression? Anyhow, it seems adding -E or using egrep found what I needed.
    – user160910
    Apr 8, 2013 at 15:20
  • * would indicate a pattern - without pattern matching you'd actually be looking for files with "*.qcow2" in the filename. As your grepping a file listing, surely just "grep .qcow2" would suffice.
    – USD Matt
    Apr 8, 2013 at 15:30
  • I guess since * matches 0 or more of the characters preceding it, and I gave no characters before the * it was like I was trying to match nothing. However since it is zero or more, shouldn't the rest of the expression have matched the .qcow2 even though the * was extraneous? Apparently it works if I give a space before the * like ' *.qcow2'.
    – user160910
    Apr 8, 2013 at 15:49
  • For anyone interested you can also do virsh domblklist or as mentioned before lsof |grep qcow2
    – user160910
    Apr 8, 2013 at 21:05

1 Answer 1

1

Since the file format and extension quite often differ (libvirt's defauls is .img usually - for both qcow2 and raw), and sometimes you're using LVs and not files, I'd start looking into the currently used storage directly:
ps -ef |grep qcow2|awk -F'-drive' '{ print $2 }'|cut -d',' -f1
This will only show the first disk, you can extend the script to show more

You must log in to answer this question.