文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Building Tiny Linux Systems with Busybox--Part I

Building Tiny Linux Systems with Busybox--Part I

时间:2006-02-25  来源:soloten

Skip navigation.
<noscript> </noscript>
Since 1994: The Original Monthly Magazine of the Linux Community
Subscribe  Now
  • Subscribe
  • Customer Service
  Magazine Advertise Community About Us  

Current Issue

Back IssuesApr 2006 [#144]Mar 2006 [#143]Feb 2006 [#142]Jan 2006 [#141]Dec 2005 [#140]Nov 2005 [#139]Oct 2005 [#138]Sep 2005 [#137]Aug 2005 [#136]Jul 2005 [#135]Jun 2005 [#134]May 2005 [#133]Apr 2005 [#132]Mar 2005 [#131]Feb 2005 [#130]Jan 2005 [#129]Dec 2004 [#128]Nov 2004 [#127]Oct 2004 [#126]Sep 2004 [#125]Aug 2004 [#124]Jul 2004 [#123]Jun 2004 [#122]May 2004 [#121]Apr 2004 [#120]Mar 2004 [#119]Feb 2004 [#118]Jan 2004 [#117]Dec 2003 [#116]Nov 2003 [#115]Oct 2003 [#114]Sep 2003 [#113]Aug 2003 [#112]Jul 2003 [#111]Jun 2003 [#110]May 2003 [#109]Apr 2003 [#108]Mar 2003 [#107]Feb 2003 [#106]Jan 2003 [#105]Dec 2002 [#104]Nov 2002 [#103]Oct 2002 [#102]Sep 2002 [#101]Aug 2002 [#100]Jul 2002 [#99]Jun 2002 [#98]May 2002 [#97]Apr 2002 [#96]Mar 2002 [#95]Feb 2002 [#94]Jan 2002 [#93]Dec 2001 [#92]Nov 2001 [#91]Oct 2001 [#90]Sep 2001 [#89]Aug 2001 [#88]Jul 2001 [#87]Jun 2001 [#86]May 2001 [#85]Apr 2001 [#84]Mar 2001 [#83]Feb 2001 [#82]Jan 2001 [#81]Dec 2000 [#80]Nov 2000 [#79]Oct 2000 [#78]Sep 2000 [#77]Aug 2000 [#76]Jul 2000 [#75]Jun 2000 [#74]May 2000 [#73]Apr 2000 [#72]Mar 2000 [#71]Feb 2000 [#70]Jan 2000 [#69]Dec 1999 [#68]Nov 1999 [#67]Oct 1999 [#66]Sep 1999 [#65]Aug 1999 [#64]Jul 1999 [#63]Jun 1999 [#62]May 1999 [#61]Apr 1999 [#60]Mar 1999 [#59]Feb 1999 [#58]Jan 1999 [#57]Dec 1998 [#56]Nov 1998 [#55]Oct 1998 [#54]Sep 1998 [#53]Aug 1998 [#52]Jul 1998 [#51]Jun 1998 [#50]May 1998 [#49]Apr 1998 [#48]Mar 1998 [#47]Feb 1998 [#46]Jan 1998 [#45]Dec 1997 [#44]Nov 1997 [#43]Oct 1997 [#42]Sep 1997 [#41]Aug 1997 [#40]Jul 1997 [#39]Jun 1997 [#38]May 1997 [#37]Apr 1997 [#36]Mar 1997 [#35]Feb 1997 [#34]Jan 1997 [#33]Dec 1996 [#32]Nov 1996 [#31]Oct 1996 [#30]Sep 1996 [#29]Aug 1996 [#28]Jul 1996 [#27]Jun 1996 [#26]May 1996 [#25]Apr 1996 [#24]Mar 1996 [#23]Feb 1996 [#22]Jan 1996 [#21]Dec 1995 [#20]Nov 1995 [#19]Oct 1995 [#18]Sep 1995 [#17]Aug 1995 [#16]Jul 1995 [#15]Jun 1995 [#14]May 1995 [#13]Apr 1995 [#12]Mar 1995 [#11]Feb 1995 [#10]Jan 1995 [#9]Dec 1994 [#8]Nov 1994 [#7]Oct 1994 [#6]Sep 1994 [#5]Aug 1994 [#4]Jun/Jul 1994 [#3]Apr/May 1994 [#2]Mar 1994 [#1]

Popular content

Today's:


All time:

Free eNewsletters

  • LJ Weekly Update
  • Searls' Suitwatch
  • TUX Desktop Watch

LJ Merchandise

  • T-shirts, mugs & more

Text Ad Five - zone 14

<noscript></noscript>

LJ Categories

- Audio/Video (251)
- Community (483)
- Education (73)
- Embedded (149)
- Hardware (172)
- HOWTOs (219)
- Industry News (567)
- International (139)
- Linux Journal (571)
- Miscellaneous (77)
- Product of the Day (161)
- Reviews (510)
- Security (231)
- Software (1184)
- SysAdmin (416)
- Webmaster (237)

Navigation

  • recent posts
  • categories
  • news aggregator
Home

Building Tiny Linux Systems with Busybox--Part I

By Bruce Perens on Tue, 2001-11-20 02:00. Hardware Create a Busybox single-floppy Linux system that includes a kernel, command-line environment and your application.

Because Linux is small and easy to customize, it's a fine kernel for embedded systems. But what about all of the other programs that are needed for a minimum functional GNU/Linux system? The minimum system installed by the Debian or Red Hat set-up disks, exclusive of the kernel, is about 40 megabytes in size. Busybox replaces the GNU/Linux distribution with a large set of command-line tools--all that are needed to boot and run a practical Linux system with networking--in a very small package.

The typical compiled size of Busybox on the i386 architecture is 256 to 500K total for all tools, depending on the C library used and how it is linked. This makes it easily possible to create a single-floppy Linux systems with a full-featured kernel, a command-line environment, plus your application.

I originally wrote Busybox in 1996 for the Debian GNU/Linux setup disk. The goal was to put a complete bootable system on a single floppy that would be both a rescue disk and an installer for the Debian system. A rescue disk is used to repair a Linux system when that system has become unbootable. Thus, a rescue disk needs to be able to boot the system and mount the hard disk file systems, and it must provide the command-line tools needed to bring the hard-disk root file system back to a bootable state. The Debian installer at the time I wrote Busybox was a Bourne shell script using dialogto provide a simple graphical interface on an ANSI terminal or the Linux console.

Since its creation, many people have added to and maintained Busybox, including members of the Debian Boot-Floppies team, the Linux Router Project and Lineo Corporation, where Eric Anderson maintains Busybox today. In the tradition of Free Software projects, contributions by other authors now make up the majority of the project. Busybox is a part of almost every commercial embedded Linux offerings, and is found in such diverse projects as the Kerbango Internet Radio and the IBM Wristwatch that runs Linux.

The name Busybox comes from a child's toy box with a telephone dial and anumber of knobs, buttons and other devices, all of which make noises when operated. This was called a busy boxin the past and is today commonly referred to as an activity center.

The Busybox source code can be found at www.busybox.lineo.com. By default, the Makefile provided builds a dynamic-link executable using the default libc library on your system. However, it is easily adapted to cross-compilation, and one can select static linking and other, specialized libc libraries by editing Makefile variables. Before you exercise the Makefile options or embed Busybox, you should build and run it on your host system just so that you can get familiar with it. If you are on a Linux system with the development tools installed, simply typing make should build it.

Once you build Busybox, it's time to learn about multi-call executable files. This is a trick we use to make Busybox small. There is one executable called busybox that is linked to 107 different names and provides the functions of 107 different programs. To illustrate this, run the following shell commands:

ln busybox ls
ln busybox uptime
ln busybox whoami


Now, run these commands:

./ls
./uptime
./whoami


Be sure to type the leading "./" as illustrated above, or you will get the system version of these commands rather than the Busybox version.

The lncommand is used to apply another name to a file. It does not copy the file. The only space it uses in the file system is the small amount that is necessary to store a name in a directory. You can illustrate this using the following ls command:

ls -il busybox ls uptime whoami


Be sure to use the -il argument to ls as above. This causes ls to print the inode number, a unique number identifying each file in a file system, along with the usual long listing provided by the -l argument. Linux allows the same file to have more than one name, but a file only has one inode number. You should see something similar to Listing 1.

1849054 -rwxrwxr-x 4 bruce bruce 252956 Sep 7 08:22 busybox
1849054 -rwxrwxr-x 4 bruce bruce 252956 Sep 7 08:22 ls
1849054 -rwxrwxr-x 4 bruce bruce 252956 Sep 7 08:22 uptime
1849054 -rwxrwxr-x 4 bruce bruce 252956 Sep 7 08:22 whoami

Note that this is not a listing of four files. It is a listing of one file with four names, as indicated by the inode number in the first column and the link count in the third column. The link count reports how many names a file has. You'll notice that directories in the common Linux file systems always have a link count of two, because they have two names: "." and "..". Most files, however, only have one name and their link count will be 1.

Because there is a fixed overhead of several kilobytes for every executable program, compressing 107 commands into one file saves a significant amount of space. So, just as we have linked Busybox to four different names, we can link it to 107. This provides us with a complete, bootable, runnable Linux system in a very small space. Even static-linking with GNU LIBC 6, which has become the standard for Linux systems, Busybox occupies only half a megabgyte.

If you don't need the internationalization of LIBC 6, the old LIBC 5 is significantly smaller. A new library intended for embedded use, uC-Libc (www.opensource.lineo.com), is even smaller, but use caution if your application is proprietary. Like Busybox, uC-Libc is covered by the GNU GPL (General Public License), and can't be linked to proprietary software. GNU LIBC 5 and 6, in contrast, are under the LGPL (the Lesser General Public License) and can be linked to proprietary applications. So, don't use uC-Libc for the libc library of a non-free program. At this writing, uC-Libc doesn't quite provide all of the functions required by Busybox, but it's only short a few and these may be provided by the time you read this article.

Table 1. Tools Provided

On the Debian install floppy, I linked Busybox dynamicaly, and then stripped down the shared libc library so that it only provided the functions necessary to support Busybox and the other executables on the floppy. This was the best way to provide a library shared by several different executables, since the floppy contained other programs besides Busybox. Stripping libc down to only the functions that actually were used cut its size by half. Rather than strip it by hand, I wrote a script that finds all of the library functions referenced by a set of dynamic executables, and then creates a library subset providing those functions (and the functions they depend on). This script has since been completely replaced by a version written by Marcus Brinkmann, which can be found in the Debian boot-floppies package under scripts/rootdisk/mklibs.sh. The script and how it works are properly the subject of another article the size of this one however, until that article is written, one can puzzle out how mklibs.sh works by installing the boot-floppies package on a Debian system, building the floppies and then reading the script carefully. Warning: mklibs.sh is probably the most complex shell script you will ever examine.

So, now that you know how to build and run Busybox, how do you make a small Linux system containing it? You'll need a few pieces: a static-linked Busybox executable, a skeleton root file system and /dev directory populated with the proper special files, and a Linux kernel with the features you need plus two features that will be used to boot and run a small Linux system: RAM disks and the compressed ROM file system. [Look for the details on how to build a small Linux system containing Busybox in a future issue--Ed.]

» add new comment | email this page | printer friendly version |

Search

Skyscraper Ad

<noscript></noscript>

Button 1 zone 6

<noscript></noscript>

Sponsored Links

 

Text ad 11/z21


Save test time and costs

NightStarLX, a powerful
set of debugging tools

for time-critical apps
<noscript></noscript>

Text ad 4 - zone 12


Improve IT Performance.

Learn how to cut cost with
out-of-band administration.

Read this White Paper.
<noscript></noscript>

Text Ad Eight - zone 17


Key console access tools

Secure console access puts
you in control of IT devices.

Read, Leading Best Practices
<noscript></noscript>

Text Ad One - zone 7


Virtual Private Servers

LAMP with Ruby & cPanel
From $29/mo - ROOT Access

www.ServerPowered.com
<noscript></noscript>

Text ad Six - zone 15


Monarch Empro 4-Way AMD

Opteron Custom Servers. Save
30% on power per CPU vs Intel

Build yours today!
<noscript></noscript>

Text ad twelve - zone 22

<noscript></noscript>
Magazine Subscriber Services Advertise Community Contact Us Privacy Statement  
Copyright © 1994 - 2006 SSC Media Corporation. All rights reserved.
Visit SSC's other sites:   TUX Magazine Linux Gazette Doc's IT Garage RSS Links
Read "News Feeds" from SSC's other sites:   News Feeds Report  Problems
相关阅读 更多 +
排行榜 更多 +
弓箭手战士酷跑

弓箭手战士酷跑

飞行射击 下载
三角洲行动全面战场攀升A点进攻指南

三角洲行动全面战场攀升A点进攻指南

飞行射击 下载
僵尸射手世界大战

僵尸射手世界大战

飞行射击 下载