Skip to content

QEMU

Qemu is perfect for creating virtual machines.

sh
sudo apt-get install -y qemu-system ovmf

https://www.qemu.org/docs/master/system/qemu-manpage.html

Create Disk

qemu-img command to create qcow2 disk image, it will not allocate all space at once.

https://linux.die.net/man/1/qemu-img

sh
qemu-img create -f qcow2 "disk1.qcow2" "1T"

Network

Create a network card and attach it.

sh
PROFILE_IN_NETWORK_X1P1=",net=10.10.1.0/24,dhcpstart=10.10.1.20,ipv4"
sh
-device pci-bridge,id=pci.01,chassis_nr=1,addr=06,shpc=off
-netdev user,id=X1P1${PROFILE_IN_NETWORK_X1P1}
-device e1000,netdev=X1P1,bus=pci.01,mac=00:11:22:33:44:AA

Port Forwarding

Add exra port forwarding option to netdev option.

sh
,hostfwd=tcp:8822-:22

Boot from ISO

Qemu to run iso file we need to add cd drive in our start script. Add bootindex=2 to make it boot from cd if bootindex=1 is not found.

sh
-device ide-cd,drive=cdx,bootindex=2 -drive if=none,id=cdx,file=./iso/netinstall.iso,cache=unsafe,format=raw \

Start Qemu

Usually you need to make a script to start qemu, and you can use virt-manager.

sh
qemu-system-x86_64  \
    -machine pc,accel=kvm           \
    -cpu host                       \
    -m 32G                          \
    -enable-kvm                     \
    -nodefaults                     \
    -bios /usr/share/ovmf/OVMF.fd   \
    -device pci-bridge,id=pci.01,chassis_nr=1,addr=06,shpc=off -netdev user,id=X1P1,net=10.10.1.0/24,dhcpstart=10.10.1.20,ipv4 -device e1000,netdev=X1P1,bus=pci.01,mac=00:11:22:33:44:AA \
    -vnc :0 -k en-us -nographic -vga std \
    -drive if=none,id=disk1,file=/mnt/e/VM/disk1.qcow2,cache=unsafe -device ide-hd,drive=disk1,bootindex=1 \
    -watchdog i6300esb -watchdog-action none \
    -boot menu=on,once=d

VNC

You can use mobaxterm, tigervnc or any other vnc client to connect to qemu. 5900 is the default port for qemu vnc.