文章目錄
- 前言
- 一、NFS介紹
- 二、NFS服務安裝配置過程
-
- 2.1 開發闆端安裝配置NFS服務
- 2.2 PC端安裝配置NFS服務
- 2.3 測試開發闆和PC端是否可以通過NFS檔案夾共享檔案
- 總結
前言
實驗室所用的Firefly AIO-3399ProC開發闆在搭建交叉編譯環境前,需要在開發闆端和PC端部署NFS遠端挂載環境,本文記錄下搭建過程,以供本人和各位參考。
一、NFS介紹
網絡檔案系統,英文為Network File System(NFS),是由SUN公司研制的UNIX表示層協定(presentation layer protocol),能使使用者通路網絡上别處的檔案就像在使用自己的計算機一樣。
NFS 允許計算的客戶-伺服器模型。伺服器實施共享檔案系統,以及用戶端所連接配接的存儲。用戶端實施使用者接口來共享檔案系統,并加載到本地檔案空間當中。
通過在開發闆和PC端部署NFS遠端挂載環境,可以很友善地在兩者間傳輸檔案。
二、NFS服務安裝配置過程
注:部分操作配置參考此文
2.1 開發闆端安裝配置NFS服務
- 安裝NFS相關元件
sudo apt-get install nfs-kernel-server -y
- 在開發闆中建立并配置NFS共享檔案夾
#建立共享檔案夾
sudo mkdir /mnt/nfs
#修改檔案夾的使用者通路權限
sudo chown -R firefly /mnt/nfs/
#檢視修改後的NFS檔案夾權限
ll /mnt/nfs/
total 3
drwxr-xr-x 3 root root 1024 May 12 2020 ./
drwxr-xr-x 22 root root 1024 Mar 12 13:13 ../
drwxr-xr-x 20 firefly firefly 1024 Mar 15 10:22 firefly/
-
設定共享檔案夾的通路權限
修改主機 /etc/exports 檔案,在該檔案中添加如下代碼
/mnt/nfs *(rw,sync,no_root_squash)
該行代碼的說明如下:
/mnt/nfs 表示所設定的共享檔案,這裡可以任意改,
*表示任意網段的下位機都可以連接配接到此檔案夾
(rw,sync,no_root_squash) //表示一些權限
rw 可讀寫的權限
ro 隻讀的權限
no_root_squash NFS 用戶端分享目錄使用者的權限,即如果用戶端使用的是 root 使用者,那麼對于這個共享的目錄而言,該用戶端就具有 root 的權限,若是以NFS挂載根檔案系統時,必須設定此項
sync 資料同步寫入到記憶體與硬碟當中
async 資料會先暫存于記憶體當中,而非直接寫入硬碟
sudo vim /etc/exports
# /etc/exports: the access control list for filesystems which may
be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(
ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_c
heck)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
/mnt/nfs *(rw,sync,no_root_squash)
- 重新開機NFS相關服務
#停止NFS服務
sudo /etc/init.d/nfs-kernel-server stop
# 啟動NFS服務
sudo /etc/init.d/nfs-kernel-server start
# 重新啟動NFS服務
sudo /etc/init.d/nfs-kernel-server restart
- 檢視系統中建立的共享檔案夾
[email protected]:~$ showmount -e
Export list for firefly:
/mnt/nfs *
- 檢視開發闆的網絡配置
ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.126 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::ecfd:ead1:e1:e900 prefixlen 64 scopeid 0x20<link>
ether 7a:10:c5:77:34:a8 txqueuelen 1000 (Ethernet)
RX packets 165358 bytes 15182215 (15.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 721900 bytes 1018945203 (1.0 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 24
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 235 bytes 17298 (17.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 235 bytes 17298 (17.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether cc:4b:73:8a:85:ff txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
可看到此時開發闆的固定IP位址為192.168.1.126。
至此開發闆端的NFS配置完成
2.2 PC端安裝配置NFS服務
- 安裝NFS服務
sudo apt-get install nfs-common -y
- 建立NFS共享檔案夾
sudo mkdir /mnt/nfs
#修改檔案夾的使用者通路權限
sudo chown -R user /mnt/nfs
#檢視修改後的NFS檔案夾權限
ll /mnt/nfs/
總用量 13
drwxr-xr-x 4 root root 4096 3月 15 10:25 ./
drwxr-xr-x 25 root root 4096 3月 5 14:01 ../
drwxr-xr-x 2 root root 4096 11月 28 19:55 hgfs/
drwxr-xr-x 2 user root 1024 3月 15 10:19 nfs/
- 測試PC端與開發闆網絡是否相通
#在PC端ping開發闆的IP位址
ping 192.168.1.126
PING 192.168.1.126 (192.168.1.126) 56(84) bytes of data.
64 bytes from 192.168.1.126: icmp_seq=1 ttl=64 time=0.674 ms
64 bytes from 192.168.1.126: icmp_seq=2 ttl=64 time=0.626 ms
64 bytes from 192.168.1.126: icmp_seq=3 ttl=64 time=0.703 ms
64 bytes from 192.168.1.126: icmp_seq=4 ttl=64 time=0.665 ms
- 在PC端挂載開發闆的NFS共享檔案夾
sudo mount -t nfs -o nolock 192.168.1.126:/mnt/nfs /mnt/nfs
-
設定開機自動挂載開發闆共享的NFS檔案夾
修改/etc/檔案夾下的fstab檔案,按實際IP位址及檔案夾目錄添加
nfs-server-ip:/nfsdir /mnt nfs rw 0 0
sudo vim /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda1 during installation
UUID=92a17988-3b1d-4bd0-8d30-bf0a8ac93146 / ext4 errors=remount-ro 0 1
/swapfile none swap sw 0 0
192.168.1.126:/mnt/nfs /mnt/nfs nfs rw 0 0
2.3 測試開發闆和PC端是否可以通過NFS檔案夾共享檔案
#開發闆端
cp /home/firefly/work_3399.zip /mnt/nfs/
#PC端
ls /mnt/nfs
work_3399.zip
#PC端
mv /mnt/nfs/work_3399.zip ./work.zip
#開發闆端
ls /mnt/nfs
work.zip

NFS支援TCP和UDP協定
通過上列代碼測試檔案傳輸及重命名,可知PC端和開發闆端可進行檔案傳輸,至此NFS遠端挂載環境搭建完成。
總結
本文總結了ARM開發闆和PC端搭建遠端挂載環境的過程,友善後續搭建交叉編譯環境。