en:misc:qemu
Setup QEMU with Network
Make /etc/rc.d/rc.ip_forward executable. The command below is unneeded since reboot.
/etc/rc.d/rc.ip_forward start
Create /usr/local/bin/qemu-ifup
/usr/sbin/brctl addbr br0 /usr/sbin/ip addr add 172.20.0.1/16 dev br0 /usr/sbin/ip link set br0 up /usr/sbin/dnsmasq --interface=br0 --bind-interfaces --dhcp-range=172.20.0.2,172.20.255.254 /usr/sbin/tunctl -t tap0 -u 500 /usr/sbin/ip link set tap0 up promisc on /usr/sbin/ip link set tap0 master br0 /usr/sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE /usr/sbin/iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT /usr/sbin/iptables -A FORWARD -i tap0 -o wlan0 -j ACCEPT
Create /usr/local/bin/qemu-ifdown
/usr/sbin/iptables -F /sbin/ifconfig tap0 down /usr/sbin/tunctl -d tap0 pkill dnsmasq /sbin/ifconfig br0 down /usr/sbin/brctl delbr br0
The script for running a virtual machine.
Replace diskimage.qcow2 and cdimage.iso with actual filenames of hard disk and cdrom images.
If the guest went black after startup, remove -display gtk,gl=on
sudo /usr/local/bin/qemu-ifup qemu-system-x86_64 -enable-kvm -machine q35 -device intel-iommu -cpu host -m 4G -vga virtio -display gtk,gl=on -audio driver=pa,model=virtio -net nic -net tap,ifname=tap0,script=no,downscript=no -drive file=diskimage.qcow2,format=qcow2 -cdrom cdimage.iso sudo /usr/local/bin/qemu-ifdown
en/misc/qemu.txt · Last modified: 2024/05/15 07:17 by 鮑誠