從nfs的原理來看須要的套件有3個,一個是nfs核心,一個是rpc,另一個就是portmap 。
對ubuntu而言,這三個套件包含在兩個套件當中,一個是nfs核心,名爲nfs-kernel-server,另一個套件是rpcbind,它不只包括RPC還包括portmap套件。
安裝:rpcbindubuntu
$sudo apt-get install rpcbind
安裝nfs-kernel-server服務器
$sudo apt-get install nfs-kernel-server
在服務器端Linux主機中檢查NFS服務狀態:async
# service nfs-kernel-server status nfsd running
開始建立NFS的共享文件夾,並修改/etc/exports 文件(有的系統安裝rpcbind和nfs-kernel-server以後會自動生成/etc/exports 文件,有的不會):測試
# mkdir /nfsfile # echo "/nfsfile 192.168.1.141(rw,sync,no_root_squash)" > /etc/exports # cat /etc/exports /nfsfile 192.168.1.134(rw,sync,no_root_squash)
這裏咱們建立了/nfsfile目錄用於NFS共享,並在/etc/exports文件中將共享屬性IP設置爲192.168.1.141(開發板上的IP,在/dev/eth0-setting裏面能夠修改IP,修改後重啓便可)的用戶可讀寫,而且由no_root_aquash指定信任客戶端,這樣咱們能夠以root權限在開發板上對/nfsfile目錄進行可讀寫操做。rw權限是可擦寫,還有ro只讀,sync表明數據會同步寫入到內存與硬盤中,async則表明數據會先暫存於內存當中,而非直接寫入硬盤,開放客戶端使用root身份來操做服務器的文件系統,那麼開no_root_squash才行,root_squash不容許。(更多配置文件的權限參數和IP(主機名)配置方式請參考鳥哥的私房菜-----Linux服務器架設篇 P400頁)。this
服務器啓動NFS服務兩種方法:
第一種:spa
# service nfs-kernel-server restart/start * Stopping NFS kernel daemon [ OK ] * Unexporting directories for NFS kernel daemon... [ OK ] * Exporting directories for NFS kernel daemon... exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "192.168.1.141:/nfsroot/". Assuming default behaviour ('no_subtree_check'). NOTE: this default has changed since nfs-utils version 1.0.x [ OK ] * Starting NFS kernel daemon [ OK ]
第二種:rest
# service nfs-kernel-server status nfsd running root@ubuntu:/home/ice# sudo /etc/init.d/portmap restart Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service portmap restart Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the stop(8) and then start(8) utilities, e.g. stop portmap ; start portmap. The restart(8) utility is also available. portmap stop/waiting portmap start/running, process 31525 # sudo /etc/init.d/nfs-kernel-server restart * Stopping NFS kernel daemon [ OK ] * Unexporting directories for NFS kernel daemon... [ OK ] * Exporting directories for NFS kernel daemon... exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "192.168.1.141:/nfsroot/". Assuming default behaviour ('no_subtree_check'). NOTE: this default has changed since nfs-utils version 1.0.x [ OK ] * Starting NFS kernel daemon [ OK ]
接下來在服務器上mount來測試:code
# touch /nfsfile/test //test 爲測試文件 # ls /mfsfile test # mount 192.168.1.140:/nfsfile /mnt/ # ls /mnt test
mount時的ip地址192.168.1.140就是Linux主機的IP地址。開發板的IP地址是192.168.1.141,和服務器在同一網段,連上網線以後它們就能夠互相ping通了。server
接着可直接在服務器上經過telnet的方式鏈接到開發板,並進行Mount操做。注意:telnet時須要開發板的賬號、密碼。賬號默認是root,密碼能夠在開發板上經過passwd命令修改。
telnet登陸以後就能夠掛載了:ip
# mount 192.168.1.140:/nfsfile /mnt # ls /mnt test
這時候可能會出現錯誤:
mount: mounting 192.168.1.140:/nfsfile on /mnt failed: Connection refused
這時掛載命令改成:
mount -t nfs -o nolock 192.168.1.140:/nfsfile /mnt
其餘問題:
1.出現問題:
reason given by server: Permission denied
解決:
服務器端啓動必定要sudo啓動,否則啓動失敗,服務拒絕
2.出現問題:
mount: mounting 192.168.1.140:/nfsroot on /mnt failed: Device or resource busy
解決:
mount上以後在進行mount命令會出現此提示,設備正在運行,不用再次mount
若是想再次mount能夠先umount /mnt/