NFS文件系统的制作以及移植
NFS网络文件系统(Network File System)是由Sun开发并发展起来的一项在不同机器、不同操作系统之间通过网络共享文件的技术。在嵌入式Linux系统的开发调试阶段,可以利用该技术在主机上建立基于NFS的根文件系统,挂载到嵌入式设备,可以很方便地修改根文件系统的内容。 1、前言我们在上面移植了initramfs文件系统,并且已经成功运行了。下面我们开始移植nfs,之
NFS网络文件系统(Network File System)是由Sun开发并发展起来的一项在不同机器、不同操作系统之间通过网络共享文件的技术。在嵌入式Linux系统的开发调试阶段,可以利用该技术在主机上建立基于NFS的根文件系统,挂载到嵌入式设备,可以很方便地修改根文件系统的内容。
1、前言
我们在上面移植了initramfs文件系统,并且已经成功运行了。下面我们开始移植nfs,之前开启PC上的nfs服务功能确认并安装NFS服务依赖软件包。
一般NFS服务器要提供服务,必须启动inet,nfs, mount,portmap或rpcbind这些守护进程并保持在后台状态运行. 这里需要提示的是从RHEL6开始, 系统使用rpcbind替换了以前早期版本中NFS依赖的portmap服务。
在使用NFS共享文件之前,我们首先使用rpm命令确认我们安装了这些应用程序。如果没有安装,则从安装光盘中找到他们并安装,或者使用yum安装。下面显示我们在安装系统时,已经选择安装了NFS服务相关软件。
[lingyun@localhost~]$ cd /opt/
[lingyun@localhostopt]$ 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
[lingyun@localhostopt]$ rpm -qa | grep rpcbind
rpcbind-0.2.0-11.el6.x86_64
修改主机上的NFS配置文件,导出/opt目录使用NFS共享:
[lingyun@localhostopt]$ sudo vim /etc/exports
/home/lingyun/yangzheng*(rw,sync,no_root_squash)
使用root权限运行“service nfs restart”命令重启NFS服务,让其生效:
[lingyun@localhost opt]$ sudo service rpcbind restart
Stoppingrpcbind: [ OK ]
Startingrpcbind: [ OK ]
[lingyun@localhostopt]$ sudo service nfs restart
Shuttingdown NFS daemon: [ OK ]
Shuttingdown NFS mountd: [ OK ]
Shuttingdown NFS quotas: [ OK ]
Shuttingdown NFS services: [ OK ]
StartingNFS services: [ OK ]
StartingNFS quotas: [ OK ]
StartingNFS mountd: [ OK ]
StoppingRPC idmapd: [ OK ]
StartingRPC idmapd: [ OK ]
StartingNFS daemon: [ OK ]
[lingyun@localhostopt]$
使用servicerpcbind status命令和“servicenfs status”命令查看相关服务的运行状态,同时可以使用“showmount –e”命令可以查看我们通过NFS服务共享的文件:
[lingyun@localhostopt]$ service rpcbind status
rpcbind(pid 6566) is running...
[lingyun@localhostopt]$ service nfs status
rpc.svcgssdis stopped
rpc.mountd(pid 6651) is running...
nfsd (pid6716 6715 6714 6713 6712 6711 6710 6709) is running...
rpc.rquotad(pid 6647) is running...
[lingyun@localhostopt]$
[lingyun@localhostopt]$ showmount -e
Exportlist for localhost.localdomain:
/usr/local/src/lingyun/yangzheng*
…………
在另外一个Linux机器上,或者在本机上通过mount命令挂载并测试如下:
[lingyun@localhost~]$ sudo mkdir -p /mnt/yz_nfs
[lingyun@localhost~]$ sudo mount -t nfs 192.168.1.3:/home/lingyun/yangzheng/ /mnt/yz_nfs/
[lingyun@localhost~]$ mount
/dev/sda2on / 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/sdb1on /usr/local/src type ext4 (rw)
none on/proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on/var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.1.2:/var/ftp/pubon /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:/opton /mnt/ky-nfs type nfs (rw,vers=4,addr=192.168.1.3,clientaddr=192.168.1.3)
192.168.1.3:/opton /mnt/nfs type nfs (rw,vers=4,addr=192.168.1.3,clientaddr=192.168.1.3)
192.168.1.3:/opton /opt/mnt/nfs type nfs (rw,vers=4,addr=192.168.1.3,clientaddr=192.168.1.3)
192.168.1.3:/opt/on /opt/mnt/ww type nfs (rw,vers=4,addr=192.168.1.3,clientaddr=192.168.1.3)
192.168.1.3:/opt/on /mnt/ww type nfs (rw,vers=4,addr=192.168.1.3,clientaddr=192.168.1.3)
192.168.1.3:/home/lingyun/yangzheng/on /mnt/yz_nfs type nfs (rw,addr=192.168.1.3)
192.168.1.3:/home/lingyun/keyueon /mnt/ky-nfs type nfs (rw,addr=192.168.1.3)
[lingyun@localhost~]$ ls yangzheng/rootfs/
apps bin data dev etc hh info init lib linuxrc mnt proc root sbin sys tmp usr var
[lingyun@localhost~]$ ls /mnt/yz_nfs/rootfs/
apps bin data dev etc hh info init lib linuxrc mnt proc root sbin sys tmp usr var
[lingyun@localhost~]$ rm yangzheng/rootfs/hh
[lingyun@localhost~]$ ls yangzheng/rootfs/
apps bin data dev etc info init lib linuxrc mnt proc root sbin sys tmp usr var
[lingyun@localhost~]$ ls /mnt/yz_nfs/rootfs/
apps bin data dev etc info init lib linuxrc mnt proc root sbin sys tmp usr var
我们先假定PC上的功能已经开启,同时在上面移植initramfs文件系统时也完成了下面添加内核对nfs的支持的前提下,我们先在上面已经运行起来的环境中试着先看看开发板上的nfs客户端功能是否支持(如果内核中没有开启这个功能也没有关系,因为这一步不是关键的):
PC上/opt目录下的内容:
[lingyun@localhost~]$ ls yangzheng/
busybox-1.20.2 busybox-1.20.2.tar.bz2 linux-3.0 linux-3.0.tar.bz2 mkimage rootfs
下面是开发中挂载PC上的/opt目录情况:
>:mount -o nolock 192.168.1.3:/home/lingyun/yangzheng /mnt/nfs/
>: ls
>: ls/mnt/nfs/
busybox-1.20.2 linux-3.0 mkimage
busybox-1.20.2.tar.bz2 linux-3.0.tar.bz2 rootfs
2、添加对内和的支持
//关掉对initramfis的支持
General setup --->
[ ]Initial RAM filesystem and RAM disk (initramfs/initrd) support
//开启对nfs的支持
[*] Networking support --->
Networkingoptions --->
[*] IP: kernel levelautoconfiguration
[ ] IP: DHCP support
[ ] IP: BOOTP support
[ ] IP: RARP support
Filesystems --->
[*]Network File Systems --->
<*> NFS clientsupport
[*] Root file systemon NFS
重新编译内核:
[lingyun@localhostlinux-3.0]$ sudo make
[lingyun@localhostlinux-3.0]$ ls
arch crypto fs Kbuild MAINTAINERS modules.order REPORTING-BUGS sound usr
block Documentation include Kconfig Makefile Module.symvers samples System.map virt
COPYING drivers init kernel mm net scripts tools vmlinux
CREDITS firmware ipc lib modules.builtin README security uImage-s3c2440.gz vmlinux.o
[lingyun@localhostlinux-3.0]$ cp uImage-s3c2440.gz/tftp/yz_nfsuImage-2440.gz
3、添加u_boot对nfs文件系统的支持
由于nfs也是不需要制作镜像文件,而直接编译进内核:
[ s3c2440@ yangzheng ]# set bootcmd_rootfs'nand read 30008000 100000 400000;bootm 30008000'
[ s3c2440@ yangzheng ]# set bootcmd 'run bootcmd_rootfs'
[ s3c2440@ yangzheng ]# set bootargs_nfs'noinitrd console=ttyS0,115200 init=/linuxrc mem=64M loglevel=7 root=/dev/nfs rw nfsroot=192.168.1.3:/opt/rootfsip=192.168.1.122:192.168.1.3:192.168.1.1:255.255.255.0:localhost.com:eth0:off'
# setbootargs_nfs 'noinitrd console=ttyS0,115200 init=/linuxrc mem=64M loglevel=7 root=/dev/nfs rwnfsroot=192.168.1.3:/home/lingyun/yangzheng/rootfs ip=192.168.1.122:192.168.1.3:192.168.1.1:255.255.255.0:localhost.com:eth0:off'
[ s3c2440@ yangzheng ]# set bootargs'noinitrd console=ttyS0,115200 init=/linuxrc mem=64M loglevel=7 root=/dev/nfs rw nfsroot=192.168.1.3:/home/lingyun/yangzheng/rootfsip=192.168.1.122:192.168.1.3:192.168.1.1:255.255.255.0:localhost.com:eth0:off'
[ s3c2440@ yangzheng ]# set bkr 'tftp30008000 yz_nfsuImage-2440.gz;nand erase 100000 400000;nand write 30008000 100000400000'
[ s3c2440@ yangzheng ]# sa
SavingEnvironment to NAND...
ErasingNand...
Erasingat 0x60000 -- 100% complete.
Writingto Nand... done
[ s3c2440@ yangzheng ]# run bkr
dm9000i/o: 0x20000300, id: 0x90000a46
DM9000:running in 16 bit mode
MAC:08:00:3e:26:0a:6b
could notestablish link
operatingat 100M full duplex mode
Usingdm9000 device
TFTP fromserver 192.168.1.3; our IP address is 192.168.1.244
Filename'yz_nfsuImage-2440.gz'.
Loadaddress: 0x30008000
Loading:T #################################################################
#################################################################
################################################
done
Bytestransferred = 2604692 (27be94 hex)
NANDerase: device 0 offset 0x100000, size 0x400000
Erasingat 0x4e0000 -- 100% complete.
OK
NANDwrite: device 0 offset 0x100000, size 0x400000
4194304 bytes written: OK
启动linux:
[ s3c2440@ yangzheng ]# boot
NANDread: device 0 offset 0x100000, size 0x27c000
2605056 bytes read: OK
## Bootingkernel from Legacy Image at 30008000 ...
Image Name: Linux Kernel
Created: 2013-06-04 7:34:46 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2604628 Bytes = 2.5 MiB
Load Address: 30008000
Entry Point: 30008040
Verifying Checksum ... OK
XIP Kernel Image ... OK
OK
OS entrypoint: 30008040
Imageentry point=30008040
Startingkernel ...
UncompressingLinux... done, booting the kernel.
Linuxversion 3.0.0 (root@localhost.localdomain) (gccversion 4.5.4 (Buildroot 2012.08) ) #4 Tue Jun 4 15:34:42 CST 2013
CPU:ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVTdata cache, VIVT instruction cache
Machine:SMDK2440
Memorypolicy: ECC disabled, Data cache writeback
CPU S3C2440A(id 0x32440001)
S3C24XX Clocks, Copyright 2004 SimtecElectronics
S3C244X: core 405.000 MHz, memory 101.250MHz, peripheral 50.625 MHz
CLOCK:Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel commandline: noinitrd console=ttyS0,115200 init=/linuxrc mem=64M loglevel=7 root=/dev/nfs rwnfsroot=192.168.1.3:/home/lingyun/yangzheng/rootfsip=192.168.1.122:192.168.1.3:192.168.1.1:255.255.255.0:localhost.com:eth0:off
PID hashtable entries: 256 (order: -2, 1024 bytes)
Dentrycache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cachehash table entries: 4096 (order: 2, 16384 bytes)
Memory:64MB = 64MB total
Memory:59488k/59488k available, 6048k reserved, 0K highmem
Virtualkernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xfff00000 - 0xfffe0000 ( 896kB)
DMA : 0xffc00000 - 0xffe00000 ( 2 MB)
vmalloc : 0xc4800000 - 0xf6000000 ( 792 MB)
lowmem : 0xc0000000 - 0xc4000000 ( 64 MB)
modules : 0xbf000000 - 0xc0000000 ( 16MB)
.init : 0xc0008000 - 0xc002c000 ( 144 kB)
.text : 0xc002c000 - 0xc04ef000 (4876 kB)
.data : 0xc04f0000 - 0xc051fb00 ( 191 kB)
.bss : 0xc051fb24 - 0xc054bf80 ( 178 kB)
NR_IRQS:85
irq:clearing pending ext status 00080000
irq:clearing subpending status 00000003
irq:clearing subpending status 00000002
Console:colour dummy device 80x30
console[ttyS0] enabled
Calibratingdelay loop... 201.52 BogoMIPS (lpj=503808)
pid_max:default: 32768 minimum: 301
Mount-cachehash table entries: 512
CPU:Testing write buffer coherency: ok
gpiochip_add:gpios 288..303 (GPIOK) failed to register
gpiochip_add:gpios 320..334 (GPIOL) failed to register
gpiochip_add:gpios 352..353 (GPIOM) failed to register
NET:Registered protocol family 16
S3C Power Management, Copyright 2004Simtec Electronics
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, Copyright 2003-2006Simtec Electronics
DMAchannel 0 at c4804000, irq 33
DMA channel1 at c4804040, irq 34
DMAchannel 2 at c4804080, irq 35
DMAchannel 3 at c48040c0,irq 36
S3C244X: Clock Support, DVS off
s3c-adc s3c24xx-adc: attached adc driver
bio:create slab <bio-0> at 0
SCSIsubsystem initialized
usbcore:registered new interface driver usbfs
usbcore:registered new interface driver hub
usbcore:registered new device driver usb
s3c-i2cs3c2440-i2c: slave address 0x10
s3c-i2cs3c2440-i2c: bus frequency set to 98 KHz
s3c-i2cs3c2440-i2c: i2c-0:S3C I2C adapter
AdvancedLinux Sound Architecture Driver Version 1.0.24.
cfg80211:Calling CRDA to update world regulatory domain
NET:Registered protocol family 2
IP routecache hash table entries: 1024 (order: 0, 4096 bytes)
TCPestablished hash table entries: 2048 (order: 2, 16384 bytes)
TCP bindhash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hashtables configured (established 2048 bind 2048)
TCP reno registered
UDP hashtable entries: 256 (order: 0, 4096 bytes)
UDP-Litehash table entries: 256 (order: 0, 4096 bytes)
NET:Registered protocol family 1
RPC:Registered named UNIX socket transport module.
RPC:Registered udp transport module.
RPC:Registered tcp transport module.
RPC:Registered tcp NFSv4.1 backchannel transport module.
NetWinderFloating Point Emulator V0.97 (extended precision)
NTFSdriver 2.1.30 [Flags: R/W].
JFFS2version 2.2. (NAND) (SUMMARY) 漏 2001-2006 Red Hat, Inc.
msgmnihas been set to 116
ioscheduler noop registered
ioscheduler deadline registered
ioscheduler cfq registered (default)
Console:switching to colour frame buffer device 60x34
fb0: s3c2410fb frame buffer device
s3c2440-uart.0: ttyS0 at MMIO 0x50000000(irq = 70) is a S3C2440
s3c2440-uart.1: ttyS1 at MMIO 0x50004000(irq = 73) is a S3C2440
s3c2440-uart.2: ttyS2 at MMIO 0x50008000(irq = 76) is a S3C2440
brd:module loaded
loop:module loaded
at240-0050: 65536 byte 24c512EEPROM, writable, 128 bytes/write
S3C24XX NAND Driver, (c) 2004 SimtecElectronics
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=329ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NANDdevice: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
Scanningdevice for bad blocks
Baderaseblock 421 at 0x0000034a0000
Baderaseblock 1177 at 0x000009320000
Baderaseblock 1727 at 0x00000d7e0000
Creating11 MTD partitions on "NAND":
0x000000000000-0x000000100000: "mtdblock0 u-boot 1MB"
0x000000100000-0x000000500000: "mtdblock1 kernel 4MB"
0x000000500000-0x000000f00000 : "mtdblock2 ramdisk10MB"
0x000000f00000-0x000001e00000 :"mtdblock3 cramfs 15MB"
0x000001e00000-0x000004600000: "mtdblock3 jffs2 40MB"
0x000004600000-0x000006e00000: "mtdblock4 yaffs2 40MB"
0x000006e00000-0x000009600000: "mtdblock5 ubifs 40MB"
0x000009600000-0x000009700000: "mtdblock6 info 1MB"
0x000009700000-0x00000bf00000: "mtdblock7 apps 40MB"
0x00000bf00000-0x00000e700000: "mtdblock8 data 40MB"
0x00000e700000-0x000010000000: "mtdblock9 backup 25MB"
PPPgeneric driver version 2.4.2
PPPDeflate Compression module registered
PPP BSDCompression module registered
PPP MPPECompression module registered
NET:Registered protocol family 24
dm9000Ethernet Driver, V1.31
eth0: dm9000a at c4864300,c4866304 IRQ 51 MAC:08:00:3e:26:0a:6b(chip)
usbcore:registered new interface driver rt2800usb
ohci_hcd:USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XXOHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned busnumber 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1:New USB device found, idVendor=1d6b, idProduct=0001
usb usb1:New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb1:Product: S3C24XXOHCI
usb usb1:Manufacturer: Linux 3.0.0 ohci_hcd
usb usb1:SerialNumber: s3c24xx
hub1-0:1.0: USB hub found
hub1-0:1.0: 2 ports detected
InitializingUSB Mass Storage driver...
usbcore:registered new interface driver usb-storage
USB MassStorage support registered.
usbcore:registered new interface driver usbserial
usbserial:USB Serial Driver core
USBSerial support registered for ch341-uart
usbcore:registered new interface driver ch341
USBSerial support registered for FTDI USB Serial Device
usbcore:registered new interface driver ftdi_sio
ftdi_sio:v1.6.0:USB FTDI Serial Converters Driver
USBSerial support registered for GSM modem (1-port)
usbcore:registered new interface driver option
option: v0.7.2:USBDriver for GSM modems
USBSerial support registered for pl2303
usbcore:registered new interface driver pl2303
pl2303:Prolific PL2303 USB to serial adaptor driver
mousedev:PS/2 mouse device common for all mice
samsung-tss3c2440-ts: driverattached, registering input device
input: S3C24XX TouchScreen as/devices/virtual/input/input0
S3C24XX RTC, (c) 2004,2006 SimtecElectronics
s3c-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
i2c /dev entries driver
s3c-sdi s3c2440-sdi: mmc0 - using pio, sw SDIO IRQ
usbcore:registered new interface driver usbhid
usbhid:USB HID core driver
S3C24XX_UDA134X SoC Audio driver
UDA134XSoC Audio Codec
asoc:uda134x-hifi <-> s3c24xx-iismapping ok
ALSAdevice list:
#0: S3C24XX_UDA134X
Netfiltermessages via NETLINK v0.30.
nf_conntrackversion 0.5.0 (929 buckets, 3716 max)
ctnetlinkv0.93: registering with nfnetlink.
xt_time:kernel timezone is -0000
ip_set:protocol 6
IPVS:Registered protocols (TCP, UDP, AH, ESP)
IPVS:Connection hash table configured (size=4096, memory=32Kbytes)
IPVS:Creating netns size=1008 id=0
IPVS:ipvs loaded.
IPVS:[rr] scheduler registered.
IPVS:[wrr] scheduler registered.
IPVS:[lc] scheduler registered.
IPVS:[wlc] scheduler registered.
IPVS:[lblc] scheduler registered.
IPVS:[lblcr] scheduler registered.
IPVS:[dh] scheduler registered.
IPVS:[sh] scheduler registered.
IPVS:[sed] scheduler registered.
IPVS:[nq] scheduler registered.
ip_tables:(C) 2000-2006 Netfilter Core Team
ipt_CLUSTERIP:ClusterIP Version 0.8 loaded successfully
arp_tables:(C) 2002 David S. Miller
TCP cubicregistered
NET:Registered protocol family 17
lib80211:common routines for IEEE802.11 drivers
Registeringthe dns_resolver key type
s3c-rtc s3c2410-rtc: setting system clock to 2047-03-2012:01:06 UTC (2436696066)
dm9000dm9000.0: eth0: link down
usb 1-1:new full speed USB device number 2 using s3c2410-ohci
IP-Config:Complete:
device=eth0, addr=192.168.1.122,mask=255.255.255.0, gw=192.168.1.1,
host=localhost, domain=, nis-domain=com,
bootserver=192.168.1.3,rootserver=192.168.1.3, rootpath=
dm9000dm9000.0: eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
VFS:Mounted root (nfs filesystem) on device 0:12.
Freeinginit memory: 144K
usb 1-1:New USB device found, idVendor=05e3, idProduct=0606
usb 1-1:New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 1-1:Product: USB Hub 2.0
hub1-1:1.0: USB hub found
hub1-1:1.0: 4 ports detected
Copyright(C) 2013 yangzheng<yz2012ww@gmail.com>
rootlogin: root
>: ls
apps data etc init linuxrc proc sbin tmp var
bin dev info lib mnt root sys usr
下面就测试一下:
在开发板上ls
>: ls
apps data etc init linuxrc proc sbin tmp var
bin dev info lib mnt root sys usr
在pc上创建一个文件haha
[lingyun@localhostrootfs]$ touch haha
[lingyun@localhostrootfs]$ ls
apps bin data dev etc haha info init lib linuxrc mnt proc root sbin sys tmp usr var
再在开发板上ls
>: ls
apps data etc info lib mnt root sys usr
bin dev haha init linuxrc proc sbin tmp var
更多推荐
所有评论(0)