-
Notifications
You must be signed in to change notification settings - Fork 3
/
qemu-run.py
executable file
·48 lines (38 loc) · 1.36 KB
/
qemu-run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
import subprocess
import os
import argparse
def main():
parser = argparse.ArgumentParser(description='Launch virtual hosts')
parser.add_argument('--index', '-i', default=1, type=int)
args = parser.parse_args()
if args.index > 9 or args.index < 1:
parser.exit(status=1, message="index must be in range [1:9]\n")
my_pid = os.getpid()
print(f"my pid is {my_pid}")
home=os.path.expanduser('~')
cwd=os.getcwd()
qemu_cmd = [
"qemu-system-x86_64",
"-nographic",
"-cpu", "host",
"-smp", "6",
"-device", "e1000,netdev=net0", "-netdev",
"user,id=net0" +
f",hostfwd=tcp::555{args.index}-:22" +
f",hostfwd=tcp::{args.index}2345-:1234" +
f",hostfwd=tcp::{args.index}3333-:3333",
'-drive', f'file=ubuntu-{args.index}.img,if=virtio',
"-readconfig", "configs/virthost.cfg",
"-kernel", "linux/arch/x86_64/boot/bzImage",
"-append", "console=ttyS0 root=/dev/vda rw",
"-gdb", f"tcp::{args.index}234",
'-fsdev', f'local,id=src,path={home}/src,security_model=passthrough,readonly=off',
'-device', 'virtio-9p-pci,fsdev=src,mount_tag=src',
]
print('launching:\n' + ' '.join(qemu_cmd))
p = subprocess.Popen(qemu_cmd)
p.wait()
print("~~~ Goodbye ~~~")
if __name__ == "__main__":
main()