qemu command

Purpose Description / Example

Start qemu - Setup a machine

Create virtual disk file image

qemu-img create -f qcow2 fedora25.img 30G

Start qemu - Setup a machine

Run a virtual machine from a iso file , with a hard drive and network.

qemu-system-x86_64  -boot c -cdrom CentOS-7-x86_64-DVD-1511.iso  -hda linux.img -user-net

Start qemu - Setup a machine

Run a virtual machine from hard drive and ssh at 2222 instead of 22.

qemu-system-x86_64  -hda linux.img   -redir tcp:2222::22 

Start qemu - Setup a machine

Run a virtual machine from hard drive and ssh at 2222 instead of 22 ( newer version as redir is deprecated)

qemu-system-x86_64  -hda linux.img    -device e1000,netdev=net0  -netdev user,id=net0,hostfwd=tcp::2222-:22 

Start qemu with kvm ( better performance )

Run a virtual machine from hard drive with kvm acceleration using virtualization extensions (Intel VT or AMD-V)

qemu-system-x86_64 -enable-kvm  -hda linux.img 

Start qemu with ram option

Run a virtual machine with 2go

qemu-system-x86_64 -hda linux.img -m 2000 

Start qemu with cpu option

Run a virtual machine with 4 core cpu ( no emulation here )

qemu-system-x86_64 -hda linux.img -cpu host -smp 4

Every day use cmd

Run a virtual machine

qemu-system-x86_64 -enable-kvm -cpu host -smp 4 -m 4000 -device e1000,netdev=net0  -netdev user,id=net0,hostfwd=tcp::2222-:22 -hda linux.img  

Boot with UEFI

Run window 10 in qemu : you may need to install the package edk2-ovmf.noarch

qemu-system-x86_64 -enable-kvm  -m 4000 -bios /usr/share/edk2/ovmf/OVMF_CODE.fd  -hda win10.qcow2

Shrink qcow2 image

Run in window 10, run sdelete : sdelete.exe -z C:\ and convert once again ( -c will compress image and therefore is advised for smaller image )

qemu-img convert -O qcow2 -c image.qcow2_ori image.qcow2

convert VirtualBox vdi to KVM qcow2

qemu-img convert -f vdi -O qcow2 vm.vdi vm.qcow2

List Device

qemu-system-x86_64 -device help