|  | 
 
 楼主|
发表于 2009-12-11 16:48:49
|
显示全部楼层 
| 
本帖最后由 aatianluaa 于 2009-12-11 16:54 编辑 
 下面的工作是挂接NFS,就是使用网络文件系统作为根文件系统启动。
 
 (2)使用NFS作根文件系统
 
 需要做几件事情:1)建立Qemu TUN/TAP 虚拟网络
 2)建立 /设置/启动 NFS服务
 3)修改u-boot启动参数,使内核从NFS启动
 一、检查运行环境
 1)安装必要软件包:使用
 #rpm –qa|grep portmap
 #rpm –qa|grep nfs
 检查是否安装nfs软件包
 
 For the TUN/TAP you need to check your kernel config file for CONFIG_TUN=m or CONFIG_TUN=y.
 
 # grep CONFIG_TUN= /boot/config-`uname -r`
 
 2)从http://sourceforge.net/projects/tunctl/ 下载 The tunctl tool for controlling the TUN/TAP driver in Linux. http://sourceforge.net/projects/ ... 1.5.tar.gz/download
 
 这个用来创建Qemu需要tap网络
 
 如果系统内没有tun网络支持,可以下载
 http://vtun.sourceforge.net/tun/tun-1.1.tar.gz
 检查方法:查看是否存在 #ls /dev/net/tun
 如果支持,没有,可以执行
 #mknod /dev/net/tun c 10 200 创建
 
 关于TUN/TAP的说明:
 Virtual network
 In computer networking, TUN and TAP are virtual network kernel drivers. They implement network devices that are supported entirely in software, which is different from ordinary network devices that are backed up by hardware network adapters.
 TAP (as in network tap) simulates an Ethernet device and it operates with layer 2 packets such as Ethernet frames. TUN (as in network TUNnel) simulates a network layer device and it operates with layer 3 packets such as IP packets. TAP is used to create a network bridge, while TUN is used with routing.
 
 Make sure that "Kernel module loader" - module auto-loading support is enabled in your kernel.
 
 Add following line to the /etc/modules.conf: 在2.6里面为 /etc/modprobe.conf
 alias char-major-10-200 tun
 Run:
 /sbin/depmod -a
 Driver will be automatically loaded when application access /dev/net/tun.
 
 Modprobe是管理模块添加删除的命令
 
 
 3)关闭redhat的firewall,或者通过system settings/security level 里把tap0加入到trusted devices, SElinux/support NFS
 
 二、设置TAP网络
 解压安装tunctl-1.5.tar.gz:
 #tar zxf tunctl-1.5.tar.gz
 #make
 #cp tunctl /sbin/
 
 创建虚拟网络:
 #/sbin/tunctl –t tap0 –u root
 #/sbin/ifconfig tap0 10.0.2.1
 
 To delete the interface, use the -d option:
 # tunctl -d tap0
 
 编辑/etc/qemu-ifup 文件为:
 #!/bin/sh
 /sbin/ifconfig $1 10.0.2.1
 这个作为Qemu启动时的网络设置脚本,和单独执行ifconfig tap0 10.0.2.1效果是一样的
 
 也可以编辑/etc/qemu-ifdown为;
 #!/bin/sh
 /sbin/ifdown tap0
 在Qemu关闭时,关闭tap网络
 
 三、设置NFS
 使用system settings/server settings/NFS 设置要共享的目录 /soft/nfs_share , hosts 设为*,RW,允许root身份
 
 通过 #/sbin/service nfs restart/status/start/stop 启动NFS服务
 
 把根文件系统文件复制到NFS共享目录里:
 #mount -o loop -t cramfs armv5_min.cramfs /mnt/cram
 #cp –r /mnt/cram/* /soft/nfs_share
 
 检查NFS是否工作正常:
 #mount -t nfs 10.0.2.1:/soft/nfs_share /mnt
 
 也可以直接修改/etc/exports:
 
 /system/directory     192.168.7.2(rw,no_root_squash,async)
 
 在exports文件 客户端,客户端主机的指定非常灵活,如下所示
 客户端主机地址                                 说明
 192.168.0.28                            指定ip地址的主机
 www.chinafu.net                         指定域名的主机
 192.168.0.10/31                        指定网段中的所有主机
 *.chinafu.com                           指定域中的所有主机
 *                                      指定所有主机
 sync                        设置NFS服务器同步写磁盘,这样不会轻易丢失数据,NFS服务器建议使用该选项
 ro                            设置输出的共享目录只读,与 rw捡能同时使用
 rw                            设置输出的共享目录可读写 ,与ro不能共同使用
 为了使NFS服务器能正常工作,需要启动portmap和nfs两人服务,并且portmap一定要先于nfs启动
 
 
 四、修改Qemu启动命令
 
 qemu-system-arm -M versatilepb -m 200 -nographic -pflash ./flash.img -net nic,vlan=0 -net tap,vlan=0,ifname=tap0
 
 关于启动参数的说明:
 The "-nographic" option boots qemu in the terminal. Leaving this option off causes qemu to boot using its separate graphical window. Hit <Ctrl><Alt><3> to toggle to the console. <Ctrl><Alt><2> gets to back to the qemu control panel, where a "quit" will exit qemu. <Ctrl><Alt><1> gives the graphics (LCD) console (which doesn't seem to work for integrator kernels, but will give a small 320×240 framebuffer screen for versatile kernels with ARM LCD enabled). Just <Ctrl><Alt> will free up the mouse. The graphic option is nice in that the console is in color.
 
 With the "-m" option you can tell the system how much memory it should have; 128 MB is the default.
 
 I run qemu as root to avoid complications, e.g., a normal user doesn't have access to the "tap0" device, apparently. The emulated system boots with the serial port /dev/ttyAMA0 as the system console.
 
 # ./run_qemu
 
 VersatilePB # set ipaddr 10.0.2.2
 VersatilePB # set serverip 10.0.2.1
 VersatilePB # set bootargs root=/dev/nfs nfsroot=10.0.2.1:/soft/nfs_share ip=10.0.2.2 mem=128M console=ttyAMA0 video=vc:1-2clcdfb:
 VersatilePB # cp 0x34080000 0x7fc0 0x00200000
 VersatilePB # bootm
 
 
 对于参数ip的解析具体由kernel中__setup("ip=", ip_auto_config_setup);函数完成
 对于参数ip的说明见Documentation/filesystems/nfsroot.txt
 ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>
 
 成功运行的log文件;
 # cat /etc/qemu-ifup
 #!/bin/sh
 /sbin/ifconfig $1 10.0.2.1
 # ./run_qemu
 
 
 U-Boot 2009.03-rc1 (Dec 02 2009 - 00:57:01)
 
 
 
 Code cloned from branch 090204_armdev of git://linux-arm.org/u-boot-armdev.git
 
 
 Release AEL-3.0
 Remote commit cloned   UNKNOWN
 Latest commit locally  UNKNOWN
 git state UNKNOWN
 DRAM:   0 kB
 pflash_write: Unimplemented flash cmd sequence (offset 00000000, wcycle 0x0 cmd 0x0 value 0xf0)
 pflash_write: Unimplemented flash cmd sequence (offset 00000000, wcycle 0x0 cmd 0x0 value 0x90)
 Flash: 64 MB
 *** Warning - bad CRC, using default environment
 
 In:    serial
 Out:   serial
 Err:   serial
 Hit any key to stop autoboot:  0
 VersatilePB # printenv
 bootargs=root=/dev/mtdblock0 mtdparts=armflash.0:7268k@0x02680000(cramfs) ip=dhcp mem=128M console=ttyAMA0 video=vc:1-2clcdfb:
 bootcmd=cp 0x36000000 0x7fc0 0x00200000 ; bootm
 bootdelay=2
 baudrate=38400
 bootfile="/tftpboot/uImage"
 stdin=serial
 stdout=serial
 stderr=serial
 verify=n
 
 Environment size: 280/8188 bytes
 VersatilePB # set ipaddr 10.0.2.2
 VersatilePB # set serverip 10.0.2.1
 VersatilePB # set bootargs root=/dev/nfs nfsroot=10.0.2.1:/soft/nfs_share ip=10.0.2.2 mem=128M console=ttyAMA0 video=vc:1-2clcdfb:
 VersatilePB # cp 0x34080000 0x7fc0 0x00200000
 VersatilePB # bootm
 ## Booting kernel from Legacy Image at 00007fc0 ...
 Image Name:   Linux-2.6.28-arm2
 Image Type:   ARM Linux Kernel Image (uncompressed)
 Data Size:    1523620 Bytes =  1.5 MB
 Load Address: 00008000
 Entry Point:  00008000
 Loading Kernel Image ... OK
 OK
 
 Starting kernel ...
 
 Uncompressing Linux............................................................................................... done, booting t he kernel.
 Linux version 2.6.28-arm2 () (gcc version 4.4.1 (Sourcery G++ Lite 2009q3-67) ) #1 Mon Nov 30 01:59:09 PST 2009
 CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00093177
 CPU: VIVT data cache, VIVT instruction cache
 Machine: ARM-Versatile PB
 Memory policy: ECC disabled, Data cache writeback
 Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 32512
 Kernel command line: root=/dev/nfs nfsroot=10.0.2.1:/soft/nfs_share ip=10.0.2.2 mem=128M console=ttyAMA0 video=vc:1-2clcdfb:
 PID hash table entries: 512 (order: 9, 2048 bytes)
 Console: colour dummy device 80x30
 Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
 Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
 Memory: 128MB = 128MB total
 Memory: 126704KB available (2656K code, 217K data, 100K init)
 SLUB: Genslabs=12, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
 Calibrating delay loop... 418.61 BogoMIPS (lpj=2093056)
 Mount-cache hash table entries: 512
 CPU: Testing write buffer coherency: ok
 net_namespace: 288 bytes
 NET: Registered protocol family 16
 NET: Registered protocol family 2
 IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
 TCP established hash table entries: 4096 (order: 3, 32768 bytes)
 TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
 TCP: Hash tables configured (established 4096 bind 4096)
 TCP reno registered
 NET: Registered protocol family 1
 JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
 msgmni has been set to 247
 io scheduler noop registered
 io scheduler anticipatory registered (default)
 io scheduler deadline registered
 io scheduler cfq registered
 CLCD: unknown LCD panel ID 0x00001000, using VGA
 CLCD: Versatile hardware, VGA display
 Clock CLCDCLK: setting VCO reg params: S=1 R=99 V=98
 Console: switching to colour frame buffer device 80x30
 Serial: AMBA PL011 UART driver
 dev:f1: ttyAMA0 at MMIO 0x101f1000 (irq = 12) is a AMBA/PL011
 console [ttyAMA0] enabled
 dev:f2: ttyAMA1 at MMIO 0x101f2000 (irq = 13) is a AMBA/PL011
 dev:f3: ttyAMA2 at MMIO 0x101f3000 (irq = 14) is a AMBA/PL011
 fpga:09: ttyAMA3 at MMIO 0x10009000 (irq = 38) is a AMBA/PL011
 smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre <nico@cam.org>
 eth0: SMC91C11xFD (rev 1) at c88da000 IRQ 25 [nowait]
 eth0: Ethernet addr: 52:54:00:12:34:56
 pflash_write: Unimplemented flash cmd sequence (offset 00000000, wcycle 0x0 cmd 0x0 value 0xf000f0)
 armflash.0: Found 1 x32 devices at 0x0 in 32-bit bank
 Intel/Sharp Extended Query Table at 0x0031
 pflash_write: Unimplemented flash cmd sequence (offset 00000000, wcycle 0x0 cmd 0x0 value 0xf0)
 Using buffer write method
 RedBoot partition parsing not available
 afs partition parsing not available
 mice: PS/2 mouse device common for all mice
 rtc-ds1307: probe of 0-0068 failed with error -5
 i2c /dev entries driver
 input: AT Raw Set 2 keyboard as /devices/fpga:06/serio0/input/input0
 mmc0: MMCI rev 0 cfg 00 at 0x0000000010005000 irq 22,33
 Advanced Linux Sound Architecture Driver Version 1.0.18rc3.
 ALSA device list:
 No soundcards found.
 TCP cubic registered
 NET: Registered protocol family 17
 RPC: Registered udp transport module.
 RPC: Registered tcp transport module.
 VFP support v0.3: implementor 41 architecture 1 part 10 variant 9 rev 0
 drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
 input: ImExPS/2 Generic Explorer Mouse as /devices/fpga:07/serio1/input/input1
 eth0: link up
 IP-Config: Guessing netmask 255.0.0.0
 IP-Config: Complete:
 device=eth0, addr=10.0.2.2, mask=255.0.0.0, gw=255.255.255.255,
 host=10.0.2.2, domain=, nis-domain=(none),
 bootserver=255.255.255.255, rootserver=10.0.2.1, rootpath=
 Looking up port of RPC 100003/2 on 10.0.2.1
 Looking up port of RPC 100005/1 on 10.0.2.1
 VFS: Mounted root (nfs filesystem).
 Freeing init memory: 100K
 init started: BusyBox v1.14.3 (2009-11-12 11:03:55 GMT)
 starting pid 325, tty '': '/etc/rc.d/rc.local'
 warning: can't open /etc/mtab: No such file or directory
 mount: mount point /proc does not exist
 mount: mount point /sys does not exist
 mount: mount point /tmp does not exist
 Thu Jan  1 00:00:23 UTC 1970
 S: devpts
 Thu Jan  1 00:00:23 UTC 1970
 S: udev
 Thu Jan  1 00:00:24 UTC 1970
 S: sshd
 PRNG is not seeded
 Thu Jan  1 00:00:28 UTC 1970
 S: dbus id
 Thu Jan  1 00:00:28 UTC 1970
 S: hald
 Thu Jan  1 00:00:29 UTC 1970
 S: Xorg
 Thu Jan  1 00:00:29 UTC 1970
 R: Xorg
 Thu Jan  1 00:00:29 UTC 1970
 S: dhcdbd
 Found no /etc/resolv.conf you need one for e.g. browser to resolve URLs
 Thu Jan  1 00:00:29 UTC 1970
 S: ohmd
 359
 No /proc/asound/cards file present
 starting pid 363, tty '': '/sbin/getty -L ttySA0 38400 vt100'
 
 AEL login: root
 login: can't chdir to home directory '/root'
 
 
 BusyBox v1.14.3 (2009-11-12 11:03:55 GMT) built-in shell (ash)
 Enter 'help' for a list of built-in commands.
 
 # ls
 | 
 |