11.3. BusyBox Operation

When you build BusyBox, you end up with a binary called, you guessed it, busybox. BusyBox can be invoked from the binary name itself, but it is more usually launched via a symlink. When BusyBox is invoked without command line parameters, it produces a list of the functions that were enabled via the configuration. Listing 11-3 shows such an output (it has been formatted slightly to fit the page width).

Listing 11-3. BusyBox Usage

root@coyote # ./busybox

BusyBox v1.01 (2005.12.03-18:00+0000) multi-call binary

Usage: busybox [function] [arguments]...

   or: [function] [arguments]...

  BusyBox is a multi-call binary that combines many common Unix

  utilities into a single executable. Most people will create a

  link to busybox for each function they wish to use and BusyBox

  will act like whatever it was invoked as!

Currently defined functions:

  [, ash, basename, bunzip2, busybox, bzcat, cat, chgrp, chmod,

   chown, chroot, chvt, clear, cmp, cp, cut, date, dd, deallocvt,

   df, dirname, dmesg, du, echo, egrep, env, expr, false, fgrep,

   find, free, grep, gunzip, gzip, halt, head, hexdump, hostname,

   id, ifconfig, init, install, kill, killall, klogd, linuxrc, ln,

   logger, ls, mkdir, mknod, mktemp, more, mount, mv, openvt, pidof,

   ping, pivot_root, poweroff, ps, pwd, readlink, reboot, reset,

   rm, rmdir, route, sed, sh, sleep, sort, strings, swapoff, swapon,

   sync, syslogd, tail, tar, tee, test, time, touch, tr, true, tty,

   umount, uname, uniq, unzip, uptime, usleep, vi, wc, wget, which,

   whoami, xargs, yes, zcat

From Listing 11-3, you can see the list of functions that are enabled in this BusyBox build. They are listed in alphabetical order from ash (a shell optimized for small memory footprint) to zcat, a utility used to decompress the contents of a compressed file. This is the default set of utilities enabled in this particular BusyBox snapshot.

To invoke a particular function, execute busybox with one of the defined functions passed on the command line. Thus, to display a listing of files in the current directory, execute this command:

[root@coyote]# ./busybox ls

Another important message from the BusyBox usage message in Listing 11-3 is the short description of the program. It describes BusyBox as a multicall binary, combining many common utilities into a single executable. This is the purpose of the symlinks mentioned earlier. BusyBox was intended to be invoked by a symlink named for the function it will perform. This removes the burden of having to type a two-word command to invoke a given function, and it presents the user with a set of familiar commands for the similarly named utilities. Listings 11-4 and 11-5 should make this clear.

Listing 11-4. BusyBox Symlink StructureTop Level

[root@coyote]$ ls -l /

total 12

drwxrwxr-x  2 root  root 4096 Dec  3 13:38 bin

lrwxrwxrwx  1 root  root   11 Dec  3 13:38 linuxrc -> bin/busybox

drwxrwxr-x  2 root  root 4096 Dec  3 13:38 sbin

drwxrwxr-x  4 root  root 4096 Dec  3 13:38 usr

Listing 11-4 shows the target directory structure as built by the BusyBox package via the make install command. The executable busybox file is found in the /bin directory, and symlinks have been populated throughout the rest of the structure pointing back to /bin/busybox. Listing 11-5 expands on the directory structure of Listing 11-4.

Listing 11-5. BusyBox Symlink StructureTree Detail

[root@coyote]$ tree

.

|-- bin

|   |-- ash -> busybox

|   |-- busybox

|   |-- cat -> busybox

|   |-- cp -> busybox

|   |-- ...

|   '-- zcat -> busybox

|-- linuxrc -> bin/busybox

|-- sbin

|   |-- halt -> ../bin/busybox

|   |-- ifconfig -> ../bin/busybox

|   |-- init -> ../bin/busybox

|   |-- klogd -> ../bin/busybox

|   |-- ...

|   '-- syslogd -> ../bin/busybox

'-- usr

    |-- bin

    |   |-- [ -> ../../bin/busybox

    |   |-- basename -> ../../bin/busybox

    |-- ...

    |   |-- xargs -> ../../bin/busybox

    |   '-- yes -> ../../bin/busybox

    '-- sbin

        '-- chroot -> ../../bin/busybox

The output of Listing 11-5 has been significantly truncated for readability and to avoid a three-page listing. Each line containing an ellipsis (...) indicates that this listing has been pruned to show only the first few and last few entries of that given directory. In actuality, more than 100 symlinks can be populated in these directories, depending on what functionality you have enabled using the BusyBox configuration utility.

Notice the busybox executable itself, the second entry from the /bin directory. Also in the /bin directory are symlinks pointing back to busybox for ash, cat, cp ... all the way to zcat. Again, the entries between cp and zcat have been omitted from this listing for readability. With this symlink structure, the user simply enters the actual name of the utility to invoke its functionality. For example, to configure a network interface using the busybox ifconfig utility, the user might enter a command similar to this:

$ ifconfig eth1 192.168.1.14

This would invoke the busybox executable through the ifconfig symlink. BusyBox examines how it was calledthat is, it reads argv[0] to determine what functionality is executed.

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату