使用busybox-1.13.3 创建Linux根文件系统

转载 2012年03月25日 00:52:26

  首先我使用的busybox是1.13.3版本!此制作过程也是参考网络上各位高手的文章,加上自己的摸索与尝试,在此留下必要的札记。

1:配置Busybox

进入解压后的目录,配置Busybox
[~busybox-1.13.3]#make menuconfig

###############################################################
 Busybox Settings >
 General Configuration >
 [*] Support for devfs
 Build Options >
 [*] Build BusyBox as a static binary (no shared libs)
/* 将busybox编译为静态连接,少了启动时找动态库的麻烦 */
 [*] Do you want to build BusyBox with a Cross Compiler?
 (/usr/local/arm/3.4.1/bin/arm-linux-)
 Cross Compiler prefix
/* 指定交叉编译工具路径 */
 Init Utilities >
 [*] init
 [*] Support reading an inittab file
/* 支持init读取/etc/inittab配置文件,一定要选上 */
 Shells >
 Choose your default shell (ash) >
/* (X) ash 选中ash,这样生成的时候才会生成bin/sh文件
* 看看我们前头的linuxrc脚本的头一句:
* #!/bin/sh 是由bin/sh来解释执行的
*/
[*] ash
###################################################################################
另外,按照他的这种方法做出来的文件系统,运行的时候 shell 并不好有,没有历史记录、自动补全、删除字符的功能,下面介绍如何为它添加这些功能: 
               Shells ---> 
---   Bourne Shell Options                                            
   [ ]   Hide message on interactive shell startup                    
   [ ]   Standalone shell                                             
   [*]   command line editing                                         
   [*]     vi-style line editing commands                             
      (15)    history size                                           
   [*]     history saving                                             
   [*]     tab completion                                             
   [*]       username completion                                     
   [ ]     Fancy shell prompts
###################################################################################
 Coreutils >
[*] cp
[*] cat
[*] ls
[*] mkdir
[*] echo (basic SuSv3 version taking no options)
[*] env
[*] mv
[*] pwd
[*] rm
[*] touch
Editors >
[*] vi
Linux System Utilities >
[*] mount
[*] umount
[*] Support loopback mounts
[*] Support for the old /etc/mtab file
Networking Utilities >
##########################################################
 Linux Module Utilities  ---> 
        
[*] insmod                  
        
[*] rmmod                                   
        
[*] lsmod                   
        
[*]   lsmod pretty output for 2.6.x Linux kernels                     
        
[*] modprobe                                             
       
[*]   Multiple options parsing               
                     ---   Options common to multiple modutils               
        
[*]   Support tainted module checking with new kernels             
       
[ ]   Support version 2.2.x to 2.4.x Linux kernels    //此项一定不要选!!!
       
[*]   Support version 2.6.x Linux kernels                                         
########################################################################
退出并保存config选项。然后:
[~busybox-1.13.3]#export PATH={交叉编译器路径}:$PATH
[~busybox-1.13.3]#make ARCH=arm CROSS_COMPILE=arm-linux-    install
此处的选项ARCH、CROSS_COMPILE是为了明确目标平台以及所使用的交叉编译器。非此版本的Busybox有可能不是ARCH或CROSS_COMPILE,具体名称可以从Makefile中可以找到。
 
编译完成后,在_install目录下会生成目标平台的相关根文件。
 
以下说明并没有真正确认过其可行性,在此不做详细解释。
如果你是使用的1.4以上的版本,交叉编译同编译内核一样,需要修改Makefile中的arch=arm     CROSS_COMPILE=arm-linux-
然后#make xconfig
#make
#make install


2.用shell脚本创建根文件系统的目录结构,并在想要建立根文件系统的地方运行此脚本

sh脚本文件build_fs.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 run this Script as 
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: 
[~busybox-1.13.3]#./build_fs.sh 
makeing rootdir 
makeing dir: bin dev etc lib proc sbin sys usr 
making dir: mnt tmp var 
making dir: home root boot 
done 
创建出一个主文件夹rootfs,里面有一批文件: 
[~busybox-1.13.3]# cd rootfs/ 
[~rootfs]# ls 
bin boot dev etc home lib mnt proc root sbin sys tmp usr var 
 
