嵌入式LINUX的NFS配置

來源:互聯網
上載者:User

fedora 17 安裝配置nfs :

http://www.server-world.info/en/note?os=Fedora_17&p=nfs

原文:

http://cabbage812.blog.163.com/blog/static/922814382009287020395/

網路檔案系統(NFS,Network File System)是一種將遠程主機上的分區(目錄)經網路掛載到本地系統的一種機制,通過對網路檔案系統的支援,使用者可以在本地系統上像操作本地分區一樣來對遠程主機的共用分區(目錄)進行操作。

  在嵌入式Linux 的開發過程中,開發人員需要在Linux伺服器上進行所有的軟體開發,交叉編譯後,通用FTP方式將可執行檔下載到嵌入式系統運行,但這種方式不但效率低下,且無法實現線上的調試。因此,可以通過建立NFS,把Linux伺服器上的特定分區共用到待調試的嵌入式目標系統上,就可以直接在嵌入式目標系統上操作Linux伺服器,同時可以線上對程式進行調試和修改,大大的方便了軟體的開發。因此,NFS 的是嵌入式Linux開發的一個重要的組成部分,本部分內容將詳細說明如何配置嵌入式Linux
的NFS 開發環境。

  嵌入式Linux 的NFS 開發環境的實現包括兩個方面:一是Linux 伺服器端的NFS 伺服器支援;二是嵌入式目標系統的NFS 用戶端的支援。因此,NFS 開發環境的建立需要配置linux 伺服器端和嵌入式目標系統端。

  一、Linux 伺服器端NFS 伺服器的配置

  以root 身份登陸Linux 伺服器,編輯/etc 目錄下的共用目錄設定檔exports,指定共用目錄及許可權等。

  執行如下命令編輯檔案/etc/exports:

  # vi /etc/exports

  在該檔案裡添加如下內容:

  /home/work 192.168.0.*(rw,sync,no_root_squash)        (逗號後面不要加空格)

  然後儲存退出。

  添加的內容表示:允許ip 位址範圍在192.168.0.*的電腦以讀寫的許可權來訪問/home/work 目錄。

  /home/work 也稱為伺服器輸出共用目錄。

  括弧內的參數意義描述如下:

  rw:讀/寫入權限,唯讀許可權的參數為ro;

  sync:資料同步寫入記憶體和硬碟,也可以使用async,此時資料會先暫存於記憶體中,而不立即寫入硬碟。

  no_root_squash:NFS 伺服器共用目錄使用者的屬性,如果使用者是 root,那麼對於這個共用目錄來說就具有 root 的許可權。

  接著執行如下命令,啟動連接埠映射:

  # /etc/rc.d/init.d/portmap start          

  最後執行如下命令啟動NFS 服務,此時NFS 會啟用守護進程,然後就開始監聽 Client 端的請求:

  # /etc/rc.d/init.d/nfs start                   
(F17 使用 #systemctl start nfs-server.service)

  使用者也可以重新啟動Linux 伺服器,自動啟動NFS 服務。

  在NFS 伺服器啟動後,還需要檢查Linux伺服器的防火牆等設定(一般需要關閉防火牆服務),確保沒有屏蔽掉NFS 使用的連接埠和允許通訊的主機,主要是檢查Linux伺服器iptables,ipchains 等選項的設定,以及/etc/hosts.deny,/etc/hosts.allow 檔案。

  我們首先在Linux 伺服器上進行NFS 伺服器的迴環測試,驗證共用目錄是否能夠被訪問。在Linux 伺服器上運行如下命令:

  # mount  -t  nfs 192.168.0.20:/home/work /mnt

  # ls /mnt

  命令將Linux 伺服器的NFS 輸出共用目錄掛載到/mnt 目錄下,因此,如果NFS 正常工作,應該能夠在/mnt 目錄看到/home/work 共用目錄中的內容。

二、嵌入式目標系統NFS 用戶端的配置

  在Linux 伺服器設定好後,還需要對用戶端進行相關配置。在配置核心時選擇Load an Alternate Configuration File輸入設定檔的路徑和檔案名稱添加核心對NFS的支援:

  選中networking options-》IP:kernel level auloconfiguralion項

  選中file systems-》network file systems-》下的root file system on nfs

  和nfs file system support重新編譯核心下載bootloader和kernel到開發板上

  在嵌入式目標系統的Linux Shell 下,執行如下命令來進行NFS 共用目錄掛載:

  # mkdir /mnt/nfs //建立Linux 伺服器輸出共用目錄的掛載點;

  # mount –t nfs 192.168.0.20:/home/work /mnt/nfs –o nolock

  # cd /mnt/nfs

  # ls

  此時,嵌入式目標系統端所顯示的內容即為Linux 伺服器的輸出目錄的內容,即Linux 伺服器的輸出目。

  錄/home/work 通過NFS 映射到了嵌入式目標系統的/mnt/nfs目錄。使用者可以用增/刪/修改檔案的方式來驗證實際效果。mount 命令中的192.168.0.20 為Linux 伺服器的IP地址,/home/work 為Linux 伺服器端所配置的共用輸出目錄,/mnt/nfs 為嵌入式裝置上的本地目錄。

  在開發過程中,來回輸入命令非常煩人,我寫了兩個簡單的指令碼來完成nfs的啟動,掛載。

  host啟動nfs:
  snfs
  #!/bin/bash
  ifconfig eth0 192.168.0.20
  /etc/rc.d/init.d/portmap start
  /etc/rc.d/init.d/nfs start
  嵌入式目標機掛載nfs:
  mnfs:

  #!/bin/sh

  mount -t nfs 192.168.0.20:/home/work/nfs /mnt/nfs -o nolock

=================================================分割線=====================================================

我PC上出現的問題

# systemctl status nfs-server.service
nfs-server.service - NFS Server
      Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled)
      Active: failed (Result: exit-code) since Thu, 14 Mar 2013 10:07:58 +0800; 6s ago
     Process: 2677 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)
     Process: 2674 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)
     Process: 2655 ExecStartPost=/usr/lib/nfs-utils/scripts/nfs-server.postconfig (code=exited, status=0/SUCCESS)
     Process: 2642 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS $RPCNFSDCOUNT (code=exited, status=0/SUCCESS)
     Process: 2683 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=22)
     Process: 2680 ExecStartPre=/usr/lib/nfs-utils/scripts/nfs-server.preconfig (code=exited, status=0/SUCCESS)
      CGroup: name=systemd:/system/nfs-server.service

Mar 14 10:07:58 huntinux exportfs[2683]: exportfs: /etc/exports:2: syntax error: bad ...st


這裡查看nfs的運行狀態,但是說/etc/exports 有錯誤,原因是 (rw, sync, no_root_squash) 中的 ',' 後面我加入了空格,把空格去掉就可以了。即成(rw,sync,no_root_squash)

相似問題文章:http://forums.fedoraforum.org/showthread.php?t=287427

===================================================================

在開發板上掛在NFS時候遇到的問題:

1)#mount -t nfs 192.168.1.131:/nfs/busybox/mini_fs /nfs/fs

錯誤提示為: mount: RPC: Unable to receive; errno = No route to host

解決辦法    : #systemctl stop iptables.service                     (臨時關閉防火牆)

                     永久關閉防火牆: #systemctl disable iptables.service

2)關閉防火牆之後再次運行#mount
-t nfs 192.168.1.131:/nfs/busybox/mini_fs  /nfs/fs

錯誤提示:rpcbind: server localhost not responding, timed out

                    按下ctrl+z後退出

解決辦法: #mount -t nfs-o nolock 192.168.1.131:/nfs/busybox/mini_fs /nfs/fs
關於-o nolock 的一些資料 :http://wb127.blog.51cto.com/2232662/401732


3) 讓開發板開機自動掛在NFS檔案系統

http://www.cnblogs.com/cornflower/archive/2010/03/27/1698279.html

=============================記得關閉防火牆======================================

systemctl stop iptables.servicesystemctl disable iptables.service

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.