5

I was wondering if it's possible to script qemu so that you can boot it up and automatically get it to run programs in the guest OS? In my case, that's Linux. Basically, I want to avoid having to interact with the guest so that I can perform a batch of experiments with condor or something similar.

I saw this question which suggests a method using python, but I'm wondering if there's any other way at all that is supported by qemu itself?

I don't want to do anything too fancy. Assuming automatic login on the guest to a simple shell, I was thinking of a script such as this:

cd <some_dir>
./experiment
scp result me@my.machine.com:

Any ideas, otherwise I'll try out the python method above?

Community
  • 1
  • 1
Timothy Jones
  • 133
  • 1
  • 6
  • Using Expect - http://stackoverflow.com/questions/3146013/qemu-guest-automation/7810608#7810608 – db42 Nov 12 '11 at 16:27

4 Answers4

5

The QEMU Monitor can interact with guest systems to a limited extent using its own console. This includes reading registers, controlling the mouse/keyboard, and getting screen dumps. There is a QEMU Monitor Protocol (QMP) that lets you pass JSON commands to and read values from the guest system.

bobbogo
  • 14,989
  • 3
  • 48
  • 57
jeremiah
  • 181
  • 3
  • 11
2

Anything you put into /etc/rc.local runs at boot. You will need to make sure that the environment is configured adequately before running your commands. Make the very last line of your script 'shutdown -h now' and the vm will even shut itself down cleanly.

pokute
  • 147
  • 1
  • 2
  • Another idea along the same lines is I tend to do is to make my machine autologin using mingetty and then just set my .bashrc file to source some `whatever.sh` file. If the whatever.sh is found on a ext2 raw image, I can mount that from the command line, change whatever.sh, restart the VM and let it run. It's kind of roundabout, but it works and it makes it easy to swap the workload in the disk image. – KarateSnowMachine Mar 31 '11 at 21:48
0

You could have a script on your host that starts the VM, waits a small amount of time, then does an ssh user@vm experiment to run the program. The stdout would end up on your host and can be redirected into a file to capture it locally and not need the scp.

Shannon Nelson
  • 2,090
  • 14
  • 14
-1

All depends on image of your VM which you load with QEMU. For example, in my case, I just added required commands to /etc/profile

But it requires to login before script would be proceeded. To make autologin I did below changes to /etc/inittab:

# Startup the system
::sysinit:/bin/mount -t proc proc /proc
::sysinit:/bin/mount -o remount,rw /
::sysinit:/bin/mkdir -p /dev/pts
::sysinit:/bin/mkdir -p /dev/shm
::sysinit:/bin/mount -a
::sysinit:/bin/hostname -F /etc/hostname
# now run any rc scripts
::sysinit:/etc/init.d/rcS
::sysinit:/bin/login -f root

# Put a getty on the serial port
ttyAMA0::respawn:/sbin/getty -L  ttyAMA0 0 vt100 # GENERIC_SERIAL

# Stuff to do for the 3-finger salute
#::ctrlaltdel:/sbin/reboot

# Stuff to do before rebooting
::shutdown:/etc/init.d/rcK
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r

Below command forces to login with username 'root' and execution /etc/profile script:

::sysinit:/bin/login -f root
N0dGrand87
  • 727
  • 1
  • 9
  • 16