4、把busybox源码目录下的etc的内容拷贝到这里的etc下 
[~rootfs]# cd etc/ 
[~etc]# ls 
[~etc]# cp -a /opt/develop/lyj/common/porting/rootfs/busybox-1.12.2/examples/bootfloppy/etc/* ./ 
[~etc]# ls 
fstab init.d inittab profile 
 
5、修改拷贝过来的profile文件 
[~etc]# vi profile 
# /etc/profile: system-wide .profile file for 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 
Inittab 
[~etc]# vi inittab 
::sysinit:/etc/init.d/rcS 
::respawn:-/bin/sh 
::restart:/sbin/init 
tty2::askfirst:-/bin/sh 
::ctrlaltdel:/bin/umount -a -r 
::shutdown:/bin/umount -a -r 
::shutdown:/sbin/swapoff –a 
Fstab 
[~etc]# vim fstab 
proc /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 
 
[~etc]# vi init.d/rcS 
#! /bin/sh 
echo "Processing etc/init.d/rc.S" 
#hostname ${HOSTNAME} 
hostname quickengine-tech
echo " Mount all" 
/bin/mount -a 
echo " Start mdev...." 
/bin/echo /sbin/mdev > proc/sys/kernel/hotplug 
mdev -s 
echo "****************************************************" 
echo " rootfs by NFS, s3c2440" 
echo " Created by Anson Liu@ 2009.11.05" 
echo " Good Luck" 
echo " www.quickengine-tech.com
echo "****************************************************" 
echo 
 

8、创建一个空的mdev.conf文件,在挂载根文件系统时会用到的 
[~etc]# touch mdev.conf

9、从本机拷贝passwd、shadow、group文件。 
[~ etc]# cp /etc/passwd . 
[~etc]# cp /etc/shadow . 
[~etc]# cp /etc/group . 
修改passwd文件,把第一行和最后一行的bash修改成ash。 
 
10、把busybox默认安装目录中的文件全部复制到这里的rootfs中。

会发现多了linuxrc -> bin/busybox文件,这是挂载文件系。 
[~etc]# cd .. 
[~rootfs]# cp -Rfv /opt/develop/lyj/common/porting/rootfs/busybox-1.12.2/_install/* ./

OK,以上用busybox创建了一个基本的文件系统。 
PS: 
如果编译busybox时选择动态库方式编译,则需要查看生成的busybox使用哪些动态库,然后把它们拷贝到rootfs/lib目录下。 
[~lib]# arm-linux-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两个库。发现只拷贝这两个库还不够,还需要ld-linux.so.2和libgcc_s.so.1,也就是我编译出来的这个busybox需要4个动态库文件。 
# cp /opt/crosstools/gcc-3.4.6-glibc-2.3.6/lib/libm.so.6 . 
# cp /opt/crosstools/gcc-3.4.6-glibc-2.3.6/lib/libc.so.6 . 
# cp /opt/crosstools/gcc-3.4.6-glibc-2.3.6/lib/ld-linux.so.2 . 
# cp /opt/crosstools/gcc-3.4.6-glibc-2.3.6/lib/libgcc_s.so.1 . 
这样,使用动态库可以节省一半左右的空间,不过效率有所降低。

准备链接库 
#cd ${OBJ_LIB}/lib (${OBJ_LIB}是交叉编译环境的目录) 
#for file in libc libcrypt libdl libm / 
>libpthread libresolv libutil 
>do 
>cp $file-*.so /home/fortis/rootfs/lib
>cp -d $file.so.[*0-9] /home/fortis/rootfs/lib
>done 
#cp -d ld*.so* /home/fortis/rootfs/lib

11.测试

