【原创】-- nfs安装配置及使用,挂载根文件系统

环境:ubuntu14.04(非虚拟机),OK6410

环境搭建:

(1)

#sudo apt-get install nfs-kernel-server

如果已经是最新版本了,无需安装

(2)

建立nfs文件夹,在ubuntu命令行中输入,

$ mkdir /nfs

$ chmod 777 /nfs

$ chmod  777  /nfs/*

(3)

打开/etc/exports文件,在末尾加入:

/nfs *(rw,sync,no_root_squash)      

注:nfs允许挂载的目录及权限,在文件/etc/exports中进行定义,各字段含义如下:

/nfs:要共享的目录

* :允许所有的网段访问

rw :读写权限

sync:资料同步写入内在和硬盘

no_root_squash:nfs客户端共享目录使用者权限

(4)

重启服务:

#sudo /etc/init.d/nfs-kernel-server restart      <---重启nfs服务

#showmount -e                                    <---显示共享出的目录

注意:若重启nfs服务时出现如下错误

 * Stopping NFS kernel daemon                                            [ OK ] 

 * Unexporting directories for NFS kernel daemon...                      [ OK ] 

WARNING: /etc/modprobe.conf line 1: ignoring bad line starting with 'Cannot'

WARNING: Could not open 'kernel/net/sunrpc/sunrpc.ko': No such file or directory

WARNING: Could not open 'kernel/fs/lockd/lockd.ko': No such file or directory

WARNING: Could not open 'kernel/fs/nfs_common/nfs_acl.ko': No such file or directory

WARNING: Could not open 'kernel/net/sunrpc/auth_gss/auth_rpcgss.ko': No such file or directory

FATAL: Could not open 'kernel/fs/nfsd/nfsd.ko': No such file or directory

 * Not starting NFS kernel daemon: no support in current kernel.

采用如下语句改正错误:

 sudo ln -s /lib/modules/3.13.0-45-generic/kernel/ /

结果如下:

* Stopping NFS kernel daemon                                             [ OK ] 

 * Unexporting directories for NFS kernel daemon...                      [ OK ] 

WARNING: /etc/modprobe.conf line 1: ignoring bad line starting with 'Cannot'

 * Exporting directories for NFS kernel daemon...                          [ OK ] 

 * Starting NFS kernel daemon                                                    [ OK ]

nfs配置成功

本机测试

(1)本机测试

现在可以在本机上试一下:

#sudo mount -t nfs localhost:/home/kevin /mnt

注:localhost为本机linux的IP地址

这样就把共享目录挂到了/mnt目录,取消挂载用:

#sudo umount /mnt

挂在根文件系统

(1)

将制作好的文件系统放入 /nfs 中,文件系统的制作方法见http://www.cnblogs.com/apolloenterprise/p/4351408.html

(2)

kernel中要设置启动nfs

$ make menuconfig ARCH=arm

General Setup -  取消  Initial RAM filesystem and ...

File System   选中  Network FileSystem

选中  Root file System on NfS

$ make uImage ARCH=arm CROSS_COMPILE=arm-linux-

编译完成

(3)

启动参数设置

开发板上电,进入uboot命令行:

$ setenv bootargs " console=ttySAC0 root=/dev/nfs nfsroot=192.168.1.200:/nfs ip=192.168.1.100"

注意:192.168.1.200   PC IP

192.168.1.100  开发板IP

保存:

$ saveenv

(4)tftp 下载内核后,bootm启动内核,此时文件系统会被调用

原文地址:https://www.cnblogs.com/apolloenterprise/p/4342254.html