计算机技術文摘

uClibc+BusyBox 的测试

uClibc和BusyBox已经编译好了,在把它们加入固件之前最好先测试一下。测试方法是建立一个模拟的根文件系统,通过chroot命令来建立一个新的执行环境,在这个环境下所执行的命令以及动态连接库都来自于这个模拟的根文件系统。

模拟根文件系统的制作方法(在PC上执行):
准备一个U盘或移动硬盘,格式化成ext3文件系统。
假设编译好的uClibc和BusyBox分别放在/home/user/dist/uclibc和/home/user/dist/busybox目录下,U盘挂载在/media/disk下。
执行下列的命令来制作测试U盘:
1 $ cp -a /home/user/dist/uclibc/lib /media/disk
2 $ cp -a /home/user/dist/busybox/* /media/disk
3 $ cd /media/disk
4 $ mkdir proc dev var tmp

制作好的U盘将有如下的文件列表:
  1 $ ls -lR                        
  2 .:                               
  3 total 32                         
  4 drwxr-xr-x 2 user users 4096 2010-03-18 13:47 bin
  5 drwxr-xr-x 2 user users 4096 2010-03-18 22:39 dev
  6 drwxr-xr-x 2 user users 4096 2010-03-18 13:47 lib
  7 drwxr-xr-x 2 user users 4096 2010-03-18 22:39 proc
  8 drwxr-xr-x 2 user users 4096 2010-03-18 22:09 sbin
  9 drwxr-xr-x 2 user users 4096 2010-03-18 22:39 tmp
 10 drwxr-xr-x 4 user users 4096 2010-03-18 22:08 usr
 11 drwxr-xr-x 2 user users 4096 2010-03-18 22:39 var
 12
 13 ./bin:
 14 total 720
 15 lrwxrwxrwx 1 user users      7 2010-03-18 22:07 ash -> busybox
 16 -rwxr-xr-x 1 user users 732460 2010-03-18 13:47 busybox      
 17 lrwxrwxrwx 1 user users      7 2010-03-18 22:07 cat -> busybox
 18 lrwxrwxrwx 1 user users      7 2010-03-18 22:07 chmod -> busybox
 19 lrwxrwxrwx 1 user users      7 2010-03-18 22:07 chown -> busybox
 20 lrwxrwxrwx 1 user users      7 2010-03-18 22:07 cp -> busybox  
 21 lrwxrwxrwx 1 user users      7 2010-03-18 22:07 date -> busybox
 22 略去若干行                                               
 23 lrwxrwxrwx 1 user users      7 2010-03-18 22:07 umount -> busybox
 24 lrwxrwxrwx 1 user users      7 2010-03-18 22:07 uname -> busybox
 25 lrwxrwxrwx 1 user users      7 2010-03-18 22:07 usleep -> busybox
 26 lrwxrwxrwx 1 user users      7 2010-03-18 22:07 vi -> busybox   
 27 lrwxrwxrwx 1 user users      7 2010-03-18 22:07 zcat -> busybox 
 28
 29 ./dev:
 30 total 0
 31
 32 ./lib:
 33 total 720
 34 -rwxr-xr-x 1 user users  21232 2010-03-18 13:47 ld-uClibc-0.9.28.so
 35 lrwxrwxrwx 1 user users     19 2010-03-18 22:07 ld-uClibc.so.0 -> ld-uClibc-0.9.28.so
 36 -rw-r--r-- 1 user users  11920 2010-03-18 13:27 libcrypt-0.9.28.so                  
 37 lrwxrwxrwx 1 user users     18 2010-03-18 22:07 libcrypt.so.0 -> libcrypt-0.9.28.so 
 38 lrwxrwxrwx 1 user users     19 2010-03-18 22:07 libc.so.0 -> libuClibc-0.9.28.so    
 39 -rw-r--r-- 1 user users   7732 2010-03-18 13:27 libdl-0.9.28.so                     
 40 lrwxrwxrwx 1 user users     15 2010-03-18 22:07 libdl.so.0 -> libdl-0.9.28.so       
 41 -rw-r--r-- 1 user users 134884 2010-03-18 13:27 libm-0.9.28.so                      
 42 lrwxrwxrwx 1 user users     14 2010-03-18 22:07 libm.so.0 -> libm-0.9.28.so         
 43 -rw-r--r-- 1 user users   1556 2010-03-18 13:27 libnsl-0.9.28.so                    
 44 lrwxrwxrwx 1 user users     16 2010-03-18 22:07 libnsl.so.0 -> libnsl-0.9.28.so     
 45 -rw-r--r-- 1 user users  82864 2010-03-18 13:27 libpthread-0.9.28.so                
 46 lrwxrwxrwx 1 user users     20 2010-03-18 22:07 libpthread.so.0 -> libpthread-0.9.28.so
 47 -rw-r--r-- 1 user users   1556 2010-03-18 13:27 libresolv-0.9.28.so                   
 48 lrwxrwxrwx 1 user users     19 2010-03-18 22:07 libresolv.so.0 -> libresolv-0.9.28.so 
 49 -rw-r--r-- 1 user users   4532 2010-03-18 13:27 librt-0.9.28.so                       
 50 lrwxrwxrwx 1 user users     15 2010-03-18 22:07 librt.so.0 -> librt-0.9.28.so         
 51 -rw-r--r-- 1 user users 432732 2010-03-18 13:27 libuClibc-0.9.28.so                   
 52 -rw-r--r-- 1 user users   4952 2010-03-18 13:27 libutil-0.9.28.so                     
 53 lrwxrwxrwx 1 user users     17 2010-03-18 22:07 libutil.so.0 -> libutil-0.9.28.so     
 54
 55 ./proc:
 56 total 0
 57
 58 ./sbin:
 59 total 0
 60 lrwxrwxrwx 1 user users 14 2010-03-18 22:07 blkid -> ../bin/busybox
 61 lrwxrwxrwx 1 user users 14 2010-03-18 22:07 devfsd -> ../bin/busybox
 62 lrwxrwxrwx 1 user users 14 2010-03-18 22:07 fdisk -> ../bin/busybox
 63 lrwxrwxrwx 1 user users 14 2010-03-18 22:07 fsck -> ../bin/busybox 
 64 略去若干行                                                   
 65 lrwxrwxrwx 1 user users 14 2010-03-18 22:07 route -> ../bin/busybox
 66 lrwxrwxrwx 1 user users 14 2010-03-18 22:07 swapoff -> ../bin/busybox
 67 lrwxrwxrwx 1 user users 14 2010-03-18 22:07 swapon -> ../bin/busybox
 68 lrwxrwxrwx 1 user users 14 2010-03-18 22:07 syslogd -> ../bin/busybox
 69 lrwxrwxrwx 1 user users 14 2010-03-18 22:07 udhcpc -> ../bin/busybox
 70
 71 ./tmp:
 72 total 0
 73
 74 ./usr:
 75 total 8
 76 drwxr-xr-x 2 user users 4096 2010-03-18 22:09 bin
 77 drwxr-xr-x 2 user users 4096 2010-03-18 22:10 sbin
 78
 79 ./usr/bin:
 80 total 0
 81 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 [ -> ../../bin/busybox
 82 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 [[ -> ../../bin/busybox
 83 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 awk -> ../../bin/busybox
 84 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 basename -> ../../bin/busybox
 85 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 bunzip2 -> ../../bin/busybox
 86 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 bzcat -> ../../bin/busybox
 87 略去若干行
 88 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 wc -> ../../bin/busybox
 89 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 wget -> ../../bin/busybox
 90 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 which -> ../../bin/busybox
 91 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 xargs -> ../../bin/busybox
 92 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 yes -> ../../bin/busybox
 93
 94 ./usr/sbin:
 95 total 0
 96 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 chroot -> ../../bin/busybox
 97 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 ftpd -> ../../bin/busybox
 98 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 httpd -> ../../bin/busybox
 99 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 inetd -> ../../bin/busybox
100 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 ntpd -> ../../bin/busybox
101 lrwxrwxrwx 1 user users 17 2010-03-18 22:08 telnetd -> ../../bin/busybox
102
103 ./var:
104 total 0
以下操作在播放机上执行
将U盘插入播放机,telnet到播放机,U盘应该已自动挂载到/tmp/usbmounts/sda1
1) 播放机默认将U盘挂载为只读模式,把它改为可读写模式
1 # mount -o remount,rw /tmp/usbmounts/sda1
2) 将/proc和/dev映射到模拟根文件系统。mount --bind 可将一个挂载点映射到另一个目录。
1 # mount --bind /proc /tmp/usbmounts/sda1/proc
2 # mount --bind /dev /tmp/usbmounts/sda1/dev
3) 复制/etc目录。chroot运行环境需要访问/etc下的文件。注意cp命令的大写的L参数,它使得符号连接作为普通文件拷贝。
1 # cp -rL /etc /tmp/usbmounts/sda1/
4) 执行chroot
 1 # chroot /tmp/usbmounts/sda1
 2
 3
 4 BusyBox v1.15.3 (2010-03-18 13:39:41 CST) built-in shell (ash)
 5 Enter 'help' for a list of built-in commands.
 6
 7 # ls
 8 bin   dev   etc   lib   proc  sbin  tmp   usr   var
 9 #

可以看到BusyBox的版本好已经是1.15.3了,ls命令也正常执行了,这说明uClibc和BusyBox都正常工作。你还可以测试一些其它命令。

5)退出chroot环境
1 # exit
2 # umount /tmp/usbmounts/sda1/proc
3 # umount /tmp/usbmounts/sda1/dev
4 # mount -o remount,ro /tmp/usbmounts/sda1

posted on 2010-03-19 22:50 计算机技术博客 阅读(528) 评论(0)  编辑 收藏 引用 所属分类: 1 Server技术7 系統維護8 網絡技術9 路由技术A 学习笔记

公告

http://www.nuanbb.com

导航

常用链接

随笔分类(255)

常用链接