1)、在本机修改/etc/export文件,重启NFS服务: 
[root@vm-dev root]# vi /etc/exports
/opt/lyj             192.168.1.*(rw,insecure,sync,no_root_squash)
/opt/develop/lyj/common/porting/rootfs/root_stand/reset/rootfs             192.168.1.*(rw,insecure,sync,no_root_squash)
[root@vm-dev root]# service nfs restart
 
2)、在Bootloader中传递以下参数给Kernel:
root=/dev/nfs rw nfsroot=192.168.1.152:/opt/develop/lyj/common/porting/rootfs/root_stand/reset/rootfs ip=192.168.1.155:192.168.1.152:192.168.1.254:255.255.255.0:Jacky:eth0:off console=ttySAC0,115200 init=/linuxrc noinitrd
 
3)、启动目标板,串口输出显示根文件系统已经加载成功: 
U-Boot 1.3.2 (Nov 27 2016 - 17:43:03)
 
DRAM:  64 MB
Flash: 512 kB
NAND:  64 MiB
In:    serial
Out:   serial
Err:   serial
Found DM9000 ID:90000a46 at address 10000000 !
DM9000 work in 16 bus width
bd->bi_entaddr: 08:00:3e:26:0a:5b
[eth_init]MAC:8:0:3e:26:a:5b:
Hit any key to stop autoboot:  0 
 
NAND read: device 0 offset 0x80000, size 0x1b0000
 1769472 bytes read: OK
## Booting image at 30008000 ...
   Image Name:   Linux-2.6.24.4
   Created:      2016-11-27   7:24:11 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1697964 Bytes =  1.6 MB
   Load Address: 30008000
   Entry Point:  30008040
   Verifying Checksum ... OK
test:hdr->ih_type:2
test:hdr->ih_comp:0
   XIP Kernel Image ... OK
test:hdr->ih_type:2
test:hdr->ih_os:5
 
Starting kernel ...
 
test:machid:805306624
test: bi_boot_params:0x33f5bfb8
test:starting 1
Uncompressing Linux............................................................................................................ done, booting the kernel.
Linux version 2.6.24.4 (root@vm-dev) (gcc version 3.4.6) #94 Thu Nov 27 10:02:26 CST 2008
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177
Machine: SMDK2410
Memory policy: ECC disabled, Data cache writeback
CPU S3C2410A (id 0x32410002)
S3C2410: core 202.800 MHz, memory 101.400 MHz, peripheral 50.700 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.152:/opt/develop/lyj/common/porting/rootfs/root_stand/reset/rootfs ip=192.168.1.155:192.168.1.152:192.168.1.254:255.255.255.0:Jacky:eth0:off console=ttySAC0,115200 init=/linuxrc noinitrd
irq: clearing subpending status 00000002
PID hash table entries: 256 (order: 8, 1024 bytes)
timer tcon=00500000, tcnt a509, tcfg 00000200,00000000, usec 00001e4c
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: 61324KB available (3088K code, 316K data, 132K 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
SCSI subsystem initialized
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: 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)
yaffs Nov 27 2008 09:58:27 Installing. 
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 80x30
fb0: s3c2410fb frame buffer device
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
DM9000: dm9k_init_module
Board init for dm9000a finished!
<DM9KS> I/O: c480e000, VID: 90000a46 
eth0: at 0xc480e000 IRQ 18
eth0: Ethernet addr: 08:00:3e:26:0a:5b
Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2
ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx
Driver 'sd' needs updating - please use bus_type methods
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2410-nand s3c2410-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
NAND_ECC_NONE selected by board driver. This is not recommended !!
Scanning device for bad blocks
Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00080000 : "Boot Agent"
0x00080000-0x00280000 : "S3C2410 kernel"
0x00280000-0x00680000 : "S3C2410 rootfs"
0x00680000-0x04000000 : "user"
usbmon: debugfs is not available
116x: driver isp116x-hcd, 03 Nov 2005
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
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
mice: PS/2 mouse device common for all mice
s3c2410 TouchScreen successfully loaded
input: s3c2410 TouchScreen as /class/input/input0
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c2410-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c2410-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
i2c /dev entries driver
s3c2410-i2c s3c2410-i2c: slave address 0x10
s3c2410-i2c s3c2410-i2c: bus frequency set to 99 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
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
s3c2410-rtc s3c2410-rtc: hctosys: invalid date/time
IP-Config: Complete:
      device=eth0, addr=192.168.1.155, mask=255.255.255.0, gw=192.168.1.254,
     host=Jacky, domain=, nis-domain=(none),
     bootserver=192.168.1.152, rootserver=192.168.1.152, rootpath=
