qemu 运行 linux(一)

qemu 运行 linux

linux 内核版本

linux-6.5.7

linux 内核下载地址

https://www.kernel.org/

可以在浏览器中点击下载,也可以使用命令行下载

wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.5.7.tar.xz

解压

tar -vxf linux-6.5.7.tar.xz 

生成配置文件

在根目录 linux-6.5.7 执行

make vexpress_defconfig ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf-

编译设备树

在根目录 linux-6.5.7 执行

make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- dtbs

编译内核

在根目录 linux-6.5.7 执行

make -j6 ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf-

报错与解决

fatal error: gmp.h: No such file or directory
fatal error: mpc.h: No such file or directory

解决

sudo apt-get install libgmp-dev
sudo apt-get install libmpc-dev

运行 linux

sudo qemu-system-arm -M vexpress-a9 -m 512M -kernel arch/arm/boot/zImage -dtb arch/arm/boot/dts/arm/vexpress-v2p-ca9.dtb -nographic
# -dtb  指定设备树,否则会失败

启动日志

1f00          131072 mtdblock0 
 (driver?)
1f01           32768 mtdblock1 
 (driver?)
List of all bdev filesystems:
 ext3
 ext4
 ext2
 cramfs
 squashfs
 vfat

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.5.7 #3
Hardware name: ARM-Versatile Express
 unwind_backtrace from show_stack+0x10/0x14
 show_stack from dump_stack_lvl+0x40/0x4c
 dump_stack_lvl from panic+0x104/0x320
 panic from mount_root_generic+0x208/0x29c
 mount_root_generic from prepare_namespace+0x1bc/0x20c
 prepare_namespace from kernel_init+0x18/0x12c
 kernel_init from ret_from_fork+0x14/0x28
Exception stack(0xa0825fb0 to 0xa0825ff8)
5fa0:                                     00000000 00000000 00000000 00000000
5fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
5fe0: 00000000 00000000 00000000 00000000 00000013 00000000
---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) ]---

从日志中可以看到,挂载 VFS 文件系统失败,导致内核 panic。下节将介绍 rootfs。

附录脚本

export ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf-   # 设置编译平台和工具链
make vexpress_defconfig                                 # 加载板子的配置信息
make dtbs                                               # 编译设备树
make -j8                                                # 编译内核

参考

  • https://www.jianshu.com/p/91baa4d140a2

猜你喜欢

转载自blog.csdn.net/tyustli/article/details/133847627