六、NFS服務器的配置
1、安裝NFS客戶端和服務器
Ubuntu上默認是沒有安裝Ubuntu nfs服務器的,因此我們首先安裝Ubuntu nfs服務器端:$sudo apt-get install nfs-kernel-server
在安裝nfs-kernel-server時,apt會自動爲我們安裝好nfs的客戶端nfs-common,以及端口映射器portmap。
2、配置/etc/exports
在根目錄下新建nfs文件夾,並更改其權限777打開文件加入下面內容
clx@think:~$ sudo gedit /etc/exports
#作爲開發板的根文件系統通過nfs 掛接
/nfsboot/rootfs 192.168.1.* (rw,sync,no_root_squash) //*和(之間沒有空格,否則跟文件系統將是隻讀的,會有很多麻煩
/nfsboot/kernel 192.168.1.* (rw,sync,no_root_squash)
#存放引用程序
/nfsboot/nfs 192.168.1.* (rw,sync,no_root_squash)
第二個部分192.168.1..*是指在這個IP段內可以共享的目錄
第三個部分: 第一個參數,rw:可以擦寫的權限; ro:只讀的權限
第二個參數:sync:資料同步寫入到內存與硬盤當中,async:資料會暫時寫入到內存中去
第三個參數:no_root_aquash: 登入NFS主機使用分享目錄的使用者,如果是root的話,那麼對於這個分享的目錄來說,它就具有root的權限,這個項目很不安全。
很重要的一點,不要在最後一個客戶端聲明的後面留下任何空白或者沒關閉括號,因爲空白都被解釋成客戶端的分隔符。
3、啓動nfs服務
(1)、首先把上面修改過的配置文件重新導入clx@think:/etc$ sudo exportfs -rv
(2)、重新啓動portmap服務(端口映射)
#sudo /etc/init.d/portmap restart
(3)、重新啓動nfs服務:
clx@think:/$ 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.*:/nfs".
Assuming default behaviour ('no_subtree_check').
NOTE: this default has changed since nfs-utils version 1.0.x
[ OK ]
* Starting NFS kernel daemon [ OK ]
4、NFS測試
(1)、手動掛載使用mount命令來掛載其他機器共享的NFS目錄。
格式:$ sudo mount [Server IP]:/[share dir] [local mount point]
clx@think:~$ sudo mount -t nfs 192.168.1.100:/nfs /home/clx/rootnfs
沒有任何提示說明成功。
(2)、和開發板掛載測試
root@MINI2440:/# mount -o nolock -t nfs 192.168.1.100:/nfs /mnt
root@MINI2440:/mnt# ls
backlight_test
掛載成功。
七、通過NFS啓動linux
1、配置虛擬機IP
虛擬機必須設置靜態IP,並且虛擬機需設置爲橋接方式,虛擬機與宿主機與目標機爲同個網段。
這裏設置虛擬機IP:192.168.1.100,開發板IP已自動設置爲:192.168.1.250
2、配置mini2440開發板
在Supervivi模式下輸入如下命令(參考mini2440光盤根目錄下的nfs.txt文件)
Supervivi> param set linux_cmd_line "console=ttySAC0 root=/dev/nfs nfsroot=192.168.1.100:/nfsboot/rootfs ip=192.168.1.250:192.168.1.100:192.168.1.1:255.255.255.0:MINI2440.DreamCatcher:eth0:off"
其中 ,param set linux_cmd_line 是設置啓動 linux 時的命令參數。其各參數的含義
console: console=tty 使用虛擬串口終端設備 。console=ttyS[,options] 使用特定的串口,options可以是這樣的形式bbbb p n x,這裏bbbb是指串口的波特率,p是奇偶位(從來沒有看過使用過),n是指的bits。console=ttySAC[,options] 同上面。看你當前的環境,有時用ttyS,有時用ttySAC,網上有人說,這是跟內核的版本有關,2.4用ttyS,2.6用ttySAC,但實際情況是官方文檔中也是使用ttyS,所以應該是跟內核版本沒有關聯的。可以查看Documentation/serial-console.txt找到相關描述。
root: 用來指定rootfs的位置, 常見的情況有:
root=/dev/ram rw
root=/dev/ram0 rw
請注意上面的這兩種設置情況是通用的,我做過測試甚至root=/dev/ram1 rw和root=/dev/ram2 rw也是可以的,網上有人說在某些情況下是不通用的,即必須設置成ram或者ram0,但是目前還沒有遇到,還需要進一步確認,遇到不行的時候可以逐一嘗試。
root=/dev/mtdx rw
root=/dev/mtdblockx rw
root=/dev/mtdblock/x rw
root=31:0x
上面的這幾個在一定情況下是通用的,當然這要看你當前的系統是否支持,不過mtd是字符設備,而mtdblock是塊設備,有時候你得挨個的試到底當前的系統支持上面那種情況下,不過root=/dev/mtdblockx rw比較通用。此外,如果直接指定設備名可以的話,那麼使用此設備的設備號也是可以的。
root=/dev/nfs,並非真的設備,而是一個告訴內核經由網絡取得根文件系統的旗標。
在文件系統爲基於nfs的文件系統的時候使用。當然指定root=/dev/nfs之後,還需要指定nfsroot。
nfsroot:參數告訴內核以哪一臺機器,哪個目錄以及哪個網絡文件系統選項作爲根文件系統使用。
nfsroot 是自己開發主機的IP 地址。
“ip=”後面:
第一項(192.168.1.230)是目標板的臨時IP(注意不要和局域網內其他IP 衝突);
第二項(192.168.1.112)是開發主機的IP;
第三項(192.168.1.1)是目標板上網關(GW)的設置;
第四項(255.255.255.0)是子網掩碼;
第五項是開發主機的名字(一般無關緊要,可隨便填寫)
eth0 是網卡設備的名稱。
內核配置確保選中了[*] Root file system on NFS
從NandFlash啓動開發板,上電時同時按下開發板上任意一個按鍵,進入BIOS,在超級終端輸入 q [q] Goto shell of vivi,進入命令行
把之前寫好的命令粘貼進去,回車。
輸入boot,回車就從NFS啓動系統了。
要想每次啓動都通過NFS啓動系統,在輸入boot前,輸入menu,然後輸入s,再輸入w,輸入q,回到BIOS菜單。這樣以後每次就自動從NFS啓動了
Supervivi> param set linux_cmd_line "console=ttySAC0 root=/dev/nfs nfsroot=192.168.1.100:/nfsboot/rootfs ip=192.168.1.250:192.168.1.100:192.168.1.1:255.255.255.0:MINI2440.DreamCatcher:eth0:off"
Change linux command line to "console=ttySAC0 root=/dev/nfs nfsroot=192.168.1.100:/nfsboot/rootfs ip=192.168.1.250:192.168.1.100:192.168.1.1:255.255.255.0:MINI2440.DreamCatcher:eth0:off"
Supervivi> menu
##### FriendlyARM BIOS 2.0 for 2440 #####
[x] format NAND FLASH for Linux
[v] Download vivi
[k] Download linux kernel
[y] Download root_yaffs image
[a] Absolute User Application
[n] Download Nboot for WinCE
[l] Download WinCE boot-logo
[w] Download WinCE NK.bin
[d] Download & Run
[z] Download zImage into RAM
[g] Boot linux from RAM
[f] Format the nand flash
[b] Boot the system
[s] Set the boot parameters
[u] Backup NAND Flash to HOST through USB(upload)
[r] Restore NAND Flash from HOST through USB
[q] Goto shell of vivi
[i] Version: 1026-2K
Enter your selection: s
##### Parameter Menu #####
[r] Reset parameter table to default table
[s] Set parameter
[v] View the parameter table
[w] Write the parameter table to flash memeory
[q] Quit
Enter your selection: w
Found block size = 0x00020000
Erasing... ... done
Writing... ... done
Written 49152 bytes
Saved vivi private data
##### Parameter Menu #####
[r] Reset parameter table to default table
[s] Set parameter
[v] View the parameter table
[w] Write the parameter table to flash memeory
[q] Quit
Enter your selection: q
##### FriendlyARM BIOS 2.0 for 2440 #####
[x] format NAND FLASH for Linux
[v] Download vivi
[k] Download linux kernel
[y] Download root_yaffs image
[a] Absolute User Application
[n] Download Nboot for WinCE
[l] Download WinCE boot-logo
[w] Download WinCE NK.bin
[d] Download & Run
[z] Download zImage into RAM
[g] Boot linux from RAM
[f] Format the nand flash
[b] Boot the system
[s] Set the boot parameters
[u] Backup NAND Flash to HOST through USB(upload)
[r] Restore NAND Flash from HOST through USB
[q] Goto shell of vivi
[i] Version: 1026-2K
Enter your selection: b
........................................................................
eth0: link down
IP-Config: Complete:
device=eth0, addr=192.168.1.250, mask=255.255.255.0, gw=192.168.1.1,
host=MINI2440, domain=, nis-domain=DreamCatcher,
bootserver=192.168.1.100, rootserver=192.168.1.100, rootpath=
Looking up port of RPC 100003/2 on 192.168.1.100
eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
Looking up port of RPC 100005/1 on 192.168.1.100
VFS: Mounted root (nfs filesystem) on device 0:14.
Freeing init memory: 132K
Processing /etc/rc.local
get hostname
Starting mdev
ifconfig eth0 192.168.1.250
DeramCatcher
Date:2013.5.14
update the time from RTC
Mon Jan 9 12:42:10 UTC 2012
Please press Enter to activate this console.
Processing /etc/profile
set user path
set search library path
set PS1
root@MINI2440:/# ls
bin dev home linuxrc proc sbin tmp var
boot etc lib mnt root sys usr
至此用NFS掛載根文件系統啓動成功!