Looking up port of RPC 100003/2 on 192.168.1.152
Looking up port of RPC 100005/1 on 192.168.1.152
VFS: Mounted root (nfs filesystem).
Freeing init memory: 132K
init started: BusyBox v1.12.2 (2016-11-27 14:55:55 CST)
starting pid 785, tty '': '/etc/init.d/rcS'
Processing etc/init.d/rc.S
 Mount all
 Start mdev....
****************************************************
 rootfs by NFS, s3c2410
 Created by lyj_uptech @ 2008.11.28
 Good Luck
 www.up-tech.com
****************************************************
 
 
Please press Enter to activate this console. 
starting pid 790, tty '': '-/bin/sh'
 
Processing /etc/profile... Done
 
Processing /etc/profile
 Set search library path
 Set user path
 Set PS1
All done!
 
[root@up-tech /]# ls
bin      dev      home     linuxrc  proc     sbin     tmp      var
boot     etc      lib      mnt      root     sys      usr
[root@up-tech /]#
 
已经直接进入了nfs文件系统!

相关文章推荐

使用Busybox1.13.3制作 yaffs2根文件系统

还记得安装时在vivi中输入“loadyaffs root u”吗?这里的img文件就是根文件系统映像文件。 准备工具1:mkyaffs2image 用途:用来制作目标文件系统映像。 工具2:b...

使用Busybox1.13.3制作yaffs2根文件系统

使用Busybox1.13.3制作yaffs2根文件系统(hlhq转)2009-09-25 21:532009-09-13 14:42(从hlhq转来)准备工具1:mkyaffs2image用途:用来...

使用busybox制作linux根文件系统

内核版本: Linux-2.6.34.10 交叉编译器版本: arm-linux-gcc  3.4.1 操作系统平台: Linux   Fedora 12 开发板平台: 飞凌  OKI...

使用BusyBox制作linux根文件系统(CramFS+mdev)

操作系统:Ubuntu9.04 内核版本:linux-2.6.24.7   开发板:博创arm2410s     交叉编译工具:arm-linux-gcc-4.1.1  Bus...

busybox制作linux根文件系统

  • 2013-03-22 15:01
  • 245KB
  • 下载

使用BusyBox制作linux根文件系统(CramFS+mdev)

转载地址:http://blog.chinaunix.net/uid-23089249-id-34501.html 操作系统:Ubuntu9.04 内核版本:linux-2.6...

使用busybox制作Linux根文件系统

构建最简单的嵌入式Linux根文件系统,下面我们一步步教大家做起。。 硬件环境: S3C2440 软件环境:        Busybox-1.16.1        cross-4.3.2 ...

如何使用busybox编译和生成最简linux根文件系统(rootfs)

继前几天对uboot和内核编译进行了初步了解之后,昨天开始研究如何制作rootfs根文件系统。昨晚对busybox这个工具有了初步的了解,今天继续深入研究,终于成功的制作出了一套完整可用的最简linu...

使用BusyBox制作嵌入式Linux根文件系统

使用BusyBox制作嵌入式Linux根文件系统 STEP 1:构建目录结构  创建根文件系统目录,主要包括以下目录 /dev  /etc /lib  /usr  /var /proc /t...
  • yi412
  • yi412
  • 2015-06-08 21:10
  • 629

使用busybox构建linux根文件系统

转载地址:http://blog.chinaunix.net/uid-26310563-id-3168454.html 主机:Windows XP,VMware 8,Ubuntu 编译...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)