QEMU Cheatsheet
创建于:
先前因为各种各样的动机用了 QEMU。读 Arch wiki 的时候大致做了个笔记记录常用的使用方法。
Install
qemu
,qemu-arch-extra
(optional, for other architectures)Disk images
Create disk image
qemu-img create -f qcow2 windows_7.cow 32G
Start the virtual machine from CD drive (with iso file)
bashqemu-system-x86_64 -cdrom iso_image_path -boot order=d -drive file=disk_image_path,format=qcow2
Memory
-m 2G
Boot menu
-boot menu=on
Ctrl+Alt+G to escape mouse
Enable KVM: append
-enable-kvm
Enable Hyper-V enlightenments for Windows guests
bash-cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time
CPU cores:
-smp 2
Network
- By default QEMU should automatically set up network for guest.
- Port forwarding
-nic user,hostfwd=tcp::8080-:80
: forward guest 80 to host 8080
Share data between host&guest
The default user-mode networking allows the guest to access the host OS at the IP address
10.0.2.2
.3D acceleration
GPU passthrough. Failed on my machine.
UEFI
- Install edk2-ovmf
cp /usr/share/edk2-ovmf/x64/OVMF_VARS.fd
-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2-ovmf/x64/OVMF_CODE.fd
-drive if=pflash,format=raw,file=/tmp/MY_VARS.fd