linux内核nfs挂载根文件系统失败的log如下:
[ 5.586185] VFS: Cannot open root device "nfs" or unknown-block(0,255)
[ 5.592372] Please append a correct "root=" boot option; here are the available partitions:
[ 5.600700] b300 3817472 mmcblk0 driver: mmcblk
[ 5.605858] b301 264759 mmcblk0p1
[ 5.610103] b302 264759 mmcblk0p2
[ 5.614349] b303 104412 mmcblk0p3
[ 5.618595] b304 3158463 mmcblk0p4
[ 5.622844] b308 7761920 mmcblk1 driver: mmcblk
[ 5.628057] b309 7726620 mmcblk1p1
[ 5.632288] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,255)
[ 5.640837] Backtrace:
[ 5.643135] [<c0034fb8>] (dump_backtrace+0x0/0x110) from [<c0501498>] (dump_stack+0x18/0x1c)
[ 5.651546] r6:00008000 r5:dfedc000 r4:c06f5b6c r3:00000002
[ 5.657161] [<c0501480>] (dump_stack+0x0/0x1c) from [<c0501514>] (panic+0x78/0xf8)
[ 5.664720] [<c050149c>] (panic+0x0/0xf8) from [<c0008f6c>] (mount_block_root+0x25c/0x2ac)
[ 5.672949] r3:00000002 r2:00000001 r1:dfc37f60 r0:c06464fa
[ 5.678564] [<c0008d10>] (mount_block_root+0x0/0x2ac) from [<c0009010>] (mount_root+0x54/0x68)
[ 5.687163] [<c0008fbc>] (mount_root+0x0/0x68) from [<c0009188>] (prepare_namespace+0x164/0x1bc)
[ 5.695912] r5:c00290cd r4:c0731740
[ 5.699448] [<c0009024>] (prepare_namespace+0x0/0x1bc) from [<c00084fc>] (kernel_init+0x128/0x170)
[ 5.708388] r5:c00083d4 r4:c0731500
[ 5.711931] [<c00083d4>] (kernel_init+0x0/0x170) from [<c0058894>] (do_exit+0x0/0x5f0)
[ 5.719826] r4:00000000 r3:00000000
[ 5.723365] Rebooting in 5 seconds..
[ 10.763051] Restarting Linux version 2.6.35.7+ (fly@fly-vm) (gcc version 4.4.1 (Sourcery G++ Lite 2009q3-67) ) #1 PREEMPT Mon Aug 9 08:31:45 CST 2021
[ 10.763062]
[ 10.778218] arch_reset: attempting watchdog reOK
Busybox Settings--->
Build Options--->
[*]Build BusyBox as a static binary(no shared libs)
Busybox Library Tuning--->
[*]vi-style line editing commands
[*]Fancy shell prompts
Linux Module Utilities--->
[ ]Simplified modutils
[*]insmod
[*]rmmod
[*]lsmod
[*]modprobe
[*]depmod
Linux System Utilities--->[*]mdev
[*]Support /etc/mdev.conf
[*]Support subdirs/symlinks
[*]Support regular expressions substitutions when renaming dev
[*]Support command execution at device addition/removal
[*]Support loading of firmwares
最终梳理发现是内核没有配置支持nfs挂载
1、配置网络部分,主要是使能CONFIG_IP_PNP以在2中能够看到Root file system on NFS选项
Networking support
Networking options
TCP/IP networking
IP: kernel level autoconfiguration
[*] IP: DHCP support
[*] IP: BOOTP support
2、配置开启nfs服务
File systems --->
Network File Systems --->
<*> NFS client support
[*] NFS client support for NFS version 3
[*] NFS client support for the NFSv3 ACL protocol extension
[*] NFS client support for NFS version 4 (EXPERIMENTAL)
[*] NFS client support for NFSv4.1 (DEVELOPER ONLY)
[*] Root file system on NFS
3、在uboot中设置如下启动参数(IP根据实际使用更改)
setenv bootargs root=/dev/nfs nfsroot=192.168.1.141:/root/porting_x210/rootfs ip=192.168.1.10:192.168.1.141:192.168.1.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC2,115200
发现使用make menuconfig配置后,
调用mk脚本编译内核时,覆盖掉了配置的.config文件,导致编译的内核没有支持nfs挂载
重新配置,保证是自己配置的.config文件,重新编译,下载内核后可以成功挂载nfs文件系统
如何使用busybox编译和生成最简linux根文件系统(rootfs) https://blog.csdn.net/LEON1741/article/details/54848842
uboot和系统移植课程中讲了制作文件夹格式的rootfs,然后通过设置bootargs让内核启动后直接通过nfs去挂载ubuntu中文件夹形式的rootfs。做这个实验出错,可能的原因有以下几个,大家要仔细检查分析,看你的问题出在哪里(如果你最后解决了发现你的问题是其他的,欢迎联系朱老师提供信息,以便帮助其他同学查找问题)。
(1)首先要确保你的开发板和ubuntu是通的。办法是在开发板中先进入uboot命令行,设置合理的IP地址后,从uboot端能ping通虚拟机ubuntu。其次还要确保ubuntu的nfs服务器搭建是ok的,并且有本地测试过可以成功挂载,测试方法在搭建nfs服务器的文档中有讲的。最后,如果还是害怕这里远端挂载有问题,可以先给开发板完整刷机,在开发板端启动linux挂载烧录的rootfs,启动进入linux命令行,再用mount -t nfs去挂载虚拟机ubuntu中的文件夹形式rootfs,确保能挂载。这时候肯定就排除了虚拟机不通或者nfs server不对的情况了。
(2)开发板端运行的kernel zImage必须使能了nfs格式的rootfs选项,这个是在make menuconfig中去配置使能的,我们在课程中专门讲过这个,而且课件里还提供了使能配置的路径。仔细看课程,跟着课程配置使能即可。
(3)我们讲课时用的ubuntu14.04,现在很多同学是用更新版本的ubuntu。这里可能会有一个问题,就是ubuntu16.04(也可能是17.04)后默认支持的nfs版本号更新了,和我们开发板使用的内核中的nfs版本号对不上,会导致挂载失败。如果你用的是新版本ubuntu,参考这篇文章来解决即可: https://blog.csdn.net/sean_8180/article/details/81112520 https://blog.csdn.net/sean_8180/article/details/81112520
(4)bootargs中ip=xxx这一段里的网卡名称应该设置为eth0,而不是ubuntu里的ens33这类名称。网上有些解读说这里是主机的网卡名,但是实际测试发现还是写成开发板端侧的网卡名eth0才可以成功dhcp分配到IP,才能nfs挂载成功,设置成ens33反而不行。