环境: loongarchlinux 2023.12月版本, 3A6000
参考 https://openwrt.org/docs/guide-user/virtualization/qemu
1. 准备Qemu环境
pacman -Sy qemu-full
准备 /etc/qemu-ifup 和 qemu-ifdown脚本
#/etc/qemu-ifup
#!/bin/sh
echo "Executing /etc/qemu-ifup"
echo "Bringing up $1 for bridged mode..."
sudo /usr/bin/ip link set $1 up promisc on
echo "Adding $1 to br0..."
sudo /usr/bin/brctl addif br0 $1 sleep 2
#/etc/qemu-ifdown #!/bin/sh
echo "Executing /etc/qemu-ifdown"
sudo /usr/bin/ip link set $1 down
sudo /usr/bin/brctl delif br0 $1
sudo /usr/bin/ip link delete dev $1
- 下载openwrt
wget https://downloads.openwrt.org/releases/23.05.3/targets/x86/64/openwrt-23.05.3-x86-64-generic-ext4-combined.img.gz
gunzip [imgfile]
调整img文件大小,为扩容文件系统做准备
qemu-img resize -f raw openwrt-*.img 300M
启动openwrt
sudo qemu-system-x86_64 -nographic \ -M q35 \ -m 512 \ -drive file=openwrt-23.05.3-x86-64-generic-ext4-combined.img,id=d0,if=none,bus=0,unit=0 \ -netdev tap,id=openwrt,ifname=tap0 \ -device ide-hd,drive=d0,bus=ide.0 \ -device virtio-net-pci,netdev=openwrt
#get the console,设置网络
uci set network.lan.ipaddr='192.168.2.20'
uci set network.lan.gateway='192.168.2.1'
uci set network.lan.dns='192.168.2.1'
uci commit
reboot
扩容openwrt根分区,原分区实在太小
opkg update
opkg install losetup
opkg install cfdisk
opkg install resize2fs
ROOT="/dev/sda2"
LOOP="$(losetup -f)"
losetup ${LOOP} ${ROOT}
fsck.ext4 -y -f ${LOOP}
resize2fs ${LOOP}
reboot