BsyboxでLinux 2.6.24カーネルに基づくnfsルートファイルシステムを作成します。

55811 ワード

転載元:http://blog.csdn.net/flymachine/article/details/7000447
======================================================================================================================
一、ホスト環境
  Linux version 2.4.20-8、RedHat 9、VMWare 5.5.3;
  gcc version 3.4.4,Thread model:posix;
  GNU Make 3.81
  arm-linux-gcc 4.2.1(この作成過程は別紙を参照してください。
crosstoolスクリプトでLinux 2.6カーネルに対するクロスコンパイルツールチェーンをコンパイルします。
)  
必要なソースファイル:  busybox-1.11.tar.bz 2;
二、Busboxでnfsファイルシステムを作成する。
1、解凍busybox-1.11.tar.bz 2、経路は[[email protected]]菗pwd
//home/jacky/busybox-1.11.1
MakefilezのARCHとCROSS_を修正します。COMPILEは本機のルートと一致しています。(各プラットフォームは全部違っています。コピーしないでください。自分の状況によって記入します。または後ろのmake menuconfigの時に記入します):CROSS_COMPILE?= /opt/crosstool/bin/arm-s3c2410-linux-gnu-
...
ARCH ?= arm
2、busyboxをコンパイルします。先にmake menuconfigを行い、以下を修正します。Busybox Settings--->
    Build Options --->
        [*] Build BusyBox as astatic binary (no shared libs)
        // ,
        (/opt/crosstool/bin/arm-s3c2410-linux-gnu-) Cross Compiler prefix     --------- , Makefile
        // Makefile ,
    Installation Options --->
        [*] Don't use/usr
        //
Shells --->
    Choose your default shell (ash) --->
    // shell ash,
        --- ash
        // ash
セーブ終了、直接メーク、メークinstall。3、shellスクリプトでルートファイルシステムのディレクトリ構造を作成し、ルートファイルシステムを構築したいところでこのスクリプトを実行します。私はrootユーザーでログインして、直接にデバイスノードを作成しました。[root@Sureroot-s 3 c 2410]〹vimmakedir.sh#!/bin/sh
  echo "makeing rootdir"
  mkdir rootfs
  cd rootfs

  echo "makeing dir: bin dev etc lib proc sbin sys usr"
  mkdir bin dev etc lib proc sbin sys usr #8 dirs
  mkdir usr/bin usr/lib usr/sbin lib/modules

#Don't use mknod, unless you runthis Script as root
# , Linux PC ;
  mknod -m 600 dev/console c 5 1
  mknod -m 666 dev/null c 1 3

  echo "making dir: mnt tmp var"
  mkdir mnt tmp var
  chmod 1777 tmp
  mkdir mnt/etc mnt/jiffs2 mnt/yaffs mnt/data mnt/temp
  mkdir var/lib var/lock var/log var/run var/tmp
  chmod 1777 var/tmp

  echo "making dir: home root boot"
  mkdir home root boot
  echo "done"
