51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 3012|回复: 0
打印 上一主题 下一主题

[讨论] about busybox

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2006-5-27 08:55:08 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
What Does BusyBox Include?

If this talk about 70 utilities in one is making you curious, here are a few samples of what BusyBox includes. The web site given above has a complete list with documentation:

chmod, chown, chroot, lsmod, rmmod, insmod
dd, df, du, mkfs.minix, fsck.minix, mount, sfdisk
find, grep, sed, gzip, gunzip, tar
kill, killall, ps
cp, cut, mv, rm, ln, more, tr
nslookup, ping, telnet
init, syslogd, sh
Many of these utilities are reduced versions to fit in the 260KB total space mentioned above. For example, the sh shell doesn't support if/then/else statements or while loops, but it has enough built-in commands to handle simple startup shell scripts. Also, commands like init and tar have greatly reduced functionality, but they are sufficient to get the job done for many applications where you don't have space for the full-blown utility.

Compiling BusyBox

Adding BusyBox to your system is simple. First, obtain the source code by visiting ftp://ftp.lineo.com/pub/busybox and downloading the most recent version of the compressed tar file. As of this writing, the most recent version is the file busybox-0.45.tar.gz, but newer versions will probably be available by the time you read this. Work on BusyBox seems to progress at a steady pace.

After you've downloaded the tar file, place it in a working directory and use this command to untar the file:


tar xvzf busybox-0.45.tar.gz
Change to the newly created busybox directory (I write the name in lowercase this time to match the binary name) and enter the make command:


cd busybox-0.45
make
Now you're ready to test a few BusyBox commands. The busybox binary is located in the main busybox directory after you use the make command. In order to use a particular feature of BusyBox, execute the busybox binary with a command name as a parameter. For example, to use the ls command, from within the busybox-0.45 directory, enter:


./busybox ls
Or to use the lsmod command, enter:


./busybox lsmod
Additional command options can be placed after the command name. For example, to use the du command to view only the contents of the /etc directory tree, type this: ./busybox du /etc

Another important feature of BusyBox is that you can see a small on-line help screen for each utility that BusyBox replaces. Just use the --help option with the command. For example, to learn about the ls options that BusyBox supports, enter ./busybox ls --help

This displays the following help text:


BusyBox v0.45 (2000.05.17-20:38+0000) multi-call
binary -- GPL2

Usage: ls [-1acdelnpuxACF] [filenames...]

Options:
-ado not hide entries starting with .
-cwith -l: show ctime (the time of last
modification of file status information)
-dlist directory entries instead of contents
-elist both full date and full time
-luse a long listing format
-nlist numeric UIDs and GIDs instead of names
-pappend indicator (one of /=@|) to entries
-uwith -l: show access time (the time of last
access of the file)
-xlist entries by lines instead of by columns
-Ado not list implied . and ..
-Clist entries by columns
-Fappend indicator (one of */=@|) to entries
Installing BusyBox

BusyBox is most useful on a system without a set of regular Linux utility programs, but you'll probably be exploring it on a standard Linux system. Because of this, you should use the PREFIX variable when installing BusyBox. The installation process creates symbolic links for all the utilities that BusyBox supports. This allows you to enter ls instead of busybox ls. Suppose you had begun working with BusyBox in the /tmp directory (such that a directory called /tmp/busybox-0.45 was created by the tar command). Then, if you want to create symbolic links in the same area, use this command:


make PREFIX=/tmp/busybox-0.45 install
The /tmp/busybox-0.45 directory will then contain subdirectories named bin, sbin and usr, each with symbolic links to /bin/busybox. You'll also need to copy the busybox binary to /bin before using these symbolic links:


cp /tmp/busybox-0.45/busybox /bin
Now you're ready to explore the symbolic links in your BusyBox subdirectories. For example, change to the bin directory:


cd /tmp/busybox-0.45/bin
Then use the ls symbolic link with the --help option:


./ls --help
You see the same help text as indicated previously. This shows you that BusyBox is being used instead of the standard ls command on your Linux system.

BusyBox uses the GNU C library, or glibc, which can add substantially to the space requirements of an embedded system or boot disk. You might consider looking at alternate C libraries to save space. Examples include minix libc and newlibc. Another example that looks promising but doesn't yet support the full functionality of BusyBox is the uC-libc project from Rt-Control (see http://www.uclinux.org/). The maintainer of BusyBox, Erik Andersen, is currently working to enhance this mini C library so that it can be used to reduce the total size requirements for BusyBox.

Configuring BusyBox

The description of BusyBox so far is straightforward, but doesn't capture all that the program offers. Returning to the source code you un-tarred when you compiled BusyBox, load the file busybox.def.h into a text editor:


cd /tmp/busybox-0.45 vi busybox.def.h
The first part of this file (about the first 100 lines) contains #define statements for each utility capability that will be included in BusyBox. If you don't want to include the capabilities of one of these utilities, simply comment out that line. For example, if you don't need sed in the system you are using BusyBox on, comment out the line for sed using two forward slashes, like this:


//#define BB_SED
Commenting out a few of the larger utilities greatly reduces the size of the final busybox binary. For example, removing five complex programs (init, tar, sfdisk, gzip and gunzip) reduces the size of the busybox binary from 260KB to 155KB.

The second part of the busybox.def.h file (after a few explanatory comments) contains #define statements that activate or disable various features of BusyBox. Some of these features are intended to save memory, such as eliminating the use of the /proc file system, reducing the amount of on-line help provided and eliminating the use of regular expressions. Other #defines are specific to features of a single command. For example, you can eliminate the ability to create new tar files with the tar features of BusyBox. Unless you really need to shave off a couple more KB in the size of BusyBox, you shouldn't need to alter the #define options in the second section of the busybox.def.h file.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-9-20 12:26 , Processed in 0.067025 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表