👋
OpenWrtをQemu環境で試す。
環境
Mac(M1)
必要ソフトダウンロード
Qemuの導入
brew install qemu
上記リンクから以下の2つをダウンロード
generic-ext4-rootfs.img.gz
generic-initramfs-kernel.bin
rootfsを展開
gzip -dk openwrt-24.10.1-armsr-armv8-generic-ext4-rootfs.img.gz
Qemuで実行
qemu-system-aarch64 \
-machine virt \
-cpu cortex-a53 \
-m 1024 \
-nographic \
-kernel openwrt-24.10.1-armsr-armv8-generic-initramfs-kernel.bin \
-drive file=openwrt-24.10.1-armsr-armv8-generic-ext4-rootfs.img,if=virtio,format=raw \
-netdev user,id=net0,hostfwd=tcp::2222-:22 \
-device virtio-net-pci,netdev=net0
40秒ほど待つとログの出力が止まりますので、エンターを押します。
するとシェルが出てきます。
[ 36.008200] virtio_net virtio0 eth0: entered promiscuous mode
[ 36.057216] br-lan: port 1(eth0) entered blocking state
[ 36.057488] br-lan: port 1(eth0) entered forwarding state
BusyBox v1.36.1 (2025-04-13 16:38:32 UTC) built-in shell (ash)
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
OpenWrt 24.10.1, r28597-0425664679
-----------------------------------------------------
=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
root@OpenWrt:~#
sshで接続できるように設定
# いったんWANを消す(衝突回避)
uci -q delete network.wan
# br-lan の bridge デバイス定義を消す(eth0が戻される根本原因)
# だいたい device 'br-lan' が1つあるはずなので全部消してOK
uci -q delete network.@device[0]
uci -q delete network.@device[0]
uci -q delete network.@device[0]
# LANをeth0直結 + DHCPにする(= QEMU user-net からIPをもらう)
uci set network.lan.device='eth0'
uci set network.lan.proto='dhcp'
# LAN固定IP設定が残ってると邪魔なので消す
uci -q delete network.lan.ipaddr
uci -q delete network.lan.netmask
uci -q delete network.lan.ip6assign
uci commit network
/etc/init.d/network restart
設定内容確認
$ ip r
root@OpenWrt:~# ip r
default via 10.0.2.2 dev eth0 src 10.0.2.15
10.0.2.0/24 dev eth0 scope link src 10.0.2.15
別ターミナルを起動してSSH接続
ssh -p 2222 root@127.0.0.1
接続できると思います。
WebUIにアクセス
Qemuをctrl+ a > x で一度閉じます。Web用のポートを設定して再度Qemuを起動します。
qemu-system-aarch64 \
-machine virt \
-cpu cortex-a53 \
-m 1024 \
-nographic \
-kernel openwrt-24.10.1-armsr-armv8-generic-initramfs-kernel.bin \
-drive file=openwrt-24.10.1-armsr-armv8-generic-ext4-rootfs.img,if=virtio,format=raw \
-append "root=/dev/vda console=ttyAMA0" \
-netdev user,id=net0,hostfwd=tcp::2222-:22,hostfwd=tcp::8080-:80 \
-device virtio-net-device,netdev=net0
ネットワーク設定
uci -q delete network.wan
uci -q delete network.@device[0]
uci -q delete network.@device[0]
uci -q delete network.@device[0]
uci set network.lan.device='eth0'
uci set network.lan.proto='dhcp'
uci -q delete network.lan.ipaddr
uci -q delete network.lan.netmask
uci -q delete network.lan.ip6assign
uci commit network
/etc/init.d/network restart
パスワード設定(WebUIログインに使います)
passwd
LuCI(WebUI)をインストールします。
opkg update
opkg install luci
確認
/etc/init.d/uhttpd status
WebUIへアクセス
http://127.0.0.1:8080/cgi-bin/luci/

http://127.0.0.1:8080/ にアクセスすると、/cgi-bin以下が自動で補完されます。
ただし、ブラウザのキャッシュが残ってると違うURLにリダイレクトされてしまいます。
うまくWebUIが表示されない場合はシークレットウィンドウで試すとうまくいく可能性があります。
実際、今回試した環境ではhttp://127.0.0.1:8080/にアクセスすると
http://127.0.0.1:8080/login/login.cgi にリダイレクトされてしまいました。
Discussion