Ubuntu22.04虚拟机通过NFS连接开发板

目录

    • 1. 首先在虚拟机上安装NFS:
    • 2. 在虚拟机上新建文件夹,配置nfs,使得开发板可以通过网络来访问nfs文件夹:
    • 3. 重启NFS服务
    • 在开启系统之后出现如下错误:
    • 解决办法:

在学习驱动开发是,为了方便编译,通过NFS将Linux的跟文件目录挂载到开发板的系统上。

1. 首先在虚拟机上安装NFS:

sudo apt-get install nfs-kernel-server rpcbind

2. 在虚拟机上新建文件夹,配置nfs,使得开发板可以通过网络来访问nfs文件夹:

sudo vi /etc/exports

打开/etc/exports 后,在文件最后添加以下内容:

/home/zuozhongkai/linux/nfs *(rw,sync,no_root_squash)

3. 重启NFS服务

sudo /etc/init.d/nfs-kernel-server restart

在构建好根文件系统之后,通过设置环境变量将根文件系统挂载到开发板上:

setenv bootargs 'console=ttymxc0,115200 root=/dev/nfs nfsroot=192.168.1.250:/home/zuozhongkai/linux/nfs/rootfs,proto=tcp rw ip=192.168.1.251:192.168.1.250:192.168.1.1:255.255.255.0::eth0:off' //设置 bootargs
saveenv //保存环境变量

在开启系统之后出现如下错误:

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:
0100           65536 ram0  (driver?)
0101           65536 ram1  (driver?)
0102           65536 ram2  (driver?)
0103           65536 ram3  (driver?)
0104           65536 ram4  (driver?)
0105           65536 ram5  (driver?)
0106           65536 ram6  (driver?)
0107           65536 ram7  (driver?)
0108           65536 ram8  (driver?)
0109           65536 ram9  (driver?)
010a           65536 ram10  (driver?)
010b           65536 ram11  (driver?)
010c           65536 ram12  (driver?)
010d           65536 ram13  (driver?)
010e           65536 ram14  (driver?)
010f           65536 ram15  (driver?)
b300         1943552 mmcblk0  driver: mmcblk
  b301         1942528 mmcblk0p1 70682931-01
b310         7634944 mmcblk1  driver: mmcblk
  b311          131072 mmcblk1p1 40bcc898-01
  b312         7493632 mmcblk1p2 40bcc898-02
b340             512 mmcblk1rpmb  (driver?)
b330            4096 mmcblk1boot1  (driver?)
b320            4096 mmcblk1boot0  (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)

在分析之后发现,是开发板安装的NFS服务版本过低,Ubuntu22.04下载的NFS版本高,默认情况下不支持较低版本NFS挂载服务,需要我们手动对配置进行修改。
首先查看虚拟机支持的NFS版本,在终端输入指令

sudo cat /proc/fs/nfsd/versions

发现为

“-2"表示系统不支持V2版本的NFS,”+3"表示支持V3版本的NFS。

解决办法:

在终端中输入vim /etc/default/nfs-kernel-server,在nfs-kernel-server文件中添加以下内容

RPCNFSDCOUNT="-V 2 8";
RPCMOUNTDOPTS="-V 2 --manage-gids";
RPCSNFSDOPTS="--nfs-version 2,3,4 --debug --syslog";

更改后保存文件

# Number of servers to start up
RPCNFSDCOUNT="-V 2 8"

# Runtime priority of server (see nice(1))
RPCNFSDPRIORITY=0

# Options for rpc.mountd.
# If you have a port-based firewall, you might want to set up
# a fixed port here using the --port option. For more information, 
# see rpc.mountd(8) or http://wiki.debian.org/SecuringNFS
# To disable NFSv4 on the server, specify '--no-nfs-version 4' here
RPCMOUNTDOPTS="-V 2 --manage-gids"

# Do you want to start the svcgssd daemon? It is only required for Kerberos
# exports. Valid alternatives are "yes" and "no"; the default is "no".
NEED_SVCGSSD=""

# Options for rpc.svcgssd.
RPCSVCGSSDOPTS=""
RPCSNFSDOPTS="--nfs-version 2,3,4 --debug --syslog"

再在终端中输入sudo vim /etc/nfs.conf,将文件中的udp和ver2打开

[nfsd]
# debug=0
# threads=8
# host=
# port=0
# grace-time=90
# lease-time=90
udp=y
# tcp=y
vers2=y
# vers3=y
# vers4=y
# vers4.0=y
# vers4.1=y
# vers4.2=y
# rdma=n
# rdma-port=20049

设置好后,重启nfs服务,发现开发板可以将nfs文件中的根目录挂载到开发板上

can-3v3: disabling
ALSA device list:
  No soundcards found.
VFS: Mounted root (nfs filesystem) readonly on device 0:15.
devtmpfs: mounted
Freeing unused kernel memory: 404K (8090f000 - 80974000)

你可能感兴趣的:(驱动开发,驱动开发)