Skip to content

Instantly share code, notes, and snippets.

@AndreiHondrari
Created November 25, 2022 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreiHondrari/a4b9c1e34fb88d8f97f2ec9581096c3d to your computer and use it in GitHub Desktop.
Save AndreiHondrari/a4b9c1e34fb88d8f97f2ec9581096c3d to your computer and use it in GitHub Desktop.

QEMU essential commands

Observations

  • KVM acceleration is for Linux machines
  • HVF acceleration is for MacOS Hypervisor.Framework

qemu-img options explained

  • -f specify disk format
    • VDI/HDD bla bla VirtualBox and VMWare formats
    • qcow2, qed, qcow - QEMU specific formats qcow2 is the latest and greatest (the others are deprecated)

qemu-system-x86_64 explained

  • -smp number of processors
  • -cdrom iso image to boot from
  • -hda disk image to boot from
  • -m amount of RAM
  • -vga type of virtual graphic card
  • -machine what kind of virtual machine
    • q35 newer virtual chipset
    • accel virtualization acceleration support
      • KVM for linux/windows(?) host OS
      • HVF for MacOS Hypervisor.Framework
  • -device adds a device driver
    • types of devices
      • controller/bridge/hub
      • USB
      • storage
      • network
      • input
      • display
      • sound
      • misc/uncategorised
      • CPU
      • watchdog
    • sample
      • e1000,netdev=net0 Intel Gigabit Ethernet with ID net0
  • -netdev configure network backend with ID 'str'
    • user,id=net0,hostfwd=tcp::5555-:22
      • id identity of the network backend
      • hostfwd has format hostip:hostport-guestip:guestport hence tcp : :555 - :22

Full e1000 options

e1000 options:
  acpi-index=<uint32>    -  (default: 0)
  addr=<int32>           - Slot and optional function number, example: 06.0 or 06 (default: -1)
  autonegotiation=<bool> - on/off (default: true)
  bootindex=<int32>
  extra_mac_registers=<bool> - on/off (default: true)
  failover_pair_id=<str>
  init-vet=<bool>        - on/off (default: true)
  mac=<str>              - Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56
  migrate_tso_props=<bool> - on/off (default: true)
  mitigation=<bool>      - on/off (default: true)
  multifunction=<bool>   - on/off (default: false)
  netdev=<str>           - ID of a netdev to use as a backend
  rombar=<uint32>        -  (default: 1)
  romfile=<str>
  romsize=<uint32>       -  (default: 4294967295)
  x-pcie-extcap-init=<bool> - on/off (default: true)
  x-pcie-lnksta-dllla=<bool> - on/off (default: true)

Creating a new virtual disk

qemu-img create -f qcow2 disk.qcow 10G

Booting up with the ISO disk inserted

qemu-system-x86_64
    -hda disk.qcow
    -cdrom ubuntu_qemu_mini.iso
    -smp 2
    -machine type=q35,accel=hvf
    -m 4G
    -vga virtio

Booting up normally

qemu-system-x86_64
    -hda disk.qcow
    -smp 2
    -machine type=q35,accel=hvf
    -m 4G
    -vga std

Booting up with network

qemu-system-x86_64
    -hda disk.qcow
    -smp 2
    -machine type=q35,accel=hvf
    -m 4G
    -vga std
    -device e1000,netdev=net0
    -netdev user,id=net0,hostfwd=tcp::5555-:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment