QEMU
QEMU, Quick EMUlator
https://gitlab.com/qemu-project/qemu
https://readthedocs.org/projects/qemu/versions
https://wiki.qemu.org/Hosts/Linux
https://embedded.pages.openeuler.org/openEuler-22.03-LTS-SP3/develop_help/qemu/qemu_start.html
https://ctf-wiki.org/pwn/linux/kernel-mode/environment/qemu-emulate
libvirt, virtualization api
https://gitlab.com/libvirt/libvirt
qemu & libvirt
https://www.cnblogs.com/yanzi2020/p/14462766.html
BOIS
compiling
sh
# get source
# 1
$ git clone https://gitlab.com/qemu-project/qemu.git --branch stable-8.0 --depth 1
$ git submodule update --init --recursive --depth 1
# 2
$ curl -O https://download.qemu.org/qemu-9.0.1.tar.xz
$ tar xvJf qemu-9.0.1.tar.xz
$ cd qemu-9.0.1
# dependencies
# https://wiki.qemu.org/Hosts/Linux#Building_QEMU_for_Linux
$ apt install make gcc
$ apt install flex bison
# compile
$ mkdir build
$ cd build
$ ../configure
start
sh
# create img
qemu-img create -f qcow2 root.qcow2 20G
$ qemu-system-aarch64 \
-m 2048 \
-cpu cortex-a57 \
-smp 2,cores=1,threads=2,sockets=1 \
-M virt \
-bios QEMU_EFI.fd \
-nographic \
-device virtio-scsi-device -device scsi-cd,drive=cdrom0 \
-drive if=none,file=alpine-standard-3.20.0-aarch64.iso,id=cdrom0,media=cdrom \
-device virtio-blk-device,drive=hd0 \
-drive if=none,file=alpine-3.20.0-rootfs.qcow2,id=hd0
-device nec-usb-xhci -device usb-kbd -device usb-mouse -device VGA \
network
! acl file
sh
cat > '/etc/qemu/bridge.conf' << EOF
include /etc/qemu/${USER}.conf
EOF
cat > '/etc/qemu/${USER}.conf' << EOF
allow all
EOF
TAP
sh
# inet ip set script
$ echo '#!/bin/bash
ifconfig $1 192.168.1.1 up' > /etc/qemu/qemu-ifup
$ chmod a+x /etc/qemu/qemu-ifup
# qemu parameters
-device virtio-net-pci,netdev=net0 -netdev tap,id=net0,script=/etc/qemu/qemu-ifup
# inner virtual machine
$ ip link set dev eth0 up
$ ip addr add 192.168.1.2/24 dev eth0
# test
$ ping 192.168.1.1
NAT
sh
# create inet
$ ip link add br0 type bridge
$ ip addr add 192.168.1.1/24 dev br0
# ip forward
$ iptables -t filter -A FORWARD -j ACCEPT -i br0 -o enp0s3
$ iptables -t filter -A FORWARD -j ACCEPT -o br0 -i enp0s3
$ iptables -t nat -A POSTROUTING -j MASQUERADE -s 192.168.1.0/24
# qemu parameters
-device virtio-net-pci,netdev=net0 -netdev bridge,br=br0,id=net0
# inner virtual machine
$ ip link set dev eth0 up
$ ip addr add 192.168.1.2/24 dev eth0
$ ip route add default via 192.168.1.1 dev eth0
# dnf
$ echo 'nameserver 8.8.8.8
nameserver 114.114.114.114' > /etc/resolv.conf
# test
$ ping www.baidu.com