1、進行NFS服務器端與客戶端的安裝:
sudo apt-get install nfs-kernel-server
安裝客戶端的作用是可以在本機進行NFS服務的測試。
2、配置portmap
兩種方法任選一種就可以:
(1):sudo gedit /etc/default/portmap
註釋掉 -i 127.0.0.1
(2)sudo dpkg-reconfigure portmap
運行後選擇“否”
3、配置掛載目錄和權限
#sudo gedit /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) hostname2(ro,sync)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt)
# /srv/nfs4/homes gss/krb5i(rw,sync)
#
/home/nfsboot 192.168.1.*(rw,sync,no_root_squash)
解釋一下:
#後面的都是解釋
/home/nfsboot是NFS的共享目錄,*表示任何IP都可以共享這個目錄,你可以改爲受限的IP,rw表示的是權限,sync是默認的。
4、更新exports文件
只要你更改了/etc/exports, 你不可以通過sudo exportfs -r 來更新 這個文件
5、重啓NFS服務
sudo /etc/init.d/nfs-kernel-server restart 重啓nfs服務
6、進行測試
嘗試一下掛載本地磁盤(我的linux系統IP爲218.196.249.253,將/home/lxy/nfsboot掛載到/mnt)
$ sudo mount 218.196.249.253:/home/lxy/nfsboot /mnt
運行 $ df 看看結果
$ sudo umount /mnt
7、嵌入式系統中使用NFS服務掛載(來自網上)
嵌入式要mount 的時候 使用
mount -t nfs -o nolock 218.196.249.253:/home/lxy/nfsboot /mnt
Networking options --->選項中
啓用 TCP/IP networking
啓用IP: kernel level autoconfiguration
General setup ---> 選項中 ,
Default kernel command string: (默認的內核命令行)
加入綠色字中的字符
root=/dev/nfs rw nfsroot=192.168.1.99:/armnfs/ ip=192.168.1.201 init=/linuxrc console=ttySAC0
File system ---> Network File System --->選項
啓用 NFS file system support
啓用 Provide NFSv3 client support
啓用 Root file system on NFS