万能コマンドBusyBoxを組み込み機器へ適用する方法や拡張の仕方、コミュニティとのかかわり方など、実践で役立つすべを伝授!
携帯電話やPDA(Personal Digital Assistant)、液晶テレビなど、組み込み機器にLinuxを使用するケースが増えてきました。皆さんも日ごろからLinux搭載の組み込み機器を知らず知らずのうちに使っているかもしれませんね。
本連載では、こうしたLinux搭載の組み込み機器には欠かせない存在ともいえる「BusyBox」について詳しく解説していきます。
「ちょっと待って、BusyBoxって何?」という方は本連載を読み進める前に、特集「組み込みLinuxで際立つ『BusyBox』の魅力」に目を通しておいてください。“BusyBoxの概要”について分かりやすくまとめてありますので、本連載を読み解くうえで必ずや役に立つと思います。
さて、本連載ではBusyBoxについて“より詳しく”解説していくわけですが、
の4つのテーマについて紹介していく予定です。
前置きはこれくらいにして、早速本題に入っていきましょう。記念すべき連載第1回は「BusyBoxのおさらい」と、BusyBoxを組み込み機器向けにコンパイルするのに必要な「クロスコンパイル環境の構築」について説明していきます。
| 関連リンク: | |
|---|---|
| ⇒ | 組み込みLinuxで際立つ「BusyBox」の魅力 |
まずは、BusyBoxについておさらいしておきましょう。
BusyBoxとは、いわゆるコマンドの集合体で、“busybox”という1つの実行ファイルで「ls」「cat」「vi」「httpd」といったさまざまなコマンドの機能を使うことができます。
以下は、BusyBoxのUsageを表示した一例ですが、“Currently defined functions:”以下に利用可能なコマンドが表示されています。
$ /bin/busybox
BusyBox v1.10.2 (2008-05-22 04:45:56 JST) multi-call binary
Copyright (C) 1998-2007 Erik Andersen, Rob Landley, Denys Vlasenko
and others. Licensed under GPLv2.
See source distribution for full notice.
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:
[, [[, addgroup, adduser, ar, arping, ash, awk, basename,
bunzip2, bzcat, cat, catv, chattr, chgrp, chmod, chown,
chroot, chrt, chvt, cksum, clear, cmp, cp, cpio, crond,
crontab, cut, date, dc, dd, deallocvt, delgroup, deluser,
(中略)
time, top, touch, tr, traceroute, true, tty, udhcpc, udhcpd,
umount, uname, uniq, unix2dos, unlzma, unzip, uptime,
usleep, uudecode, uuencode, vconfig, vi, vlock, watch,
watchdog, wc, wget, which, who, whoami, xargs, yes, zcat
$
原稿執筆時点での最新バージョンは「1.10.2」ですが、このバージョンでは約300個ものコマンドが用意されています。
実際にそれぞれのコマンドの機能を使う場合は、busyboxという実行ファイルにコマンド名のリンクを張って利用します(実際には、BusyBoxインストール時に自動的にリンクを作ってくれます)。例えば、BusyBoxをインストールした環境の“/bin”ディレクトリを「ls」コマンドで見てみると、
$ ls -l /bin/ lrwxrwxrwx 1 root root 7 May 22 13:47 addgroup -> busybox lrwxrwxrwx 1 root root 7 May 22 13:47 adduser -> busybox lrwxrwxrwx 1 root root 7 May 22 13:47 ash -> busybox -rwsr-xr-x 1 root root 620344 May 22 13:47 busybox lrwxrwxrwx 1 root root 7 May 22 13:47 cat -> busybox (中略) lrwxrwxrwx 1 500 500 7 May 21 13:47 login -> busybox lrwxrwxrwx 1 500 500 7 May 21 13:47 ls -> busybox lrwxrwxrwx 1 500 500 7 May 21 13:47 lsattr -> busybox (以下略)
といったように、「ls」コマンドを含め、さまざまなコマンドがbusyboxにリンクされていることが分かります。
では、なぜ複数のコマンドを1つの実行ファイルにする必要があるのでしょうか?
それは、複数のコマンドに必要な同じような処理(例えば、エラー処理やファイル操作など)や各実行ファイルに含まれるヘッダ情報などを1つにまとめることで、ディスク上のフットプリント(占有領域)を削減できるからです。組み込み機器のように限られたリソースしか使えない環境では、必要な機能を入れるためのサイズの縮小化は重要な課題となります。また、個々のコマンドを別々にコンパイルするのに比べ、BusyBox1つをコンパイルすることで、環境構築がとても簡単になります。そのため、組み込み向けのLinux環境構築では欠かせないツールといえます。
ただしサイズ縮小化のため、コマンドによってはあまり使われないオプションや機能は省略されています。例えば、プロセスを表示する「ps」コマンドのオプションの場合、FedoraやDebianなどで使われているフル機能では、
[shinji@Fedora9 ~]$ ps --help
********* simple selection ********* ********* selection by list *********
-A all processes -C by command name
-N negate selection -G by real group ID (supports names)
-a all w/ tty except session leaders -U by real user ID (supports names)
-d all except session leaders -g by session OR by effective group name
-e all processes -p by process ID
T all processes on this terminal -s processes in the sessions given
a all w/ tty, including other users -t by tty
g OBSOLETE -- DO NOT USE -u by effective user ID (supports names)
r only running processes U processes for specified users
x processes w/o controlling ttys t by tty
*********** output format ********** *********** long options ***********
-o,o user-defined -f full --Group --User --pid --cols --ppid
-j,j job control s signal --group --user --sid --rows --info
-O,O preloaded -o v virtual memory --cumulative --format --deselect
-l,l long u user-oriented --sort --tty --forest --version
-F extra full X registers --heading --no-heading --context
********* misc options *********
-V,V show version L list format codes f ASCII art forest
-m,m,-L,-T,H threads S children in sum -y change -l format
-M,Z security data c true command name -c scheduling class
-w,w wide output n numeric WCHAN,UID -H process hierarchy
[shinji@Fedora9 ~]$
といったように多くのオプションを利用することができますが、BusyBoxの「ps」コマンドでは次のように1つしか提供されていません。
$ ps --help
BusyBox v1.10.2 (2008-05-22 04:45:56 JST) multi-call binary
Usage: ps
Report process status
Options:
-o col1,col2=header Select columns for display
$
そのため、もし省略された機能を使いたい場合には、BusyBoxで提供されているコマンドをフル機能のコマンドに置き換えるか、もしくはBusyBoxのコマンドを拡張する必要があります。
Copyright © ITmedia, Inc. All Rights Reserved.
組み込み開発の記事ランキング
コーナーリンク
よく読まれている編集記者コラム