armlinux之旅挂载NFS根文件目录

8次阅读

共计 1058 个字符,预计需要花费 3 分钟才能阅读完成。

为了加快应用的开发速度,比较推荐的方式是在引导 kernel 之后通过网络挂载到主机设置的 nfs 文件夹中。减少了来回拷贝的麻烦

开发环境

  • 主机:ubuntu 16.04 x64
  • 开发板:NUC980 linux-4.4 内核

NFS 服务器配置

sudo apt install nfs-kernel-server    // 安装 NFS 服务器
sudo vim /etc/exports    // 配置 NFS 文件夹
exportfs -r    // 检查 NFS 配置
sudo /etc/init.d/nfs-kernel-server restart    // 重启服务器
sudo ufw disable    // 关闭防火墙 

NFS 文件夹配置


配置文件位置为 /etc/exports,写完后通过 exportfs - r 检查

/NFS_ROOT_NAME  (rw,sync,insecure,all_squash)

ro 该主机对该共享目录有只读权限
rw 该主机对该共享目录有读写权限
root_squash 客户机用 root 用户访问该共享文件夹时,将 root 用户映射成匿名用户
no_root_squash 客户机用 root 访问该共享文件夹时,不映射 root 用户
sync 资料同步写入到内存与硬盘中
async 资料会先暂存于内存中,而非直接写入硬盘
insecure 允许从这台机器过来的非授权访问

all_squash 客户机上的任何用户访问该共享目录时都映射成匿名用户
anonuid 将客户机上的用户映射成指定的本地用户 ID 的用户
anongid 将客户机上的用户映射成属于指定的本地用户组 ID

内核配置

在内核的 menuconfig 中,打开以下选项

  1. 打开网络相关选项

    Networking support  --->
        Networking options  --->
            [*] TCP/IP networking
            [*]   IP: kernel level autoconfiguration
            [*]     IP: DHCP support
            [*]     IP: BOOTP support
            [*]     IP: RARP support
  2. 打开 NFS 文件系统相关选项

    File systems  --->
        [*] Network File Systems  --->
            <*>   NFS client support
            <*>     NFS client support for NFS version 2
            <*>     NFS client support for NFS version 3
            [*]   Root file system on NFS
  3. 内核引导参数

    root=/dev/nfs
    nfsroot=s.s.s.s/path
    ip=localAddress:serverAddress:gateway:netmask
正文完
 0