开发者

Is it possible to script qemu?

开发者 https://www.devze.com 2023-02-16 09:31 出处:网络
I was wondering if it\'s possible to script qemu so that you can boot it up and automatically get it to run pr开发者_JAVA技巧ograms in the guest OS?In my case, that\'s Linux.Basically, I want to avoid

I was wondering if it's possible to script qemu so that you can boot it up and automatically get it to run pr开发者_JAVA技巧ograms 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?


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.


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.


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消