內核: linux-3.0linux
u-boot: 2010.09vim
開發板: fl2440(s3c2440主芯片)安全
交叉編譯器: 2011.11服務器
咱們在上面移植了initramfs文件系統,而且已經成功運行了。下面咱們開始移植nfs,以前開啓PC上的nfs服務功能app
確認並安裝NFS服務依賴軟件包dom
通常NFS服務器要提供服務,必須啓動inet,nfs, mount,portmap或rpcbind這些守護進程並保持在後臺狀態運行. 這裏須要提示的是從RHEL6開始, 系統使用rpcbind替換了之前早期版本中NFS依賴的portmap服務。async
在使用NFS共享文件以前,咱們首先使用rpm命令確認咱們安裝了這些應用程序。若是沒有安裝,則從安裝光盤中找到他們並安裝,或者使用yum安裝。下面顯示咱們在安裝系統時,已經選擇安裝了NFS服務相關軟件ide
1.學習
[weishusheng@localhost ~]$ rpm -qa | grep nfs
nfs4-acl-tools-0.3.3-6.el6.x86_64
nfs-utils-lib-1.1.5-4.el6.x86_64
nfs-utils-1.2.3-36.el6.x86_64測試
[weishusheng@localhost ~]$ rpm -qa | grep rpcbind
rpcbind-0.2.0-11.el6.x86_64
2.
修改主機上的NFS配置文件,導出/opt目錄使用NFS共享:
[weishusheng@localhost ~]$ sudo vim /etc/exports
/opt/ *(sync,no_root_squash,rw)
/home/lingyun/keyue *(rw,sync,no_root_squash)
/home/lingyun/yangzheng *(rw,sync,no_root_squash)
/home/lingyun/yangxu *(rw,sync,no_root_squash)
/home/lingyun/yanshifu *(rw,sync,no_root_squash)
/home/lingyun/huangyidong *(rw,sync,no_root_squash)
/home/lingyun/liuchengdeng/s3c2440/fs/nfs *(rw,sync,no_root_squash)
/home/zhouguangfeng/ *(rw,sync,no_root_squash)
/home/weishusheng/rootfs_tree/rootfs *(sync,no_root_squash,rw)
/home/zhanbiqiang/rootfs *(rw,sync,no_root_squash)
/home/lingyun/suosuo/rootfs *(rw,sync,no_root_squash)
下面是一些NFS共享的經常使用參數:
ro 只讀訪問
rw 讀寫訪問
sync 全部數據在請求時寫入共享
async NFS在寫入數據前能夠相應請求
secure NFS經過1024如下的安全TCP/IP端口發送
insecure NFS經過1024以上的端口發送
wdelay若是多個用戶要寫入NFS目錄,則歸組寫入(默認)
no_wdelay 若是多個用戶要寫入NFS目錄,則當即寫入,當使用async時,無需此設置。
hide 在NFS共享目錄中不共享其子目錄
no_hide 共享NFS目錄的子目錄
subtree_check 若是共享/usr/bin之類的子目錄時,強制NFS檢查父目錄的權限(默認)
no_subtree_check 和上面相對,不檢查父目錄權限
all_squash 共享文件的UID和GID映射匿名用戶anonymous,適合公用目錄。
no_all_squash 保留共享文件的UID和GID(默認)
root_squash root用戶的全部請求映射成如anonymous用戶同樣的權限(默認)
no_root_squas root用戶具備根目錄的徹底管理訪問權限
anonuid=xxx 指定NFS服務器/etc/passwd文件中匿名用戶的UID
anongid=xxx 指定NFS服務器/etc/passwd文件中匿名用戶的GID
關於/etc/exports文件的更加詳細的配置說明,咱們能夠使用man exports命令來查看幫助手冊。
3.從新啓動rpcbind或portmap和nfs服務
使用root權限運行「service rpcbind restart」(RHEL高於6.0版本)或「service portmap restart」(RHEL5及如下版本)命令重啓NFS依賴的服務:
[weishusheng@localhost ~]$ sudo service rpcbind restart
Stopping rpcbind: [ OK ]
Starting rpcbind: [ OK ]
[weishusheng@localhost ~]$ sudo service rpcbind restart
Stopping rpcbind: [ OK ]
Starting rpcbind: [ OK ]
[weishusheng@localhost ~]$ sudo service nfs restart
Shutting down NFS daemon: [ OK ]
Shutting down NFS mountd: [ OK ]
Shutting down NFS quotas: [ OK ]
Shutting down NFS services: [ OK ]
Starting NFS services: exportfs: Failed to stat /home/lingyun/yangxu: No such file or directory
exportfs: Failed to stat /home/lingyun/yangzheng: No such file or directory
exportfs: Failed to stat /home/lingyun/keyue: No such file or directory
[ OK ]
Starting NFS quotas: rpc.rquotad: Cannot bind to given address: Address already in use
[ OK ]
Starting NFS mountd: [ OK ]
Stopping RPC idmapd: [ OK ]
Starting RPC idmapd: [ OK ]
Starting NFS daemon: [ OK ]
[weishusheng@localhost ~]$
4.使用service rpcbind status命令和「service nfs status」命令查看相關服務的運行狀態,同時能夠使用「showmount –e」命令能夠查看咱們經過NFS服務共享的文件:
[weishusheng@localhost ~]$ service rpcbind status
rpcbind (pid 8879) is running...
[weishusheng@localhost ~]$ service nfs status
rpc.svcgssd is stopped
rpc.mountd (pid 8966) is running...
nfsd (pid 9031 9030 9029 9028 9027 9026 9025 9024) is running...
rpc.rquotad (pid 8962) is running...
5.[weishusheng@localhost ~]$ showmount -e
[weishusheng@localhost ~]$ showmount -e
Export list for localhost.localdomain:
/home/lingyun/suosuo/rootfs *
/home/zhanbiqiang/rootfs *
/home/weishusheng/rootfs_tree/rootfs *
/home/zhouguangfeng *
/usr/local/src/lingyun/liuchengdeng/s3c2440/fs/nfs *
/usr/local/src/lingyun/huangyidong *
/usr/local/src/lingyun/yanshifu *
/home/lingyun/yangxu *
/home/lingyun/yangzheng *
/home/lingyun/keyue *
/opt
6.測試NFS訪問
在另一個Linux機器上,或者在本機上經過mount命令掛載並測試以下:
[weishusheng@localhost ~]$ sudo mkdir -p /mnt/wss
[weishusheng@localhost ~]$ ls /mnt/
ls: cannot access /mnt/nfs4: Stale file handle
ls: cannot access /mnt/ww: Stale file handle
ky-nfs nfs nfs1 nfs2 nfs3 nfs4 nfs_zhou wss ww yz_nfs
[weishusheng@localhost ~]$ sudo mount -t nfs 192.168.1.3:/home/weishusheng/rootfs_tree/rootfs /mnt/wss
[weishusheng@localhost ~]$ mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sdb1 on /usr/local/src type ext4 (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.1.2:/var/ftp/pub on /opt/pub type nfs (rw,vers=4,addr=192.168.1.2,clientaddr=192.168.1.3)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.1.3:/opt on /mnt/nfs type nfs (rw,vers=4,addr=192.168.1.3,clientaddr=192.168.1.3)
192.168.1.3:/opt on /mnt/nfs1 type nfs (rw,vers=4,addr=192.168.1.3,clientaddr=192.168.1.3)
192.168.1.3:/opt on /mnt/nfs3 type nfs (rw,vers=4,addr=192.168.1.3,clientaddr=192.168.1.3)
192.168.1.3:/home/zhanbiqiang/rootfs/ on /mnt/nfs4 type nfs (rw,vers=4,addr=192.168.1.3,clientaddr=192.168.1.3)
192.168.1.3:/home/weishusheng/rootfs_tree/rootfs on /mnt/wss type nfs (rw,vers=4,addr=192.168.1.3,clientaddr=192.168.1.3)
[weishusheng@localhost ~]$ ls /home/weishusheng/rootfs_tree/rootfs
apps data etc init linuxrc proc sbin tmp var
bin dev info lib mnt root sys usr weishusheng
[weishusheng@localhost ~]$ ls /mnt/wss
apps data etc init linuxrc proc sbin tmp var
bin dev info lib mnt root sys usr weishusheng
7.添加內核對nfs的支持
[weishusheng@localhost linux-3.0-nfs]$ pwd
/home/weishusheng/kernel/linux-3.0-nfs
[weishusheng@localhost linux-3.0-nfs]$ vt100
[weishusheng@localhost linux-3.0-nfs]$ sudo make menuconfig
General setup --->
[ ] Initial RAM filesystem and RAM disk (initramfs/initrd) support
[*] Networking support --->
Networking options --->
[*] IP: kernel level autoconfiguration
[ ] IP: DHCP support
[ ] IP: BOOTP support
[ ] IP: RARP support
File systems --->
[*] Network File Systems --->
[*] Root file system on NFS
[weishusheng@localhost linux-3.0-nfs]$ make
[weishusheng@localhost linux-3.0-ubifs-dm9000]$ du -h linuxrom-mini2440-wei.bin
2.5M linuxrom-mini2440-wei.bin
8.添加uboot對nfs支持
[fl2440@weishusheng]#set bootcmd_rootfs 'nand read 30008000 100000 400000;bootm 30008000'
[fl2440@weishusheng]#set bootcmd 'run bootcmd_rootfs'
[fl2440@weishusheng]#set bootargs_nfs 'noinitrd console=ttyS0,115200 init=/linuxrc mem=64M loglevel=7 root=/dev/nfs rw nfsroot=192.168.1.3:/home/weishusheng/rootfs_tree/rootfs ip=192.168.1.23:192.168.1.3:192.168.1.1:255.255.255.0:localhost.com:eth0:off'
[fl2440@weishusheng]#set bootargs 'noinitrd console=ttyS0,115200 init=/linuxrc mem=64M loglevel=7 root=/dev/nfs rw nfsroot=192.168.1.3:/home/weishusheng/rootfs_tree/rootfs ip=192.168.1.23:192.168.1.3:192.168.1.1:255.255.255.0:localhost.com:eth0:off'
(bootargs_nfs沒起做用,真正起做用的是bootargs,bootargs_nfs只是一個備忘的做用,由於咱們接下來會作jffs2,yaffs2,ubifs等文件系統,而每一個文件系統的bootargs與bootcmd不同,當咱們須要換文件系統時便用到bootargs_nfs了)
上面的設置中ip=<my-ip>:<serv-ip>這兩個是必須在bootargs中出現,否則可能沒法啓動。
my-ip就是開發板上你本身設的ip
serv-ip就是服務器ip
[fl2440@weishusheng]#set bkr 'tftp 30008000 linuxrom-mini2440-wei.bin;nand erase 100000 800000;nand write 30008000 100000 800000'
(你們如抱着學習的態度儘可能不要複製粘貼,由於每一個人的ip,下載地址不會同樣,固然你能夠設置和個人同樣,本身敲收穫會更大,還要注意不要有中文標點)
[fl2440@weishusheng]#save
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x60000 -- 100% complete.
Writing to Nand... done
9.下載啓動
[fl2440@weishusheng]# run bkr
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:6b
could not establish link
Using dm9000 device
TFTP from server 192.168.1.3; our IP address is 192.168.1.23
Filename 'linuxrom-mini2440-wei.bin'.
Load address: 0x30008000
Loading: #################################################################
#################################################################
#############################################
done
Bytes transferred = 2563280 (271cd0 hex)
NAND erase: device 0 offset 0x100000, size 0x800000
Erasing at 0x8e0000 -- 100% complete.
OK
NAND write: device 0 offset 0x100000, size 0x800000
8388608 bytes written: OK
[fl2440@weishusheng]#boot
......
Copyright (C) 2014 weishusheng
root login: root
Password:
>: ls
apps dev init mnt sbin usr
bin etc lib proc sys var
data info linuxrc root tmp weishusheng
>:
咱們已經啓動內核,下面測試nfs文件系統是否正常,在服務器上新建一個目錄nfs-done
[weishusheng@localhost rootfs]$ pwd
/home/weishusheng/rootfs_tree/rootfs
[weishusheng@localhost rootfs]$ ls
apps data etc init linuxrc proc sbin tmp var
bin dev info lib mnt root sys usr weishusheng
[weishusheng@localhost rootfs]$ mkdir nfs-done
[weishusheng@localhost rootfs]$ ls
apps data etc init linuxrc nfs-done root sys usr weishusheng
bin dev info lib mnt proc sbin tmp var
在開發板上輸入
>: ls
apps etc linuxrc root usr
bin info mnt sbin var
data init nfs-done sys weishusheng
dev lib proc tmp
>:
看到nfs-donne,說明nfs文件系統製做成功。
(當啓動不成功時,看看是否添加了Dm9000網卡的驅動,若是沒有添加,就須要本身添加,能夠網上找一個可用的,再和本身的內核作個patch包,而後對着patch包改,把patch包裏全部的MD9000網卡相關的都加進去,當學到驅動時就會明白爲何這麼加了。若是網上找不到,能夠發郵件到<642613208@qq.com>,我給你發,當你在啓動信息裏看到:dm9000 dm9000.0: eth0: link up, 100Mbps, full-duplex, lpa 0x41E1
Copyright (C) 2014 weishusheng
root login:
之類的信息時才行)