Skip to content

Instantly share code, notes, and snippets.

@Opposite34
Last active January 15, 2026 10:10
Show Gist options
  • Select an option

  • Save Opposite34/5ab16015a867f4fab8b7c8ed4e1b9e66 to your computer and use it in GitHub Desktop.

Select an option

Save Opposite34/5ab16015a867f4fab8b7c8ed4e1b9e66 to your computer and use it in GitHub Desktop.
QEMU Commands: Notes for self

QEMU Commands

References

Creating Image

qemu-img create -f qcow2 Image.img 10G Note: cow stands for copy-on-write

Resizing Image

For adding space to the image qemu-img resize disk_image +10G

For removing space qemu-img resize --shrink disk_image -10G

Running the VM

qemu-system-x86_64 -enable-kvm -cdrom OS_ISO.iso -boot menu=on -drive file=Image.img -m 4G

Note:

  • change 4G to appropriate RAM allocation for the system
  • remove the cdrom flag after installing the OS
  • use -smp <CORE_NUM> to specified CPU cores
  • add -vga virtio -display sdl,gl=on for performance
  • add -device ich9-intel-hda -device hda-output for audio support (intel audio specific)

Other stuffs

for UEFI copy over /usr/share/edk2/x64/OVMF_VARS.4m.fd to be readable and then do the follow (source: archwiki in ref):

-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/x64/OVMF_CODE.4m.fd \
-drive if=pflash,format=raw,file=/copy/of/OVMF_VARS.4m.fd

Keybinds

CTRL+ALT+F fullscreen CTRL+ALT+Q quit CTRL+ALT+G to unfocus from the VM

Linux stuffs

After resizing (growing) an image, you can do the following to grow the partition:

  1. cfdisk /dev/<drive> and then resize the partition there
  2. e2fsck -f /dev/<partition> to check the partition
  3. resize2fs /dev/<partition> to then grow the filesystem to the partition

For btrfs you can also just create a new partition with cfdisk and then use the command below sudo btrfs device add /dev/<partition> <mountpoint>

Example: sudo btrfs device add /dev/vda3 / would add the vda3 partition to be used for the / mountpoint. This seems to work better for atomic distros / if you're lazy to chroot and do all the resizing there.

@Opposite34
Copy link
Author

Opposite34 commented Jun 11, 2025

#/usr/bin/sh
qemu-system-x86_64 -enable-kvm -boot menu=on -drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/x64/OVMF_CODE.4m.fd -drive if=pflash,format=raw,file=OVMF_VARS.4m.4d -drive file=PopOS.img -m 4G -smp 3 -vga virtio -device ich9-intel-hda -device hda-output

Example script for running PopOS (after it has been installed into the img) in QEMU with UEFI.

@Opposite34
Copy link
Author

regarding btrfs, there's also btrfs-replace, which might be cleaner to use but is going to take some time to finish migrating things and such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment