一、问题描述。
嵌入式linux开发,使用nfs挂载根文件系统时,内核无挂载文件系统,报错如下:
VFS: Unable to mount root fs via NFS, trying floppy.
VFS: Cannot open root device "nfs" or unknown-block(2,0): error -6
Please append a correct "root=" boot option; here are the available partitions:
1f00 2048 mtdblock0 (driver?)
1f01 20480 mtdblock1 (driver?)
1f02 239616 mtdblock2 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
CPU: 0 PID: 1 Comm: swapper Not tainted 3.10.101 #233
Backtrace:
[<c0011f24>] (dump_backtrace+0x0/0x10c) from [<c0012138>] (show_stack+0x18/0x1c)
r6:c05b3d68 r5:00008000 r4:c051a658 r3:00000000
[<c0012120>] (show_stack+0x0/0x1c) from [<c0467ce4>] (dump_stack+0x20/0x28)
[<c0467cc4>] (dump_stack+0x0/0x28) from [<c04658d0>] (panic+0xa4/0x1f8)
[<c046582c>] (panic+0x0/0x1f8) from [<c0595054>] (mount_block_root+0x1c4/0x270)
r3:00000001 r2:00000000 r1:c3843ea0 r0:c051a658
r7:c051a6c0
[<c0594e90>] (mount_block_root+0x0/0x270) from [<c05952e8>] (mount_root+0xec/0x114)
[<c05951fc>] (mount_root+0x0/0x114) from [<c0595470>] (prepare_namespace+0x160/0x1c0)
r8:c05b3d40 r7:c0623dc0 r6:c05b3d68 r5:c05b3d68 r4:c0623e20
[<c0595310>] (prepare_namespace+0x0/0x1c0) from [<c0594c48>] (kernel_init_freeable+0x1d8/0x220)
r6:c0623dc0 r5:00000007 r4:c05d960c
[<c0594a70>] (kernel_init_freeable+0x0/0x220) from [<c04651ac>] (kernel_init+0x10/0x158)
[<c046519c>] (kernel_init+0x0/0x158) from [<c000ecf8>] (ret_from_fork+0x14/0x3c)
r5:c046519c r4:00000000
二、问题分析。
nfs版本问题,我使用的linux系统版本是ubuntu18.04.5,。使用nfsstat命令查看nfs状态信息,确认host端nfs支持的版本。
ms@ubuntu:~$ nfsstat -v
Server packet stats:
packets udp tcp tcpconn
234 209 25 2
Server rpc stats:
calls badcalls badfmt badauth badclnt
25 209 209 0 0
Server reply cache:
hits misses nocache
0 0 25
Server io stats:
read write
0 0
Server read ahead cache:
size 0-10% 10-20% 20-30% 30-40% 40-50% 50-60% 60-70% 70-80% 80-90% 90-100% notfound
0 0 0 0 0 0 0 0 0 0 0 0
Server file handle cache:
lookup anon ncachedir ncachenondir stale
0 0 0 0 0
Server nfs v3:
null getattr setattr lookup access
2 8% 12 48% 0 0% 0 0% 2 8%
readlink read write create mkdir
1 4% 0 0% 0 0% 0 0% 0 0%
symlink mknod remove rmdir rename
0 0% 0 0% 0 0% 0 0% 0 0%
link readdir readdirplus fsstat fsinfo
0 0% 0 0% 2 8% 0 0% 4 16%
pathconf commit
2 8% 0 0%
ms@ubuntu:~$
三、解决方案。
修改内核配置,在bootargs中指定nfs版本,加上v3。
CONFIG_CMDLINE="noinitrd root=/dev/nfs nfsroot=198.168.1.18:/mnt/nfs/rootfs,v3,nolock rw ip=198.168.1.25:198.168.1.18:198.168.1.1:255.255.255.0::eth0:off init=/linuxrc console=ttyS0,115200n8 mem=64M"
成功启动,如下:
VFS: Mounted root (nfs filesystem) on device 0:11.
devtmpfs: mounted
Freeing unused kernel memory: 276K (c0594000 - c05d9000)
BusyBox v1.22.1 (2016-02-03 14:11:04 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.
~ #