本文章使用Ubuntu focal 20.04 LTS作为宿主机qemu版本为5.2.0,以x86_64构架openwrt为例。
直接启动固件
因为宿主机也是x86_64构架且支持硬件虚拟化,所以这里启动kvm加速,openwrt-x86-64-generic-squashfs-combined.img是编译好的固件。
qemu-system-x86_64 --enable-kvm openwrt-x86-64-generic-squashfs-combined.img
可以看见openwrt成功运行并打印log。
Booting `OpenWrt' Booting `OpenWrt
'
[ 0.000000] Linux version 5.4.52 (fw867@koolshare.cn) (gcc version 8.4.0 (OpenWrt GCC 8.4.0 r13620-533ee970da)) #0 SMP Thu Jul 23 12:16:45 2020
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz root=PARTUUID=09cf104a-02 rootwait console=tty0 console=ttyS0,115200n8 noinitrd
[ 0.000000] x86/fpu: x87 FPU will use FXSAVE
[ 0.000000] BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x0000000007fdffff] usable
[ 0.000000] BIOS-e820: [mem 0x0000000007fe0000-0x0000000007ffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
[ 0.000000] NX (Execute Disable) protection: active
[ 0.000000] SMBIOS 2.8 present.
[ 0.000000] DMI: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
[ 0.000000] Hypervisor detected: KVM
[ 0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00
[ 0.000000] kvm-clock: cpu 0, msr 21ea001, primary cpu clock
[ 0.000000] kvm-clock: using sched offset of 1486715385 cycles
[ 0.000003] clocksource: kvm-clock: mask: 0xffffffffffffffff max_cycles: 0x1cd42e4dffb, max_idle_ns: 881590591483 ns
[ 0.000006] tsc: Detected 3693.044 MHz processor
[ 0.001576] last_pfn = 0x7fe0 max_arch_pfn = 0x400000000
[ 0.001634] x86/PAT: Configuration

本文介绍了如何在Ubuntu Focal 20.04 LTS上使用QEMU 5.2.0模拟OpenWrt x86_64系统,并启用KVM加速。通过直接启动固件,展示了OpenWrt成功运行的日志。此外,还详细说明了如何配置网桥以实现虚拟机与物理机之间的网络互通,包括修改netplan配置文件并应用设置。最后,通过在QEMU命令中指定网桥设备,实现了OpenWrt与宿主机的网络连接。

2375

被折叠的 条评论
为什么被折叠?



