Skip to content

Instantly share code, notes, and snippets.

@GabrielL
Created June 1, 2014 15:23
Show Gist options
  • Save GabrielL/31be0c3da661c578dc84 to your computer and use it in GitHub Desktop.
Save GabrielL/31be0c3da661c578dc84 to your computer and use it in GitHub Desktop.
# before, launch qemu-system-x86_64 stos-i386-pc.boot \
# -serial tcp:127.0.0.1:4445,server,nowait \
# -qmp tcp:127.0.0.1:4444,server,nowait \
# -nographic
import sys
sys.path.append("/home/gaby/source/qemu/scripts/qmp")
import qmp
import pexpect
import time
monitor = qmp.QEMUMonitorProtocol(("127.0.0.1", 4444))
monitor.connect()
def qmp_send_string_to_vm(monitor, string):
translated = {
' ': 'spc',
'\n': 'ret'
}
for c in string:
if c in translated:
c = translated[c]
monitor.command('send-key', keys=[{'type':'qcode','data': c}])
time.sleep(0.05)
com = pexpect.spawn("nc 127.0.0.1 4445")
qmp_send_string_to_vm(monitor, 'serial\n')
qmp_send_string_to_vm(monitor, 'terminal serial\n')
com.expect(".*grub> ")
com.sendline("root (hd0,0)")
com.expect(".*grub> ")
com.sendline("setup (hd0)")
com.expect(".*grub> ")
monitor.command('quit')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment