17

I am using qemu-system-x86_64 to boot virtual machines on kvm running on Ubuntu 12.04 64-bit desktop. I have a few VM's that are currently running. I want to get the list of all VM's booted using qemu-system-x86_64 on this host machine, how do I get this list?

Specifications:

  • qemu-system-x86_64 version 1.0

  • linux 3.2.0-60-generic

P.S.: Just as a side note, I am aware of virsh -c qemu:///system list which would list all VMs booted using virsh. However, this does not seem to give the list of VMs booted using qemu-system-x86_64, it would be great if virsh command could list the VMs booted using qemu-system-x86_64.

jobin
  • 28,667

2 Answers2

24

Each VM started with qemu-system-x86_64 corresponds to a process on the host machine. This means that a list of qemu-system-x86_64 processes corresponds to the list of VMs that are currently running on the host.

ps -ef | grep qemu-system-x86_64

This will list all the qemu-system-x86_64 processes, their pids and the parameters used to start the VM.

mas_kur1
  • 431
  • 1
    +1 for a good method, would appreciate a script that would help distinguish two virtual machines booted using qemu-system-x86_64 (may have the same name). – jobin May 17 '14 at 10:13
  • 1
    If both VMs use the same image and you don't want to distinguish them by pid, you could assign a different MAC address for each VM. This depends off course also on your network settings, if this is an option: -net nic,macaddr= Off course, this does not solve the problem for already existing VMs. – mas_kur1 May 17 '14 at 10:44
  • Thanks. Noting the process might not be named qemu-system-x86_64. In my case it is qemu-kvm. – Peter Becich Dec 29 '23 at 20:32
3

Here is a solution for some more advanced nice view (see source below):

This one shows all wemu-systems, not only the x86_64 ones.

Cutton Eye@QEMU:~$ ps -ef | awk -e '/qemu/ && !/awk/' | sed -e 's/[^/]*//' -e 's/ -/\n\t-/g'

/18   00:00:17 qemu-system-x86_64
  -enable-kvm
  -hda MyDrive.img
  -m 1G
  -…

Sean Swehla has created this awesome regex

Cutton Eye
  • 1,276
  • 1
    What is the -e option for awk? I have to remove it to make the command work. – Livy Nov 23 '21 at 01:51
  • awk is a need tool for advanced scripting in command line. -e / --source is the actual script to be executed followed by the actual string. For your convenience don't hesitate to run man awk for retrieving the answer to your command line options. – Cutton Eye Nov 30 '21 at 11:44