このshを実行します
[root@Sureroot-s 3 c 2410]〹sh makedir.sh
メインフォルダのrootfsを作成しました。中にはいくつかのファイルがあります。
[root@Surerootfs.
ビン  ブック  dev  etc  ホーム  lib  mnt  proc  root  sbin  sys  tmp  アメリカ  var
4、busyboxのソースディレクトリの下のetcの内容をここのetcにコピーします。
[root@Surerootfs)29846;cd etc/
[root@Sureetc]荍cp-a/home/jacky/busybox-1.11/examples/boot flopy/etc/*.
5、コピーしたプロファイルを修正する
[root@Sureetc]菗vim profile#/etc/profile:system-wide.profile filefor the Bourne shells

echo "Processing /etc/profile"
# no-op

# Set search library path
echo " Set search library path"
export LD_LIBRARY_PATH=/lib:/usr/lib

# Set user path
echo " Set user path"
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

# Set PS1
echo " Set PS1"
HOSTNAME=`/bin/hostname`
shell host 。 `, ’,
Jacky

export PS1="\\e[32m[$USER@$HOSTNAME \\w\\a]\\$\\e[00;37m "
\\e[32m “[$USER@$HOSTNAME \\w\\a]
\\e[00
\\e[05
37m
echo 「All done!」echo
6、初期化ファイルinittabとfstabを修正する。root@Sureetc]璝vim inittab::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh
::restart:/sbin/init

tty2::askfirst:-/bin/sh
::ctrlaltdel:/bin/umount--r
::shutdown:/bin/umount--r
::shutdown:/sbin/swapoff –a
[root@Sureetc]29853;vim fstabproc /proc proc defaults 0 0
none /tmp ramfs defaults 0 0
mdev /dev ramfs defaults 0 0
sysfs /sys sysfs defaults 0 0
7、初期化されたスクリプトファイルinit.d/rcsを修正する[root@Sureetc]璝vim init.d/rcs#!/bin/sh
echo "Processing etc/init.d/rc.S"

#hostname ${HOSTNAME}

echo " Mount all"
/bin/mount -a

echo " Start mdev...."
/bin/echo /sbin/mdev > proc/sys/kernel/hotplug
mdev -s

echo "****************************************************"
echo " RootFS by NFS, s3c2410"
echo " Created by Jacky Xu @ 2008.7.13"
echo " Enjoy it!!!"
echo "****************************************************"
echo
8、空きmdev.co nfファイルを作成し、ルートファイルシステムをマウントする際に使用する[root@Sureetc]萼touch mdev.co 9、本機からpasswd、show、groupファイルをコピーします。[root@Sureetc]33166;cp/etc/passwd.[root@Sureetc]33852;cp/etc/show.[root@Sureetc.⑵菗cp/etc/group.passwdファイルを修正して、最初の行と最後の行のbashをshに修正します。10、ここのrootfsには、busyboxのデフォルトのインストールディレクトリのファイルを全部コピーします。Linuxrc->bin/busyboxファイルが多く発見されます。これはファイルシステムをマウントするために実行されます。[root@Sureetc.[root@Surerootfs;膌cp-Rfv/home/jacky/busybox-1.11.1/_install/.
OKです。以上はbusyboxで基本的なファイルシステムを作成しました。PS:    busyboxをコンパイルするときにダイナミックライブラリ方式を選択してコンパイルすると、生成したbusyboxがどのダイナミックライブラリを使用しているかを確認して、rootfs/libディレクトリにコピーする必要があります。[root@Surelib]((zhi arm-s 3 c 2410-linux-gnu-readelf-d./bin/busybox)Dynamic section at offset 0xc1014 contains 21 entries:
  Tag Type Name/Value
 0x00000001 (NEEDED) Shared library:[libm.so.6]
 0x00000001 (NEEDED) Shared library:[libc.so.6]
 0x0000000c (INIT) 0xc2ec
 0x0000000d (FINI) 0xa96b8
 0x00000004 (HASH) 0x80e8
 0x00000005 (STRTAB) 0xa4c4
 0x00000006 (SYMTAB) 0x8b64
 0x0000000a (STRSZ) 3505(bytes)
 0x0000000b (SYMENT) 16(bytes)
 0x00000015 (DEBUG) 0x0
 0x00000003 (PLTGOT) 0xd10e4
 0x00000002 (PLTRELSZ) 3112(bytes)
 0x00000014 (PLTREL) REL
 0x00000017 (JMPREL) 0xb6c4
 0x00000011 (REL) 0xb674
 0x00000012 (RELSZ) 80(bytes)
 0x00000013 (RELENT) 8(bytes)
 0x6ffffffe (VERNEED) 0xb5a4
 0x6fffffff (VERNEEDNUM) 2
 0x6ffffff0 (VERSYM) 0xb276
 0x00000000 (NULL) 0x0
libm.so.6とlibc.so.6の2つのライブラリを使用していることが分かります。この二つのライブラリをコピーするだけでは足りないことが分かりました。またld-linux.so.2とlibgcc_が必要です。s.so.1、つまり私がコンパイルしたこのbusyboxは4つのダイナミックライブラリファイルが必要です。cp/opt/crosstool/arm-s 3 c 2410-linux-gnu/sys-root/lib/libm.so.6.cp/opt/crosstool/arm-s 3 c 2410-linux-gnu/sys-root/lib/lib/lib.sold.sl/sc 2 p/opt/crosstool/arm-s 3 c 2410-linux-gnu/libgcc_s.so.1.このように、ダイナミックライブラリを使うと、半分ぐらいのスペースが節約できますが、効率が低下します。
三、テスト1、本機で修正/etc/exportファイルを修正し、NFSサービスを再起動する:root@Surerootfs;落vim/etc/exports/home/jacky/root-s 3 c 2410/rootfs 192.168.1.*(rw,sync,nouroot倈sh)[root@Surerootfs)玣service nfs retart 2、Bootloaderで以下のパラメータを伝えます。Kernel:root=/dev/nfs rw nfsroot=192.168.1.249:/home/jacky/root-s 3 c 2410/rootfs ip=192.168.1.249:192.168.1.1:255.255.00:Jackoff=200Boot Parameters: root=/dev/nfs rw nfsroot=192.168.1.249:/home/jacky/root-s3c2410/rootfs ip=192.168.1.199:192.168.1.249:192.168.1.1:255.255.255.0:Jacky:eth0:off console=ttySAC0,115200 init=/linuxrc noinitrd
Now, booting Linux...
Uncompressing Linux........................................................................................................... done, booting the kernel.
Linux version 2.6.24.7(root@Sure)(gcc version 4.2.1)#5 Sat Jul 12 17:26:16 CST 2008
CPU: ARM920T [41129200] revision 0(ARMv4T), cr=c0007177
Machine: SMDK2410
ATAG_INITRD is deprecated; please update your bootloader.
Memory policy: ECC disabled, Data cache writeback
CPU S3C2410A (id 0x32410002)
S3C2410: core 200.000 MHz, memory 100.000 MHz, peripheral 50.000 MHz
S3C24XX Clocks, (c) 2004 Simtec Electronics
CLOCK: Slow mode(1.500 MHz), fast, MPLL on, UPLL on
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 in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: root=/dev/nfs rw nfsroot=192.168.1.249:/home/jacky/root-s3c2410/rootfs ip=192.168.1.199:192.168.1.249:192.168.1.1:255.255.255.0:Jacky:eth0:off console=ttySAC0,115200 init=/linuxrc noinitrd
irq: clearing subpending status 00000003
PID hash table entries: 256 (order: 8, 1024 bytes)
timer tcon=00000000, tcnt a2c1, tcfg 00000200,00000000, usec 00001eb8
Console: colour dummy device 80x30
console [ttySAC0] enabled
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096(order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 61440KB available (3048K code, 314K data, 128K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 64 bytes
NET: Registered protocol family 16
S3C2410 Power Management, (c) 2004 Simtec Electronics
S3C2410: Initialising architecture
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4800000, irq 33
DMA channel 1 at c4800040, irq 34
DMA channel 2 at c4800080, irq 35
DMA channel 3 at c48000c0, irq 36
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
Bluetooth: Core ver 2.11
NET: Registered protocol family 31
Bluetooth: HCI device and connection manager initialized
Bluetooth: HCI socket layer initialized
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048(order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NetWinder Floating Point Emulator V0.97 (double precision)
JFFS2 version 2.2.(NAND) Â© 2001-2006 Red Hat, Inc.
JFS: nTxBlock = 480, nTxLock= 3840
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
s3c2410-lcd s3c2410-lcd: no platform datafor lcd, cannot attach
s3c2410-lcd: probe of s3c2410-lcd failed witherror -22
lp: driver loaded but no devices found
ppdev: user-space parallel port driver
Serial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing enabled
s3c2410-uart.0: s3c2410_serial0 at MMIO 0x50000000(irq = 70) is a S3C2410
s3c2410-uart.1: s3c2410_serial1 at MMIO 0x50004000(irq = 73) is a S3C2410
s3c2410-uart.2: s3c2410_serial2 at MMIO 0x50008000(irq = 76) is a S3C2410
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
loop: module loaded
Cirrus Logic CS8900A driver for Linux (Modified for SMDK2410)
eth0: CS8900A rev E at 0xe0000300 irq=53, addr: 00: 0:3E:26:0A: 0
Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2
ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2410-nand s3c2410-nand: Tacls=3, 30ns Twrph0=7 70ns, Twrph1=3 30ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76(Samsung NAND 64MiB 3,3V 8-bit)
Scanning device for bad blocks
Creating 5 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00100000 : "Bootloader"
0x00100000-0x00400000 : "Kernel"
0x00400000-0x03400000 : "Root"
0x03400000-0x03fe0000 : "ExtRoot"
0x03fe0000-0x04000000 : "Param"
usbmon: debugfs is not available
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci:new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
mice: PS/2 mouse device commonfor all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c2410-i2c s3c2410-i2c: slave address 0x10
s3c2410-i2c s3c2410-i2c: bus frequencyset to 390 KHz
s3c2410-i2c s3c2410-i2c: i2c-0: S3C I2C adapter
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive,reset disabled, irq enabled
TCP cubic registered
NET: Registered protocol family 1
NET: Registered protocol family 17
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
drivers/rtc/hctosys.c: unable toopen rtc device (rtc0)
IP-Config: Complete:
      device=eth0, addr=192.168.1.199, mask=255.255.255.0, gw=192.168.1.1,
     host=Jacky, domain=, nis-domain=(none),
     bootserver=192.168.1.249, rootserver=192.168.1.249, rootpath=
Looking up port of RPC 100003/2 on 192.168.1.249
Looking up port of RPC 100005/1 on 192.168.1.249
VFS: Mounted root (nfs filesystem).
Freeing init memory: 128K
init started: BusyBox v1.11.1(2008-07-13 14:46:21 CST)
starting pid 789, tty '': '/etc/init.d/rcS'
Processing etc/init.d/rc.S
  Mount all
  Start mdev....
****************************************************
              RootFS by NFS, s3c2410
         Created by Jacky Xu @ 2008.7.13
                   Enjoy 
****************************************************

starting pid 793, tty '': '-/bin/sh'
Processing /etc/profile
  Set search library path
  Set user path
  Set PS1
All 

[root@Jacky /]# ls
bin dev home linuxrc proc sbin tmp var
boot etc lib mnt root sys usr
[root@Jacky /]#
, arm-linux-gcc strip , 。例:铉arm-linux-strip/home/ス/rootfs/lib/*.そしてクロスコンパイラ4.3.2のlibはどこで探しますか?以前はusr/local/arm/4.3.2/arm-non-linux-gnueabi/libc/lib下の*.soファイルをrootfs/lib/下に揃えましたが、ダウンロードしたら「Kernel panic」に戻ります。 - not syncing: attempted to キルイット!」エラーメッセージ。その後、ライブラリのリンクが問題になる可能性があると思いました。usr/local/arm/4.3.2/arm-non-linux-gnueabi/libc/armv 4 t/lib下のファイルを再コピーしました。問題は解決します。 
直接nfsファイルシステムに入りました。