linux初学-内核编译以及文件系统4

2019-07-13 02:49发布

  linux初学-内核编译以及文件系统4     最近一段时间都没有继续K9板的linux开发学习。这边把NFS的开发环境的建立步骤做一下简要的说明,希望对和我一样刚刚开始linux开发的朋友有一点帮助。这一段的关于NFS的开发我主要参考了http://blog.chinaunix.net/u/21948/showart.php?id=150851上嵌入式linuxNFS开发环境的建立及配置实例一文。这边先对那位大侠的共享精神表示感谢。呵呵   1 建立NFS开发环境   嵌入式linuxNFS开发环境包含着两个方面:一是linux server端的NFS Server支持;二是target boardNFS Client支持。   1.1 linux server   1.1.1 root的身份登录,编译共享目录的配置文件exports,指定共享目录及其权限。   vi /etc/exports   在该文件中添加:   /home/lqm(共享目录) 192.168.1.*(rw,sync,no_root_squash)   添加的内容表示允许IP范围在192.168.1.*的计算机以读写的权限来访问共享目   /home/lqm   『注:参数说明如下:   rw---读/写权限。如果设定只读权限,则设为ro。但是一般情况下,为了方便交互,要设   置为rw   sync--数据同步写入内存和硬盘。   no_root_squash--此参数用来要求服务器允许远程系统以它自己的root特权存取该目录。』   就是说,如果用户是root,那么他就对这个共享目录有root的权限。很明显,该参数授予了target board很大的权利。安全性是首先要考虑的,可以采取一定的保护机制,在下面会讲一下保护机制。如果使用默认的root_squashtarget board自己的根文件系统可能有很多无法写入,所以运行会受到极大的限制。在安全性有所保障的前提下,推荐使用no_root_squash参数。   1.1.2 起用保护机制   可以通过设定/etc/hosts.deny/etc/hosts.allow文件来限制网络服务的存取权限。   ***/etc/hosts.deny***   portmap:ALL   lockd:ALL   mountd:ALL   rquotad:ALL   statd:ALL   ***/etc/hosts.allow***   portmap:192.168.1.100   lockd:192.168.1.100   mountd:192.168.1.100   rquotad:192.168.1.100   statd:192.168.1.100   同时使用这两个文件就会使得只有ip192.168.1.100的机器使用NFS服务。你的target   boardip地址设定为192.168.1.100,这样就可以了。   1.1.3 启动   首先要启动portmapper(端口映射)服务,这是NFS本身需要的。   /etc/init.d/portmap start   然后启动NFS Server。此时NFS会激活守护进程,然后开始监听客户端的请求。   /etc/init.d/nfs start   NFS Server启动后,还要检查一下linux serveriptables等,确定没有屏蔽NFS使用的端口和允许通信的主机。   可以首先在linux server上面进行NFS的回环测设。修改/etc/hosts.allow,把ip改为linux   serverip地址,然后在linux server上执行命令:   mount -t nfs :/home/lqm /mnt   ls /mnt   如果NFS Server正常工作,应该在/mnt下面看到共享目录/home/lqm的内容。       1.2 target board端的client   1.2.1 嵌入式linux内核应该支持NFS客户端。   内核配置时,选择如下:   File system--> Network File Systems-->   选中File SystemNFS System supportProvide NFSvs client support,然后保存退出,重新编译内   核,将生成的镜像文件重新下载到target board     1.2.2 uboot引导参数的设置   bootargs=root=/dev/ram rw initrd=0x20a00000,4M init=/linuxrc console=ttyS0,11520   0,mem=32m ip=192.168.2.10   其中ip=192.168.2.10就是将linux系统ip地址设置成192.168.2.10。注意这个ip需要设置成与主机端是同一个网段的。不然会出现Network is unreachable的错误。   为了调试网络的方便,我们这边可以把命令ifconfigping等网络调试命令编译进来。   Linux启动信息如下:注意与前面的启动信息相比较,在IP_Config那边有区别:   ## Booting image at 20007fc0 ...                                     Image Name:   Linux 2.6.20                                Image Type:   ARM Linux Kernel Image (uncompressed)                                                          Data Size:    1255088 Bytes =  1.2 MB                                           Load Address: 20007fc0                            Entry Point:  20008000                            Verifying Checksum ... OK                               XIP Kernel Image ... OK                          Starting kernel ...                     Uncompressing Linux.............................................................                                                                                ..................... done, booting the kernel.                                                Linux version 2.6.20 (root@dengdl) (gcc version 3.4.1) #6 Fri Apr 6 09:05:37 CST                                                                                 2007     CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177                                                        Machine: Atmel AT91RM9200-DK                             Memory policy: ECC disabled, Data cache writeback                                                 Clocks: CPU 179 MHz, master 59 MHz, main 18.432 MHz                                                    CPU0: D VIVT write-back cache                              CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets                                                                    CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets                                                                    Built 1 zonelists.  Total pages: 4064                                      Kernel command line: root=/dev/ram rw initrd=0x20a00000,4M init=/linuxrc console                                                                                 =ttyS0,115200,mem=32m ip=192.168.2.10                                      AT91: 128 gpio irqs in 4 banks                              PID hash table entries: 64 (order: 6, 256 bytes)                                                 Console: colour dummy device 80x30                                  Dentry cache hash table entries: 2048 (order: 1, 8192 bytes)                                                             Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)                                                            Memory: 16MB = 16MB total                         Memory: 9484KB available (2292K code, 226K data, 100K init)                                                           Mount-cache hash table entries: 512                                    CPU: Testing write buffer coherency: ok                                       NET: Registered protocol family 16                                   Generic PHY: Registered new driver                                  usbcore: registered new interface driver usbfs                                               usbcore: registered new interface driver hub                                            usbcore: registered new device driver usb                                          NET: Registered protocol family 2                                 IP route cache hash table entries: 1024 (order: 0, 4096 bytes)                                                               TCP established hash table entries: 1024 (order: 0, 4096 bytes)                                                                TCP bind hash table entries: 512 (order: -1, 2048 bytes)                                                         TCP: Hash tables configured (established 1024 bind 512)                                                        TCP reno registered                   checking if image is initramfs...it isn't (no cpio magic); looks like an initrd                                                                               Freeing initrd memory: 4096K                            NetWinder Floating Point Emulator V0.97 (double precision)                                                           io scheduler noop registered                            io scheduler anticipatory registered (default)                                               at91_spi: Baud rate set to 5990400                                  AT91 SPI driver loaded                      AT91 Watchdog Timer enabled (5 seconds, nowayout)                                                 atmel_usart.0: ttyS0 at MMIO 0xfefff200 (irq = 1) is a ATMEL_SERIAL                                                                    atmel_usart.1: ttyS1 at MMIO 0xfffc4000 (irq = 7) is a ATMEL_SERIAL                                                                    RAMDISK driver initialized: 16 RAM disks of 8192K size 1024 blocksize                                                                      tun: Universal TUN/TAP device driver, 1.6                                         tun: (C) 1999-2004 Max Krasnyansky                                                        eth0: Link down.                eth0: AT91 ethernet at 0xfefbc000 int=24 10-HalfDuplex (00:15:f2:9d:66:80)                                                                           eth0: Davicom 9161 PHY (Copper)                               netconsole: not configured, aborting                                     physmap platform flash device: 00200000 at 10000000                                                   physmap-flash.0: Found 1 x16 devices at 0x0 in 16-bit bank                                                           NOR chip too large to fit in mapping. Attempting to cope...                                                           Support for command set 0001 not present                                         gen_probe: No supported Vendor Command Set found                                                physmap-flash physmap-flash.0: map_probe failed                                                at91_cf: irqs det #64, io #0                            usbmon: debugfs is not available                                 at91_ohci at91_ohci: AT91 OHCI                              at91_ohci at91_ohci: new USB bus registered, assigned bus number 1                                                                   at91_ohci at91_ohci: irq 23, io mem 0x00300000                                              usb usb1: Product: AT91 OHCI                             usb usb1: Manufacturer: Linux 2.6.20 ohci_hcd                                              usb usb1: SerialNumber: at91                            usb usb1: configuration #1 chosen from 1 choice                                               hub 1-0:1.0: USB hub                     hub 1-0:1.0: 2 ports detected                             udc: at91_udc version 3 May 2006                                 mice: PS/2 mouse device common for all mice                                           at91_rtc at91_rtc: rtc core: registered at91_rtc as rtc0                                                         AT91 Real Time Clock driver.                            i2c /dev entries driver                       at91_i2c at91_i2c: AT91 i2c bus driver.                                       pktgen v2.68: Packet Generator for packet performance testing.                                                               TCP cubic registered                    NET: Registered protocol family 1                                  NET: Registered protocol family 17                                  at91_rtc at91_rtc: setting the system clock to 1998-01-01 00:00:24 (883612824)                                                                               usb 1-2: new low speed USB device using at91_ohci and address 2                        Flash: 16 MB            In:    serial  usb 1-2: device descriptor read/64, error -62serial             usb 1-2: new low speed USB device using at91_ohci and address 3 usb 1-2: device descriptor read/64, error -62 usb 1-2: device descriptor read/64, error -62 IP-Config: Guessing netmask 255.255.255.0 IP-Config: Complete:      device=eth0, addr=192.168.2.10, mask=255.255.255.0, gw=255.255.255.255,      host=192.168.2.10, domain=, nis-domain=(none),      bootserver=255.255.255.255, rootserver=255.255.255.255, rootpath= RAMDISK: Compressed image found at block 0 usb 1-2: new low speed USB device using at91_ohci and address 4 VFS: Mounted root (ext2 filesystem). Freeing init memory: 100K route: SIOC[ADD|DEL]RT: No such process route: SIOC[ADD|DEL]RT: Network is unreachable 1.2.3 target boardlinux shell下,执行下列命令来进行NFS共享目录的挂载。 mkdir /mnt/nfs mount -o nolock -t nfs :/home/lqm /mnt/nfs ls /mnt/nfs   由于很多嵌入式设备的根文件系统中不带portmap,所以一般都使用-o nolock参数,即不使用NFS文件锁,这样就可以避免使用portmap。如果顺利,在/mnt/nfs下,就可以看到linuxserver的共享文件夹下的内容了,