Last active
September 19, 2024 01:03
-
-
Save roxwize/aa0279040214c6417433c2c3c6d8f922 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import argparse, subprocess, sys | |
| parser = argparse.ArgumentParser( | |
| description = 'run a qemu image with 3GB of ram and KVM acceleration (plus some other stuff)' | |
| ) | |
| parser.add_argument('-i', '--image', required = True) | |
| parser.add_argument('-a', '--arch', choices = ['aarch64', 'arm', 'x86_64'], default = 'x86_64', help = 'system architecture to use, currently not functional (default x86_64)') | |
| parser.add_argument('-f', '--format', choices = ['raw', 'qcow2'], default = "qcow2", help = '(default qcow2)') | |
| parser.add_argument('-r', '--ram', default = '3G', help = '(default 3G)') | |
| parser.add_argument('--args', help = 'additional arguments') | |
| parser.add_argument('--audiodriver', default = "pa", help = '`qemu-system-x86_64 -audiodev help` for options') | |
| group2 = parser.add_argument_group(title = 'Boot') | |
| group2.add_argument('--boot-cdrom', action = 'store_true', help = 'boot into cdrom instead of hda at boot') | |
| group1 = parser.add_argument_group(title = 'Storage') | |
| group1.add_argument('-u', '--usb-passthrough', help = 'syntax: [BUS]:[DEVICE]') | |
| group1.add_argument('--cdrom') | |
| group1.add_argument('--sd-card') | |
| group1.add_argument('--sd-card-format', default = "raw", help = '(default raw)') | |
| args = parser.parse_args() | |
| params = [ | |
| "-drive", "file=" + args.image + ",index=0,format=" + args.format, | |
| "-m", args.ram | |
| ] | |
| if args.arch == "x86_64": | |
| params = params + [ | |
| "-accel", "kvm", | |
| "-audiodev", "pa,id=vsnd0", | |
| "-cpu", "Skylake-Client,vmx=on", | |
| "-device", "ich9-intel-hda", | |
| "-device", "AC97,audiodev=vsnd0", | |
| "-machine", "pc", | |
| "-vga", "virtio" | |
| ] | |
| # boot | |
| if args.boot_cdrom: | |
| params = params + ["-boot", "once=d"] | |
| else: | |
| params = params + ["-boot", "c"] | |
| # storage | |
| if args.usb_passthrough: | |
| dev = args.usb_passthrough.split(":") | |
| params = params + [ | |
| "-device", "qemu-xhci", | |
| "-device", "usb-host,hostbus=" + dev[0] + ",hostaddr=" + dev[1] | |
| ] | |
| if args.cdrom: | |
| params = params + ["-cdrom", args.cdrom] | |
| if args.sd_card: | |
| params = params + [ | |
| "-device", "sdhci-pci", | |
| "-device", "sd-card,drive=sd-drive", | |
| "-drive", "id=sd-drive,if=none,format=" + args.sd_card_format + ",file=" + args.sd_card | |
| ] | |
| if args.args: | |
| params = params + args.args.split() | |
| subprocess.run(["qemu-system-x86_64"] + params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment