标签:style color os io 使用 ar for 文件 数据
内核: linux-3.0
u-boot: 2010.08
开发板: fl2440(s3c2440主芯片)
交叉编译器: 2011.11
我们在上面移植了initramfs文件系统,并且已经成功运行了。下面我们开始移植nfs,之前开启PC上的nfs服务功能
确认并安装NFS服务依赖软件包
一般NFS服务器要提供服务,必须启动inet,nfs, mount,portmap或rpcbind这些守护进程并保持在后台状态运行. 这里需要提示的是从RHEL6开始, 系统使用rpcbind替换了以前早期版本中NFS依赖的portmap服务。
在使用NFS共享文件之前,我们首先使用rpm命令确认我们安装了这些应用程序。如果没有安装,则从安装光盘中找到他们并安装,或者使用yum安装。下面显示我们在安装系统时,已经选择安装了NFS服务相关软件
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文件系统制作成功。
标签:style color os io 使用 ar for 文件 数据
原文地址:http://www.cnblogs.com/wss-linux/p/3931802.html