blob: ac4e90a41da4af43749bb04f0a010fb01f5aff6b [file] [log] [blame]
Eric Andersen6c4a6b12004-10-08 10:50:08 +00001<!--#include file="header.html" -->
2
Eric Andersen6c4a6b12004-10-08 10:50:08 +00003<h3>Frequently Asked Questions</h3>
4
5This is a collection of some of the more frequently asked questions
6about BusyBox. Some of the questions even have answers. If you
7have additions to this FAQ document, we would love to add them,
8
Rob Landleyb73d2bf2006-05-11 15:00:32 +00009<h2>General questions</h2>
Eric Andersen6c4a6b12004-10-08 10:50:08 +000010<ol>
Rob Landleyac4c92d2006-05-11 17:21:13 +000011<li><a href="#getting_started">How can I get started using BusyBox?</a></li>
12<li><a href="#configure">How do I configure busybox?</a></li>
Bernhard Reutner-Fischer8936a192007-06-08 07:19:06 +000013<li><a href="#build">How do I build BusyBox with a cross-compiler?</a></li>
Rob Landleyac4c92d2006-05-11 17:21:13 +000014<li><a href="#build_system">How do I build a BusyBox-based system?</a></li>
15<li><a href="#kernel">Which Linux kernel versions are supported?</a></li>
16<li><a href="#arch">Which architectures does BusyBox run on?</a></li>
17<li><a href="#libc">Which C libraries are supported?</a></li>
18<li><a href="#commercial">Can I include BusyBox as part of the software on my device?</a></li>
Bernhard Reutner-Fischerbeea4b82008-08-21 12:42:39 +000019<li><a href="#external">Where can I find other small utilities since busybox does not include the features I want?</a></li>
Rob Landleyac4c92d2006-05-11 17:21:13 +000020<li><a href="#demanding">I demand that you to add &lt;favorite feature&gt; right now! How come you don't answer all my questions on the mailing list instantly? I demand that you help me with all of my problems <em>Right Now</em>!</a></li>
21<li><a href="#helpme">I need help with BusyBox! What should I do?</a></li>
22<li><a href="#contracts">I need you to add &lt;favorite feature&gt;! Are the BusyBox developers willing to be paid in order to fix bugs or add in &lt;favorite feature&gt;? Are you willing to provide support contracts?</a></li>
Rob Landleyb73d2bf2006-05-11 15:00:32 +000023</ol>
Rob Landleyde7f9b72005-07-31 04:27:19 +000024
Rob Landleyb73d2bf2006-05-11 15:00:32 +000025<h2>Troubleshooting</h2>
26<ol>
27<li><a href="#bugs">I think I found a bug in BusyBox! What should I do?!</a></li>
Rob Landley95718b32006-08-16 22:13:56 +000028<li><a href="#backporting">I'm using an ancient version from the dawn of time and something's broken. Can you backport fixes for free?</a></li>
Rob Landleyb73d2bf2006-05-11 15:00:32 +000029<li><a href="#init">Busybox init isn't working!</a></li>
30<li><a href="#sed">I can't configure busybox on my system.</a></li>
31<li><a href="#job_control">Why do I keep getting "sh: can't access tty; job control turned off" errors? Why doesn't Control-C work within my shell?</a></li>
32</ol>
33
Denis Vlasenko153cd692007-07-13 15:26:53 +000034<h2>Misc. questions</h2>
35<ol>
36 <li><a href="#tz">How do I change the time zone in busybox?</a></li>
37</ol>
38
Rob Landleyb73d2bf2006-05-11 15:00:32 +000039<h2>Programming questions</h2>
40<ol>
41 <li><a href="#goals">What are the goals of busybox?</a></li>
42 <li><a href="#design">What is the design of busybox?</a></li>
Bernhard Reutner-Fischerbeea4b82008-08-21 12:42:39 +000043 <li><a href="#source">How is the source code organized?</a>
44 <ul>
Rob Landleyb73d2bf2006-05-11 15:00:32 +000045 <li><a href="#source_applets">The applet directories.</a></li>
46 <li><a href="#source_libbb">The busybox shared library (libbb)</a></li>
Bernhard Reutner-Fischerbeea4b82008-08-21 12:42:39 +000047 </ul>
48 </li>
Rob Landleyb73d2bf2006-05-11 15:00:32 +000049 <li><a href="#optimize">I want to make busybox even smaller, how do I go about it?</a></li>
50 <li><a href="#adding">Adding an applet to busybox</a></li>
51 <li><a href="#standards">What standards does busybox adhere to?</a></li>
52 <li><a href="#portability">Portability.</a></li>
Bernhard Reutner-Fischerbeea4b82008-08-21 12:42:39 +000053 <li><a href="#tips">Tips and tricks.</a>
54 <ul>
Rob Landleyb73d2bf2006-05-11 15:00:32 +000055 <li><a href="#tips_encrypted_passwords">Encrypted Passwords</a></li>
56 <li><a href="#tips_vfork">Fork and vfork</a></li>
57 <li><a href="#tips_short_read">Short reads and writes</a></li>
58 <li><a href="#tips_memory">Memory used by relocatable code, PIC, and static linking.</a></li>
59 <li><a href="#tips_kernel_headers">Including Linux kernel headers.</a></li>
Bernhard Reutner-Fischerbeea4b82008-08-21 12:42:39 +000060 </ul>
61 </li>
Denis Vlasenko153cd692007-07-13 15:26:53 +000062 <li><a href="#who">Who are the BusyBox developers?</a></li>
63 </ul>
Eric Andersen6c4a6b12004-10-08 10:50:08 +000064</ol>
65
Denis Vlasenko153cd692007-07-13 15:26:53 +000066
67<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +000068<h1>General questions</h1>
69
Rob Landley380ad122005-09-23 16:52:09 +000070<hr />
Rob Landley380ad122005-09-23 16:52:09 +000071<h2><a name="getting_started">How can I get started using BusyBox?</a></h2>
Denis Vlasenko153cd692007-07-13 15:26:53 +000072
Rob Landley380ad122005-09-23 16:52:09 +000073<p> If you just want to try out busybox without installing it, download the
Rob Landleyac4c92d2006-05-11 17:21:13 +000074 tarball, extract it, run "make defconfig", and then run "make".
Rob Landley380ad122005-09-23 16:52:09 +000075</p>
76<p>
Rob Landleyac4c92d2006-05-11 17:21:13 +000077 This will create a busybox binary with almost all features enabled. To try
Rob Landley380ad122005-09-23 16:52:09 +000078 out a busybox applet, type "./busybox [appletname] [options]", for
79 example "./busybox ls -l" or "./busybox cat LICENSE". Type "./busybox"
80 to see a command list, and "busybox appletname --help" to see a brief
81 usage message for a given applet.
82</p>
83<p>
84 BusyBox uses the name it was invoked under to determine which applet is
85 being invoked. (Try "mv busybox ls" and then "./ls -l".) Installing
86 busybox consists of creating symlinks (or hardlinks) to the busybox
Rob Landley3d283dd2005-11-03 22:11:00 +000087 binary for each applet in busybox, and making sure these links are in
88 the shell's command $PATH. The special applet name "busybox" (or with
89 any optional suffix, such as "busybox-static") uses the first argument
90 to determine which applet to run, as shown above.
Rob Landley380ad122005-09-23 16:52:09 +000091</p>
92<p>
Denis Vlasenkof7996f32007-01-11 17:20:00 +000093 BusyBox also has a feature called the
Bernhard Reutner-Fischer32f3ebf2006-12-10 13:40:16 +000094 <a name="standalone_shell">"standalone shell"</a>, where the busybox
Rob Landley380ad122005-09-23 16:52:09 +000095 shell runs any built-in applets before checking the command path. This
96 feature is also enabled by "make allyesconfig", and to try it out run
97 the command line "PATH= ./busybox ash". This will blank your command path
98 and run busybox as your command shell, so the only commands it can find
99 (without an explicit path such as /bin/ls) are the built-in busybox ones.
Bernhard Reutner-Fischerd591a362006-08-20 17:35:13 +0000100 This is another good way to see what's built into busybox.
101 Note that the standalone shell requires CONFIG_BUSYBOX_EXEC_PATH
102 to be set appropriately, depending on whether or not /proc/self/exe is
103 available or not. If you do not have /proc, then point that config option
104 to the location of your busybox binary, usually /bin/busybox.
105 (So if you set it to /proc/self/exe, and happen to be able to chroot into
106 your rootfs, you must mount /proc beforehand.)
Rob Landley380ad122005-09-23 16:52:09 +0000107</p>
Bernhard Reutner-Fischer32f3ebf2006-12-10 13:40:16 +0000108<p>
109 A typical indication that you set CONFIG_BUSYBOX_EXEC_PATH to proc but
110 forgot to mount proc is:
111<pre>
112$ /bin/echo $PATH
113/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11
114$ echo $PATH
115/bin/sh: echo: not found
116</pre>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000117
Rob Landleyac4c92d2006-05-11 17:21:13 +0000118<hr />
Rob Landleyac4c92d2006-05-11 17:21:13 +0000119<h2><a name="configure">How do I configure busybox?</a></h2>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000120
Rob Landleyac4c92d2006-05-11 17:21:13 +0000121<p> Busybox is configured similarly to the linux kernel. Create a default
122 configuration and then run "make menuconfig" to modify it. The end
123 result is a .config file that tells the busybox build process what features
124 to include. So instead of "./configure; make; make install" the equivalent
125 busybox build would be "make defconfig; make; make install".
126</p>
127
128<p> Busybox configured with all features enabled is a little under a megabyte
129 dynamically linked on x86. To create a smaller busybox, configure it with
130 fewer features. Individual busybox applets cost anywhere from a few
131 hundred bytes to tens of kilobytes. Disable unneeded applets to save,
132 space, using menuconfig.
133</p>
134
135<p>The most important busybox configurators are:</p>
136
137<ul>
138<li><p>make <b>defconfig</b> - Create the maximum "sane" configuration. This
139enables almost all features, minus things like debugging options and features
140that require changes to the rest of the system to work (such as selinux or
141devfs device names). Use this if you want to start from a full-featured
142busybox and remove features until it's small enough.</p></li>
143<li><p>make <b>allnoconfig</b> - Disable everything. This creates a tiny version
144of busybox that doesn't do anything. Start here if you know exactly what
145you want and would like to select only those features.</p></li>
146<li><p>make <b>menuconfig</b> - Interactively modify a .config file through a
147multi-level menu interface. Use this after one of the previous two.</p></li>
148</ul>
149
150<p>Some other configuration options are:</p>
151<ul>
152<li><p>make <b>oldconfig</b> - Update an old .config file for a newer version
153of busybox.</p></li>
154<li><p>make <b>allyesconfig</b> - Select absolutely everything. This creates
155a statically linked version of busybox full of debug code, with dependencies on
156selinux, using devfs names... This makes sure everything compiles. Whether
157or not the result would do anything useful is an open question.</p></li>
158<li><p>make <b>allbareconfig</b> - Select all applets but disable all sub-features
159within each applet. More build coverage testing.</p></li>
160<li><p>make <b>randconfig</b> - Create a random configuration for test purposes.</p></li>
161</ul>
162
163<p> Menuconfig modifies your .config file through an interactive menu where you can enable or disable
164 busybox features, and get help about each feature.
165
Rob Landley380ad122005-09-23 16:52:09 +0000166<p>
167 To build a smaller busybox binary, run "make menuconfig" and disable the
168 features you don't need. (Or run "make allnoconfig" and then use
169 menuconfig to add just the features you need. Don't forget to recompile
170 with "make" once you've finished configuring.)
171</p>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000172
173<hr />
Bernhard Reutner-Fischer8936a192007-06-08 07:19:06 +0000174<h2><a name="build">How do I build BusyBox with a cross-compiler?</a></h2>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000175
Bernhard Reutner-Fischer8936a192007-06-08 07:19:06 +0000176<p>
177 To build busybox with a cross-compiler, specify CROSS_COMPILE=&lt;prefix&gt;.
178</p>
179<p>
180 CROSS_COMPILE specifies the prefix used for all executables used
181 during compilation. Only gcc and related binutils executables
182 are prefixed with $(CROSS_COMPILE) in the makefiles.
183 CROSS_COMPILE can be set on the command line:
184<pre>
185 make CROSS_COMPILE=arm-linux-uclibcgnueabi-
186</pre>
187 Alternatively CROSS_COMPILE can be set in the environment.
188 Default value for CROSS_COMPILE is not to prefix executables.
189</p>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000190
191<hr />
Rob Landley380ad122005-09-23 16:52:09 +0000192<h2><a name="build_system">How do I build a BusyBox-based system?</a></h2>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000193
Rob Landley380ad122005-09-23 16:52:09 +0000194<p>
195 BusyBox is a package that replaces a dozen standard packages, but it is
196 not by itself a complete bootable system. Building an entire Linux
197 distribution from source is a bit beyond the scope of this FAQ, but it
198 understandably keeps cropping up on the mailing list, so here are some
199 pointers.
200</p>
201<p>
202 Start by learning how to strip a working system down to the bare essentials
203 needed to run one or two commands, so you know what it is you actually
204 need. An excellent practical place to do
205 this is the <a href="http://www.tldp.org/HOWTO/Bootdisk-HOWTO/">Linux
206 BootDisk Howto</a>, or for a more theoretical approach try
207 <a href="http://www.tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html">From
208 PowerUp to Bash Prompt</a>.
209</p>
210<p>
211 To learn how to build a working Linux system entirely from source code,
Bernhard Reutner-Fischer5f521502008-08-21 11:52:12 +0000212 the place to go is the <a href="http://www.linuxfromscratch.org/">Linux
Rob Landley380ad122005-09-23 16:52:09 +0000213 From Scratch</a> project. They have an entire book of step-by-step
214 instructions you can
215 <a href="http://www.linuxfromscratch.org/lfs/view/stable/">read online</a>
216 or
217 <a href="http://www.linuxfromscratch.org/lfs/downloads/stable/">download</a>.
218 Be sure to check out the other sections of their main page, including
219 Beyond Linux From Scratch, Hardened Linux From Scratch, their Hints
220 directory, and their LiveCD project. (They also have mailing lists which
221 are better sources of answers to Linux-system building questions than
222 the busybox list.)
223</p>
224<p>
225 If you want an automated yet customizable system builder which produces
226 a BusyBox and uClibc based system, try
Bernhard Reutner-Fischer5f521502008-08-21 11:52:12 +0000227 <a href="http://buildroot.uclibc.org/">buildroot</a>, which is
Rob Landleya253e732006-02-14 08:29:48 +0000228 another project by the maintainer of the uClibc (Erik Andersen).
229 Download the tarball, extract it, unset CC, make.
Rob Landley380ad122005-09-23 16:52:09 +0000230 For more instructions, see the website.
231</p>
232
Rob Landleyd48633f2006-03-09 18:03:21 +0000233<hr />
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000234<h2><a name="kernel">Which Linux kernel versions are supported?</a></h2>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000235
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000236<p>
Rob Landley380ad122005-09-23 16:52:09 +0000237 Full functionality requires Linux 2.4.x or better. (Earlier versions may
238 still work, but are no longer regularly tested.) A large fraction of the
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000239 code should run on just about anything. While the current code is fairly
240 Linux specific, it should be fairly easy to port the majority of the code
241 to support, say, FreeBSD or Solaris, or Mac OS X, or even Windows (if you
242 are into that sort of thing).
Rob Landley380ad122005-09-23 16:52:09 +0000243</p>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000244
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000245<hr />
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000246<h2><a name="arch">Which architectures does BusyBox run on?</a></h2>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000247
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000248<p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000249 BusyBox in general will build on any architecture supported by gcc.
Rob Landley380ad122005-09-23 16:52:09 +0000250 Kernel module loading for 2.4 Linux kernels is currently
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000251 limited to ARM, CRIS, H8/300, x86, ia64, x86_64, m68k, MIPS, PowerPC,
252 S390, SH3/4/5, Sparc, v850e, and x86_64 for 2.4.x kernels.
Rob Landley380ad122005-09-23 16:52:09 +0000253</p>
254<p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000255 With 2.6.x kernels, module loading support should work on all architectures.
Rob Landley380ad122005-09-23 16:52:09 +0000256</p>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000257
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000258<hr />
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000259<h2><a name="libc">Which C libraries are supported?</a></h2>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000260
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000261<p>
Rob Landley380ad122005-09-23 16:52:09 +0000262 On Linux, BusyBox releases are tested against uClibc (0.9.27 or later) and
263 glibc (2.2 or later). Both should provide full functionality with busybox,
264 and if you find a bug we want to hear about it.
265</p>
Mike Frysingerd505e3e2005-10-29 08:03:54 +0000266<p>
Rob Landley380ad122005-09-23 16:52:09 +0000267 Linux-libc5 is no longer maintained (and has no known advantages over
268 uClibc), dietlibc is known to have numerous unfixed bugs, and klibc is
269 missing too many features to build BusyBox. If you require a small C
270 library for Linux, the busybox developers recommend uClibc.
271</p>
272<p>
273 Some BusyBox applets have been built and run under a combination
274 of newlib and libgloss (see
275 <a href="http://www.busybox.net/lists/busybox/2005-March/013759.html">this thread</a>).
276 This is still experimental, but may be supported in a future release.
277</p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000278
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000279<hr />
Mike Frysinger86097b32005-09-15 01:37:36 +0000280<h2><a name="commercial">Can I include BusyBox as part of the software on my device?</a></h2>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000281
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000282<p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000283 Yes. As long as you <a href="http://busybox.net/license.html">fully comply
284 with the generous terms of the GPL BusyBox license</a> you can ship BusyBox
285 as part of the software on your device.
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000286</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000287
288<hr />
Denis Vlasenko153cd692007-07-13 15:26:53 +0000289<h2><a name="external">Where can I find other small utilities since busybox
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000290 does not include the features i want?</a></h2>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000291
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000292<p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000293 we maintain such a <a href="tinyutils.html">list</a> on this site!
294</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000295
296<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000297<h2><a name="demanding">I demand that you to add &lt;favorite feature&gt; right now! How come you don't answer all my questions on the mailing list instantly? I demand that you help me with all of my problems <em>Right Now</em>!</a></h2>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000298
Denis Vlasenko153cd692007-07-13 15:26:53 +0000299<p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000300 You have not paid us a single cent and yet you still have the product of
301 many years of our work. We are not your slaves! We work on BusyBox
302 because we find it useful and interesting. If you go off flaming us, we
303 will ignore you.
304
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000305<hr />
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000306<h2><a name="helpme">I need help with BusyBox! What should I do?</a></h2>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000307
Denis Vlasenko153cd692007-07-13 15:26:53 +0000308<p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000309 If you find that you need help with BusyBox, you can ask for help on the
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000310 BusyBox mailing list at busybox@busybox.net.</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000311
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000312<p> In addition to the mailing list, Erik Andersen (andersee), Manuel Nova
313 (mjn3), Rob Landley (landley), Mike Frysinger (SpanKY), Bernhard Fischer
314 (blindvt), and other long-time BusyBox developers are known to hang out
315 on the uClibc IRC channel: #uclibc on irc.freenode.net. There is a
316 <a href="http://ibot.Rikers.org/%23uclibc/">web archive of
317 daily logs of the #uclibc IRC channel</a> going back to 2002.
318</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000319
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000320<p>
Rob Landleya253e732006-02-14 08:29:48 +0000321 <b>Please do not send private email to Rob, Erik, Manuel, or the other
322 BusyBox contributors asking for private help unless you are planning on
323 paying for consulting services.</b>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000324</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000325
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000326<p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000327 When we answer questions on the BusyBox mailing list, it helps everyone
328 since people with similar problems in the future will be able to get help
329 by searching the mailing list archives. Private help is reserved as a paid
330 service. If you need to use private communication, or if you are serious
331 about getting timely assistance with BusyBox, you should seriously consider
332 paying for consulting services.
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000333</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000334
335<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000336<h2><a name="contracts">I need you to add &lt;favorite feature&gt;! Are the BusyBox developers willing to be paid in order to fix bugs or add in &lt;favorite feature&gt;? Are you willing to provide support contracts?</a></h2>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000337
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000338<p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000339 Yes we are. The easy way to sponsor a new feature is to post an offer on
340 the mailing list to see who's interested. You can also email the project's
341 maintainer and ask them to recommend someone.
342</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000343
Denis Vlasenko153cd692007-07-13 15:26:53 +0000344<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000345<h1>Troubleshooting</h1>
346
347<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000348<h2><a name="bugs">I think I found a bug in BusyBox! What should I do?</a></h2>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000349
350<p>
351 If you simply need help with using or configuring BusyBox, please submit a
352 detailed description of your problem to the BusyBox mailing list at <a
Bernhard Reutner-Fischer557f9c42008-08-21 11:54:23 +0000353 href="mailto:busybox@busybox.net">busybox@busybox.net</a>.
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000354 Please do not send email to individual developers asking
355 for private help unless you are planning on paying for consulting services.
356 When we answer questions on the BusyBox mailing list, it helps everyone,
357 while private answers help only you...
358</p>
359
360<p>
Rob Landley95718b32006-08-16 22:13:56 +0000361 Bug reports and new feature patches sometimes get lost when posted to the
362 mailing list, because the developers of BusyBox are busy people and have
363 only so much they can keep in their brains at a time. You can post a
364 polite reminder after 2-3 days without offending anybody. If that doesn't
365 result in a solution, please use the
366 <a href="http://bugs.busybox.net/">BusyBox Bug
367 and Patch Tracking System</a> to submit a detailed explanation and we'll
368 get to it as soon as we can.
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000369</p>
370
Rob Landley95718b32006-08-16 22:13:56 +0000371<p>
372 Note that bugs entered into the bug system without being mentioned on the
373 mailing list first may languish there for months before anyone even notices
374 them. We generally go through the bug system when preparing for new
375 development releases, to see what fell through the cracks while we were
376 off writing new features. (It's a fast/unreliable vs slow/reliable thing.
377 Saves retransits, but the latency sucks.)
378</p>
379
380<hr />
Bernhard Reutner-Fischerbeea4b82008-08-21 12:42:39 +0000381<h2><a name="backporting">I'm using an ancient version from the dawn of time and something's broken. Can you backport fixes for free?</a></h2>
Rob Landley95718b32006-08-16 22:13:56 +0000382
383<p>Variants of this one get asked a lot.</p>
384
385<p>The purpose of the BusyBox mailing list is to develop and improve BusyBox,
386and we're happy to respond to our users' needs. But if you're coming to the
387list for free tech support we're going to ask you to upgrade to a current
388version before we try to diagnose your problem.</p>
389
Bernhard Reutner-Fischerbeea4b82008-08-21 12:42:39 +0000390<p>If you're building BusyBox 0.50 with uClibc 0.9.19 and gcc 1.27 there's a
Rob Landley95718b32006-08-16 22:13:56 +0000391fairly large chance that whatever problem you're seeing has already been fixed.
392To get that fix, all you have to do is upgrade to a newer version. If you
393don't at least _try_ that, you're wasting our time.</p>
394
395<p>The volunteers are happy to fix any bugs you point out in the current
396versions because doing so helps everybody and makes the project better. We
397want to make the current version work for you. But diagnosing, debugging, and
398backporting fixes to old versions isn't something we do for free, because it
399doesn't help anybody but you. The cost of volunteer tech support is using a
400reasonably current version of the project.</p>
401
402<p>If you don't want to upgrade, you have the complete source code and thus
403the ability to fix it yourself, or hire a consultant to do it for you. If you
404got your version from a vendor who still supports the older version, they can
405help you. But there are limits as to what the volunteers will feel obliged to
406do for you.</p>
407
408<p>As a rule of thumb, volunteers will generally answer polite questions about
409a given version for about three years after its release before it's so old
410we don't remember the answer off the top of our head. And if you want us to
411put any _effort_ into tracking it down, we want you to put in a little effort
412of your own by confirming it's still a problem with the current version. It's
413also hard for us to fix a problem of yours if we can't reproduce it because
414we don't have any systems running an environment that old.</p>
415
416<p>A consultant will happily set up a special environment just to reproduce
417your problem, and you can always ask on the list if any of the developers
418have consulting rates.</p>
419
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000420<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000421<h2><a name="init">Busybox init isn't working!</a></h2>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000422
Mike Frysinger77dbe732005-04-17 04:32:22 +0000423<p>
Rob Landleyc5e4ab72006-06-29 04:59:11 +0000424 Init is the first program that runs, so it might be that no programs are
425 working on your new system because of a problem with your cross-compiler,
426 kernel, console settings, shared libraries, root filesystem... To rule all
427 that out, first build a statically linked version of the following "hello
428 world" program with your cross compiler toolchain:
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000429</p>
430<pre>
431#include &lt;stdio.h&gt;
Mike Frysinger77dbe732005-04-17 04:32:22 +0000432
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000433int main(int argc, char *argv)
434{
435 printf("Hello world!\n");
436 sleep(999999999);
437}
438</pre>
439
440<p>
441 Now try to boot your device with an "init=" argument pointing to your
442 hello world program. Did you see the hello world message? Until you
443 do, don't bother messing with busybox init.
444</p>
445
446<p>
447 Once you've got it working statically linked, try getting it to work
448 dynamically linked. Then read the FAQ entry <a href="#build_system">How
Rob Landleyc5e4ab72006-06-29 04:59:11 +0000449 do I build a BusyBox-based system?</a>, and the
450 <a href="/downloads/BusyBox.html#item_init">documentation for BusyBox
451 init</a>.
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000452</p>
Mike Frysinger77dbe732005-04-17 04:32:22 +0000453
454<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000455<h2><a name="sed">I can't configure busybox on my system.</a></h2>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000456
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000457<p>
458 Configuring Busybox depends on a recent version of sed. Older
459 distributions (Red Hat 7.2, Debian 3.0) may not come with a
460 usable version. Luckily BusyBox can use its own sed to configure itself,
461 although this leads to a bit of a chicken and egg problem.
462 You can work around this by hand-configuring busybox to build with just
463 sed, then putting that sed in your path to configure the rest of busybox
464 with, like so:
465</p>
466
467<pre>
468 tar xvjf sources/busybox-x.x.x.tar.bz2
469 cd busybox-x.x.x
470 make allnoconfig
471 make include/bb_config.h
472 echo "CONFIG_SED=y" >> .config
473 echo "#undef ENABLE_SED" >> include/bb_config.h
474 echo "#define ENABLE_SED 1" >> include/bb_config.h
475 make
476 mv busybox sed
477 export PATH=`pwd`:"$PATH"
478</pre>
479
480<p>Then you can run "make defconfig" or "make menuconfig" normally.</p>
481
482<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000483<h2><a name="job_control">Why do I keep getting "sh: can't access tty; job control turned off" errors? Why doesn't Control-C work within my shell?</a></h2>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000484
Denis Vlasenko153cd692007-07-13 15:26:53 +0000485<p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000486 Job control will be turned off since your shell can not obtain a controlling
487 terminal. This typically happens when you run your shell on /dev/console.
488 The kernel will not provide a controlling terminal on the /dev/console
489 device. Your should run your shell on a normal tty such as tty1 or ttyS0
490 and everything will work perfectly. If you <em>REALLY</em> want your shell
491 to run on /dev/console, then you can hack your kernel (if you are into that
492 sortof thing) by changing drivers/char/tty_io.c to change the lines where
493 it sets "noctty = 1;" to instead set it to "0". I recommend you instead
494 run your shell on a real console...
495</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000496
Denis Vlasenko153cd692007-07-13 15:26:53 +0000497<hr />
498<h1>Misc. questions</h1>
499
500<hr />
501<h2><a name="tz">How do I change the time zone in busybox?</a></h2>
502
503<p>Busybox has nothing to do with the timezone. Please consult your libc
Bernhard Reutner-Fischer5f521502008-08-21 11:52:12 +0000504documentation. (<a href="http://google.com/search?q=uclibc+glibc+timezone">http://google.com/search?q=uclibc+glibc+timezone</a>).</p>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000505
506<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000507<h1>Development</h1>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000508
Denis Vlasenko153cd692007-07-13 15:26:53 +0000509<hr />
510<h2><a name="goals">What are the goals of busybox?</a></h2>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000511
512<p>Busybox aims to be the smallest and simplest correct implementation of the
513standard Linux command line tools. First and foremost, this means the
514smallest executable size we can manage. We also want to have the simplest
515and cleanest implementation we can manage, be <a href="#standards">standards
516compliant</a>, minimize run-time memory usage (heap and stack), run fast, and
517take over the world.</p>
518
Denis Vlasenko153cd692007-07-13 15:26:53 +0000519<hr />
520<h2><a name="design">What is the design of busybox?</a></h2>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000521
522<p>Busybox is like a swiss army knife: one thing with many functions.
523The busybox executable can act like many different programs depending on
524the name used to invoke it. Normal practice is to create a bunch of symlinks
525pointing to the busybox binary, each of which triggers a different busybox
526function. (See <a href="FAQ.html#getting_started">getting started</a> in the
527FAQ for more information on usage, and <a href="BusyBox.html">the
528busybox documentation</a> for a list of symlink names and what they do.)
529
530<p>The "one binary to rule them all" approach is primarily for size reasons: a
531single multi-purpose executable is smaller then many small files could be.
532This way busybox only has one set of ELF headers, it can easily share code
533between different apps even when statically linked, it has better packing
534efficiency by avoding gaps between files or compression dictionary resets,
535and so on.</p>
536
537<p>Work is underway on new options such as "make standalone" to build separate
538binaries for each applet, and a "libbb.so" to make the busybox common code
539available as a shared library. Neither is ready yet at the time of this
540writing.</p>
541
542<a name="source"></a>
543
Denis Vlasenko153cd692007-07-13 15:26:53 +0000544<hr />
545<h2><a name="source_applets">The applet directories</a></h2>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000546
547<p>The directory "applets" contains the busybox startup code (applets.c and
548busybox.c), and several subdirectories containing the code for the individual
549applets.</p>
550
551<p>Busybox execution starts with the main() function in applets/busybox.c,
Denis Vlasenko8f8f2682006-10-03 21:00:43 +0000552which sets the global variable applet_name to argv[0] and calls
Denis Vlasenkoe4f2d062007-04-11 17:03:19 +0000553run_applet_and_exit() in applets/applets.c. That uses the applets[] array
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000554(defined in include/busybox.h and filled out in include/applets.h) to
555transfer control to the appropriate APPLET_main() function (such as
556cat_main() or sed_main()). The individual applet takes it from there.</p>
557
558<p>This is why calling busybox under a different name triggers different
559functionality: main() looks up argv[0] in applets[] to get a function pointer
560to APPLET_main().</p>
561
562<p>Busybox applets may also be invoked through the multiplexor applet
Denis Vlasenko82d38da2007-10-10 14:38:47 +0000563"busybox" (see busybox_main() in libbb/appletlib.c), and through the
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000564standalone shell (grep for STANDALONE_SHELL in applets/shell/*.c).
565See <a href="FAQ.html#getting_started">getting started</a> in the
566FAQ for more information on these alternate usage mechanisms, which are
567just different ways to reach the relevant APPLET_main() function.</p>
568
569<p>The applet subdirectories (archival, console-tools, coreutils,
570debianutils, e2fsprogs, editors, findutils, init, loginutils, miscutils,
571modutils, networking, procps, shell, sysklogd, and util-linux) correspond
572to the configuration sub-menus in menuconfig. Each subdirectory contains the
573code to implement the applets in that sub-menu, as well as a Config.in
574file defining that configuration sub-menu (with dependencies and help text
575for each applet), and the makefile segment (Makefile.in) for that
576subdirectory.</p>
577
578<p>The run-time --help is stored in usage_messages[], which is initialized at
579the start of applets/applets.c and gets its help text from usage.h. During the
580build this help text is also used to generate the BusyBox documentation (in
581html, txt, and man page formats) in the docs directory. See
582<a href="#adding">adding an applet to busybox</a> for more
583information.</p>
584
Denis Vlasenko153cd692007-07-13 15:26:53 +0000585<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000586<h2><a name="source_libbb"><b>libbb</b></a></h2>
587
588<p>Most non-setup code shared between busybox applets lives in the libbb
589directory. It's a mess that evolved over the years without much auditing
590or cleanup. For anybody looking for a great project to break into busybox
591development with, documenting libbb would be both incredibly useful and good
592experience.</p>
593
594<p>Common themes in libbb include allocation functions that test
595for failure and abort the program with an error message so the caller doesn't
596have to test the return value (xmalloc(), xstrdup(), etc), wrapped versions
597of open(), close(), read(), and write() that test for their own failures
598and/or retry automatically, linked list management functions (llist.c),
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000599command line argument parsing (getopt32.c), and a whole lot more.</p>
Eric Andersen6c4a6b12004-10-08 10:50:08 +0000600
601<hr />
Rob Landleyc7a3e1b2005-07-31 04:25:00 +0000602<h2><a name="optimize">I want to make busybox even smaller, how do I go about it?</a></h2>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000603
Rob Landleyc7a3e1b2005-07-31 04:25:00 +0000604<p>
605 To conserve bytes it's good to know where they're being used, and the
606 size of the final executable isn't always a reliable indicator of
607 the size of the components (since various structures are rounded up,
608 so a small change may not even be visible by itself, but many small
609 savings add up).
610</p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000611
612<p> The busybox Makefile builds two versions of busybox, one of which
613 (busybox_unstripped) has extra information that various analysis tools
614 can use. (This has nothing to do with CONFIG_DEBUG, leave that off
615 when trying to optimize for size.)
616</p>
617
618<p> The <b>"make bloatcheck"</b> option uses Matt Mackall's bloat-o-meter
619 script to compare two versions of busybox (busybox_unstripped vs
620 busybox_old), and report which symbols changed size and by how much.
Rob Landleyd244bc12006-05-27 21:30:34 +0000621 To use it, first build a base version with <b>"make baseline"</b>.
622 (This creates busybox_old, which should have the original sizes for
623 comparison purposes.) Then build the new version with your changes
624 and run "make bloatcheck" to see the size differences from the old
625 version.
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000626</p>
Rob Landleyc7a3e1b2005-07-31 04:25:00 +0000627<p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000628 The first line of output has totals: how many symbols were added or
629 removed, how many symbols grew or shrank, the number of bytes added
630 and number of bytes removed by these changes, and finally the total
631 number of bytes difference between the two files. The remaining
632 lines show each individual symbol, the old and new sizes, and the
633 increase or decrease in size (which results are sorted by).
634</p>
635<p>
636 The <b>"make sizes"</b> option produces raw symbol size information for
637 busybox_unstripped. This is the output from the "nm --size-sort"
638 command (see "man nm" for more information), and is the information
639 bloat-o-meter parses to produce the comparison report above. For
640 defconfig, this is a good way to find the largest symbols in the tree
641 (which is a good place to start when trying to shrink the code). To
642 take a closer look at individual applets, configure busybox with just
643 one applet (run "make allnoconfig" and then switch on a single applet
644 with menuconfig), and then use "make sizes" to see the size of that
645 applet's components.
646</p>
647<p>
648 The "showasm" command (in the scripts directory) produces an assembly
649 dump of a function, providing a closer look at what changed. Try
650 "scripts/showasm busybox_unstripped" to list available symbols, and
651 "scripts/showasm busybox_unstripped symbolname" to see the assembly
652 for a sepecific symbol.
Rob Landleyc7a3e1b2005-07-31 04:25:00 +0000653</p>
Denis Vlasenko153cd692007-07-13 15:26:53 +0000654
Rob Landleyc7a3e1b2005-07-31 04:25:00 +0000655<hr />
Denis Vlasenko153cd692007-07-13 15:26:53 +0000656<h2><a name="adding">Adding an applet to busybox</a></h2>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000657
658<p>To add a new applet to busybox, first pick a name for the applet and
659a corresponding CONFIG_NAME. Then do this:</p>
660
661<ul>
662<li>Figure out where in the busybox source tree your applet best fits,
663and put your source code there. Be sure to use APPLET_main() instead
664of main(), where APPLET is the name of your applet.</li>
665
666<li>Add your applet to the relevant Config.in file (which file you add
667it to determines where it shows up in "make menuconfig"). This uses
668the same general format as the linux kernel's configuration system.</li>
669
670<li>Add your applet to the relevant Makefile.in file (in the same
671directory as the Config.in you chose), using the existing entries as a
672template and the same CONFIG symbol as you used for Config.in. (Don't
673forget "needlibm" or "needcrypt" if your applet needs libm or
674libcrypt.)</li>
675
676<li>Add your applet to "include/applets.h", using one of the existing
677entries as a template. (Note: this is in alphabetical order. Applets
678are found via binary search, and if you add an applet out of order it
679won't work.)</li>
680
681<li>Add your applet's runtime help text to "include/usage.h". You need
682at least appname_trivial_usage (the minimal help text, always included
683in the busybox binary when this applet is enabled) and appname_full_usage
684(extra help text included in the busybox binary with
685CONFIG_FEATURE_VERBOSE_USAGE is enabled), or it won't compile.
686The other two help entry types (appname_example_usage and
687appname_notes_usage) are optional. They don't take up space in the binary,
688but instead show up in the generated documentation (BusyBox.html,
689BusyBox.txt, and the man page BusyBox.1).</li>
690
691<li>Run menuconfig, switch your applet on, compile, test, and fix the
692bugs. Be sure to try both "allyesconfig" and "allnoconfig" (and
693"allbareconfig" if relevant).</li>
694
695</ul>
696
Denis Vlasenko153cd692007-07-13 15:26:53 +0000697<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000698<h2><a name="standards">What standards does busybox adhere to?</a></h2>
699
700<p>The standard we're paying attention to is the "Shell and Utilities"
701portion of the <a href="http://www.opengroup.org/onlinepubs/009695399/">Open
702Group Base Standards</a> (also known as the Single Unix Specification version
7033 or SUSv3). Note that paying attention isn't necessarily the same thing as
704following it.</p>
705
706<p>SUSv3 doesn't even mention things like init, mount, tar, or losetup, nor
707commonly used options like echo's '-e' and '-n', or sed's '-i'. Busybox is
708driven by what real users actually need, not the fact the standard believes
709we should implement ed or sccs. For size reasons, we're unlikely to include
710much internationalization support beyond UTF-8, and on top of all that, our
711configuration menu lets developers chop out features to produce smaller but
712very non-standard utilities.</p>
713
714<p>Also, Busybox is aimed primarily at Linux. Unix standards are interesting
715because Linux tries to adhere to them, but portability to dozens of platforms
716is only interesting in terms of offering a restricted feature set that works
717everywhere, not growing dozens of platform-specific extensions. Busybox
718should be portable to all hardware platforms Linux supports, and any other
719similar operating systems that are easy to do and won't require much
720maintenance.</p>
721
722<p>In practice, standards compliance tends to be a clean-up step once an
723applet is otherwise finished. When polishing and testing a busybox applet,
724we ensure we have at least the option of full standards compliance, or else
725document where we (intentionally) fall short.</p>
726
Denis Vlasenko153cd692007-07-13 15:26:53 +0000727<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000728<h2><a name="portability">Portability.</a></h2>
729
730<p>Busybox is a Linux project, but that doesn't mean we don't have to worry
731about portability. First of all, there are different hardware platforms,
732different C library implementations, different versions of the kernel and
733build toolchain... The file "include/platform.h" exists to centralize and
734encapsulate various platform-specific things in one place, so most busybox
735code doesn't have to care where it's running.</p>
736
737<p>To start with, Linux runs on dozens of hardware platforms. We try to test
738each release on x86, x86-64, arm, power pc, and mips. (Since qemu can handle
739all of these, this isn't that hard.) This means we have to care about a number
740of portability issues like endianness, word size, and alignment, all of which
741belong in platform.h. That header handles conditional #includes and gives
742us macros we can use in the rest of our code. At some point in the future
743we might grow a platform.c, possibly even a platform subdirectory. As long
744as the applets themselves don't have to care.</p>
745
746<p>On a related note, we made the "default signedness of char varies" problem
747go away by feeding the compiler -funsigned-char. This gives us consistent
748behavior on all platforms, and defaults to 8-bit clean text processing (which
749gets us halfway to UTF-8 support). NOMMU support is less easily separated
750(see the tips section later in this document), but we're working on it.</p>
751
752<p>Another type of portability is build environments: we unapologetically use
753a number of gcc and glibc extensions (as does the Linux kernel), but these have
754been picked up by packages like uClibc, TCC, and Intel's C Compiler. As for
755gcc, we take advantage of newer compiler optimizations to get the smallest
756possible size, but we also regression test against an older build environment
757using the Red Hat 9 image at "http://busybox.net/downloads/qemu". This has a
7582.4 kernel, gcc 3.2, make 3.79.1, and glibc 2.3, and is the oldest
759build/deployment environment we still put any effort into maintaining. (If
760anyone takes an interest in older kernels you're welcome to submit patches,
761but the effort would probably be better spent
762<a href="http://www.selenic.com/linux-tiny/">trimming
763down the 2.6 kernel</a>.) Older gcc versions than that are uninteresting since
764we now use c99 features, although
765<a href="http://fabrice.bellard.free.fr/tcc/">tcc</a> might be worth a
766look.</p>
767
768<p>We also test busybox against the current release of uClibc. Older versions
769of uClibc aren't very interesting (they were buggy, and uClibc wasn't really
770usable as a general-purpose C library before version 0.9.26 anyway).</p>
771
772<p>Other unix implementations are mostly uninteresting, since Linux binaries
773have become the new standard for portable Unix programs. Specifically,
774the ubiquity of Linux was cited as the main reason the Intel Binary
775Compatability Standard 2 died, by the standards group organized to name a
776successor to ibcs2: <a href="http://www.telly.org/86open/">the 86open
777project</a>. That project disbanded in 1999 with the endorsement of an
778existing standard: Linux ELF binaries. Since then, the major players at the
779time (such as <a
Bernhard Reutner-Fischerbeea4b82008-08-21 12:42:39 +0000780href="http://www-03.ibm.com/servers/aix/products/aixos/linux/index.html">AIX</a>, <a
781href="http://www.sun.com/software/solaris/ds/linux_interop.jsp#3">Solaris</a>, and
782<a href="http://www.onlamp.com/pub/a/bsd/2000/03/17/linuxapps.html">FreeBSD</a>)
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000783have all either grown Linux support or folded.</p>
784
785<p>The major exceptions are newcomer MacOS X, some embedded environments
786(such as newlib+libgloss) which provide a posix environment but not a full
787Linux environment, and environments like Cygwin that provide only partial Linux
788emulation. Also, some embedded Linux systems run a Linux kernel but amputate
789things like the /proc directory to save space.</p>
790
791<p>Supporting these systems is largely a question of providing a clean subset
792of BusyBox's functionality -- whichever applets can easily be made to
793work in that environment. Annotating the configuration system to
794indicate which applets require which prerequisites (such as procfs) is
795also welcome. Other efforts to support these systems (swapping #include
796files to build in different environments, adding adapter code to platform.h,
797adding more extensive special-case supporting infrastructure such as mount's
798legacy mtab support) are handled on a case-by-case basis. Support that can be
799cleanly hidden in platform.h is reasonably attractive, and failing that
800support that can be cleanly separated into a separate conditionally compiled
801file is at least worth a look. Special-case code in the body of an applet is
802something we're trying to avoid.</p>
803
Denis Vlasenko153cd692007-07-13 15:26:53 +0000804<hr />
Bernhard Reutner-Fischerb5d701d2008-08-21 12:52:45 +0000805<h2><a name="tips">Programming tips and tricks.</a></h2>
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000806
807<p>Various things busybox uses that aren't particularly well documented
808elsewhere.</p>
809
Denis Vlasenko153cd692007-07-13 15:26:53 +0000810<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000811<h2><a name="tips_encrypted_passwords">Encrypted Passwords</a></h2>
812
813<p>Password fields in /etc/passwd and /etc/shadow are in a special format.
814If the first character isn't '$', then it's an old DES style password. If
815the first character is '$' then the password is actually three fields
816separated by '$' characters:</p>
817<pre>
818 <b>$type$salt$encrypted_password</b>
819</pre>
820
821<p>The "type" indicates which encryption algorithm to use: 1 for MD5 and 2 for SHA1.</p>
822
823<p>The "salt" is a bunch of ramdom characters (generally 8) the encryption
824algorithm uses to perturb the password in a known and reproducible way (such
825as by appending the random data to the unencrypted password, or combining
826them with exclusive or). Salt is randomly generated when setting a password,
827and then the same salt value is re-used when checking the password. (Salt is
828thus stored unencrypted.)</p>
829
830<p>The advantage of using salt is that the same cleartext password encrypted
831with a different salt value produces a different encrypted value.
832If each encrypted password uses a different salt value, an attacker is forced
833to do the cryptographic math all over again for each password they want to
834check. Without salt, they could simply produce a big dictionary of commonly
835used passwords ahead of time, and look up each password in a stolen password
836file to see if it's a known value. (Even if there are billions of possible
837passwords in the dictionary, checking each one is just a binary search against
838a file only a few gigabytes long.) With salt they can't even tell if two
839different users share the same password without guessing what that password
840is and decrypting it. They also can't precompute the attack dictionary for
841a specific password until they know what the salt value is.</p>
842
843<p>The third field is the encrypted password (plus the salt). For md5 this
844is 22 bytes.</p>
845
846<p>The busybox function to handle all this is pw_encrypt(clear, salt) in
847"libbb/pw_encrypt.c". The first argument is the clear text password to be
848encrypted, and the second is a string in "$type$salt$password" format, from
849which the "type" and "salt" fields will be extracted to produce an encrypted
850value. (Only the first two fields are needed, the third $ is equivalent to
851the end of the string.) The return value is an encrypted password in
852/etc/passwd format, with all three $ separated fields. It's stored in
853a static buffer, 128 bytes long.</p>
854
855<p>So when checking an existing password, if pw_encrypt(text,
856old_encrypted_password) returns a string that compares identical to
857old_encrypted_password, you've got the right password. When setting a new
858password, generate a random 8 character salt string, put it in the right
859format with sprintf(buffer, "$%c$%s", type, salt), and feed buffer as the
860second argument to pw_encrypt(text,buffer).</p>
861
Denis Vlasenko153cd692007-07-13 15:26:53 +0000862<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000863<h2><a name="tips_vfork">Fork and vfork</a></h2>
864
865<p>On systems that haven't got a Memory Management Unit, fork() is unreasonably
866expensive to implement (and sometimes even impossible), so a less capable
867function called vfork() is used instead. (Using vfork() on a system with an
868MMU is like pounding a nail with a wrench. Not the best tool for the job, but
869it works.)</p>
870
871<p>Busybox hides the difference between fork() and vfork() in
872libbb/bb_fork_exec.c. If you ever want to fork and exec, use bb_fork_exec()
873(which returns a pid and takes the same arguments as execve(), although in
874this case envp can be NULL) and don't worry about it. This description is
875here in case you want to know why that does what it does.</p>
876
877<p>Implementing fork() depends on having a Memory Management Unit. With an
878MMU then you can simply set up a second set of page tables and share the
879physical memory via copy-on-write. So a fork() followed quickly by exec()
880only copies a few pages of the parent's memory, just the ones it changes
881before freeing them.</p>
882
883<p>With a very primitive MMU (using a base pointer plus length instead of page
884tables, which can provide virtual addresses and protect processes from each
885other, but no copy on write) you can still implement fork. But it's
886unreasonably expensive, because you have to copy all the parent process'
887memory into the new process (which could easily be several megabytes per fork).
888And you have to do this even though that memory gets freed again as soon as the
889exec happens. (This is not just slow and a waste of space but causes memory
890usage spikes that can easily cause the system to run out of memory.)</p>
891
892<p>Without even a primitive MMU, you have no virtual addresses. Every process
893can reach out and touch any other process' memory, because all pointers are to
894physical addresses with no protection. Even if you copy a process' memory to
895new physical addresses, all of its pointers point to the old objects in the
896old process. (Searching through the new copy's memory for pointers and
897redirect them to the new locations is not an easy problem.)</p>
898
899<p>So with a primitive or missing MMU, fork() is just not a good idea.</p>
900
901<p>In theory, vfork() is just a fork() that writeably shares the heap and stack
902rather than copying it (so what one process writes the other one sees). In
903practice, vfork() has to suspend the parent process until the child does exec,
904at which point the parent wakes up and resumes by returning from the call to
905vfork(). All modern kernel/libc combinations implement vfork() to put the
906parent to sleep until the child does its exec. There's just no other way to
907make it work: the parent has to know the child has done its exec() or exit()
908before it's safe to return from the function it's in, so it has to block
909until that happens. In fact without suspending the parent there's no way to
910even store separate copies of the return value (the pid) from the vfork() call
911itself: both assignments write into the same memory location.</p>
912
913<p>One way to understand (and in fact implement) vfork() is this: imagine
914the parent does a setjmp and then continues on (pretending to be the child)
915until the exec() comes around, then the _exec_ does the actual fork, and the
916parent does a longjmp back to the original vfork call and continues on from
917there. (It thus becomes obvious why the child can't return, or modify
918local variables it doesn't want the parent to see changed when it resumes.)
919
920<p>Note a common mistake: the need for vfork doesn't mean you can't have two
921processes running at the same time. It means you can't have two processes
922sharing the same memory without stomping all over each other. As soon as
923the child calls exec(), the parent resumes.</p>
924
925<p>If the child's attempt to call exec() fails, the child should call _exit()
926rather than a normal exit(). This avoids any atexit() code that might confuse
927the parent. (The parent should never call _exit(), only a vforked child that
928failed to exec.)</p>
929
930<p>(Now in theory, a nommu system could just copy the _stack_ when it forks
931(which presumably is much shorter than the heap), and leave the heap shared.
932Even with no MMU at all
933In practice, you've just wound up in a multi-threaded situation and you can't
934do a malloc() or free() on your heap without freeing the other process' memory
935(and if you don't have the proper locking for being threaded, corrupting the
936heap if both of you try to do it at the same time and wind up stomping on
937each other while traversing the free memory lists). The thing about vfork is
938that it's a big red flag warning "there be dragons here" rather than
939something subtle and thus even more dangerous.)</p>
940
Denis Vlasenko153cd692007-07-13 15:26:53 +0000941<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000942<h2><a name="tips_sort_read">Short reads and writes</a></h2>
943
944<p>Busybox has special functions, bb_full_read() and bb_full_write(), to
945check that all the data we asked for got read or written. Is this a real
946world consideration? Try the following:</p>
947
948<pre>while true; do echo hello; sleep 1; done | tee out.txt</pre>
949
950<p>If tee is implemented with bb_full_read(), tee doesn't display output
951in real time but blocks until its entire input buffer (generally a couple
952kilobytes) is read, then displays it all at once. In that case, we _want_
953the short read, for user interface reasons. (Note that read() should never
954return 0 unless it has hit the end of input, and an attempt to write 0
955bytes should be ignored by the OS.)</p>
956
957<p>As for short writes, play around with two processes piping data to each
958other on the command line (cat bigfile | gzip &gt; out.gz) and suspend and
959resume a few times (ctrl-z to suspend, "fg" to resume). The writer can
960experience short writes, which are especially dangerous because if you don't
961notice them you'll discard data. They can also happen when a system is under
962load and a fast process is piping to a slower one. (Such as an xterm waiting
963on x11 when the scheduler decides X is being a CPU hog with all that
964text console scrolling...)</p>
965
966<p>So will data always be read from the far end of a pipe at the
967same chunk sizes it was written in? Nope. Don't rely on that. For one
Denis Vlasenkof7996f32007-01-11 17:20:00 +0000968counterexample, see <a href="http://www.faqs.org/rfcs/rfc896.html">rfc 896
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000969for Nagle's algorithm</a>, which waits a fraction of a second or so before
970sending out small amounts of data through a TCP/IP connection in case more
971data comes in that can be merged into the same packet. (In case you were
972wondering why action games that use TCP/IP set TCP_NODELAY to lower the latency
973on their their sockets, now you know.)</p>
974
Denis Vlasenko153cd692007-07-13 15:26:53 +0000975<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +0000976<h2><a name="tips_memory">Memory used by relocatable code, PIC, and static linking.</a></h2>
977
978<p>The downside of standard dynamic linking is that it results in self-modifying
979code. Although each executable's pages are mmaped() into a process' address
980space from the executable file and are thus naturally shared between processes
981out of the page cache, the library loader (ld-linux.so.2 or ld-uClibc.so.0)
982writes to these pages to supply addresses for relocatable symbols. This
983dirties the pages, triggering copy-on-write allocation of new memory for each
984processes' dirtied pages.</p>
985
986<p>One solution to this is Position Independent Code (PIC), a way of linking
987a file so all the relocations are grouped together. This dirties fewer
988pages (often just a single page) for each process' relocations. The down
989side is this results in larger executables, which take up more space on disk
990(and a correspondingly larger space in memory). But when many copies of the
991same program are running, PIC dynamic linking trades a larger disk footprint
992for a smaller memory footprint, by sharing more pages.</p>
993
994<p>A third solution is static linking. A statically linked program has no
995relocations, and thus the entire executable is shared between all running
996instances. This tends to have a significantly larger disk footprint, but
997on a system with only one or two executables, shared libraries aren't much
998of a win anyway.</p>
999
1000<p>You can tell the glibc linker to display debugging information about its
1001relocations with the environment variable "LD_DEBUG". Try
1002"LD_DEBUG=help /bin/true" for a list of commands. Learning to interpret
1003"LD_DEBUG=statistics cat /proc/self/statm" could be interesting.</p>
1004
1005<p>For more on this topic, here's Rich Felker:</p>
1006<blockquote>
1007<p>Dynamic linking (without fixed load addresses) fundamentally requires
1008at least one dirty page per dso that uses symbols. Making calls (but
1009never taking the address explicitly) to functions within the same dso
1010does not require a dirty page by itself, but will with ELF unless you
1011use -Bsymbolic or hidden symbols when linking.</p>
1012
1013<p>ELF uses significant additional stack space for the kernel to pass all
1014the ELF data structures to the newly created process image. These are
1015located above the argument list and environment. This normally adds 1
1016dirty page to the process size.</p>
1017
1018<p>The ELF dynamic linker has its own data segment, adding one or more
1019dirty pages. I believe it also performs relocations on itself.</p>
1020
1021<p>The ELF dynamic linker makes significant dynamic allocations to manage
1022the global symbol table and the loaded dso's. This data is never
1023freed. It will be needed again if libdl is used, so unconditionally
1024freeing it is not possible, but normal programs do not use libdl. Of
1025course with glibc all programs use libdl (due to nsswitch) so the
1026issue was never addressed.</p>
1027
1028<p>ELF also has the issue that segments are not page-aligned on disk.
1029This saves up to 4k on disk, but at the expense of using an additional
1030dirty page in most cases, due to a large portion of the first data
1031page being filled with a duplicate copy of the last text page.</p>
1032
1033<p>The above is just a partial list of the tiny memory penalties of ELF
1034dynamic linking, which eventually add up to quite a bit. The smallest
1035I've been able to get a process down to is 8 dirty pages, and the
1036above factors seem to mostly account for it (but some were difficult
1037to measure).</p>
1038</blockquote>
1039
Denis Vlasenko153cd692007-07-13 15:26:53 +00001040<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001041<h2><a name="tips_kernel_headers"></a>Including kernel headers</h2>
1042
Bernhard Reutner-Fischerb5d701d2008-08-21 12:52:45 +00001043<p>The &quot;linux&quot; or &quot;asm&quot; directories of /usr/include
1044contain Linux kernel
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001045headers, so that the C library can talk directly to the Linux kernel. In
1046a perfect world, applications shouldn't include these headers directly, but
1047we don't live in a perfect world.</p>
1048
1049<p>For example, Busybox's losetup code wants linux/loop.c because nothing else
1050#defines the structures to call the kernel's loopback device setup ioctls.
1051Attempts to cut and paste the information into a local busybox header file
1052proved incredibly painful, because portions of the loop_info structure vary by
1053architecture, namely the type __kernel_dev_t has different sizes on alpha,
Bernhard Reutner-Fischerb5d701d2008-08-21 12:52:45 +00001054arm, x86, and so on. Meaning we either #include &lt;linux/posix_types.h&gt; or
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001055we hardwire #ifdefs to check what platform we're building on and define this
1056type appropriately for every single hardware architecture supported by
1057Linux, which is simply unworkable.</p>
1058
1059<p>This is aside from the fact that the relevant type defined in
1060posix_types.h was renamed to __kernel_old_dev_t during the 2.5 series, so
1061to cut and paste the structure into our header we have to #include
Bernhard Reutner-Fischerb5d701d2008-08-21 12:52:45 +00001062&lt;linux/version.h&gt; to figure out which name to use. (What we actually
1063do is
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001064check if we're building on 2.6, and if so just use the new 64 bit structure
1065instead to avoid the rename entirely.) But we still need the version
1066check, since 2.4 didn't have the 64 bit structure.</p>
1067
1068<p>The BusyBox developers spent <u>two years</u> trying to figure
1069out a clean way to do all this. There isn't one. The losetup in the
1070util-linux package from kernel.org isn't doing it cleanly either, they just
1071hide the ugliness by nesting #include files. Their mount/loop.h
Bernhard Reutner-Fischerb5d701d2008-08-21 12:52:45 +00001072#includes &quot;my_dev_t.h&quot;, which #includes &lt;linux/posix_types.h&gt;
1073and &lt;linux/version.h&gt; just like we do. There simply is no alternative.
1074</p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001075
1076<p>Just because directly #including kernel headers is sometimes
1077unavoidable doesn't me we should include them when there's a better
1078way to do it. However, block copying information out of the kernel headers
1079is not a better way.</p>
1080
Denis Vlasenko153cd692007-07-13 15:26:53 +00001081<hr />
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001082<h2><a name="who">Who are the BusyBox developers?</a></h2>
1083
1084<p>The following login accounts currently exist on busybox.net. (I.E. these
Bernhard Reutner-Fischer5f521502008-08-21 11:52:12 +00001085people can commit <a href="http://busybox.net/downloads/patches/">patches</a>
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001086into subversion for the BusyBox, uClibc, and buildroot projects.)</p>
1087
1088<pre>
Bernhard Reutner-Fischer5f521502008-08-21 11:52:12 +00001089aldot :Bernhard Reutner-Fischer
Denis Vlasenkoabfc4cf2006-11-18 16:30:04 +00001090andersen :Erik Andersen - uClibc and BuildRoot maintainer.
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001091bug1 :Glenn McGrath
1092davidm :David McCullough
Denis Vlasenkoabfc4cf2006-11-18 16:30:04 +00001093gkajmowi :Garrett Kajmowicz - uClibc++ maintainer
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001094jbglaw :Jan-Benedict Glaw
1095jocke :Joakim Tjernlund
Bernhard Reutner-Fischer5f521502008-08-21 11:52:12 +00001096landley :Rob Landley
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001097lethal :Paul Mundt
1098mjn3 :Manuel Novoa III
1099osuadmin :osuadmin
1100pgf :Paul Fox
1101pkj :Peter Kjellerstedt
1102prpplague :David Anders
1103psm :Peter S. Mazinger
1104russ :Russ Dill
1105sandman :Robert Griebl
1106sjhill :Steven J. Hill
1107solar :Ned Ludd
1108timr :Tim Riker
1109tobiasa :Tobias Anderberg
1110vapier :Mike Frysinger
Bernhard Reutner-Fischer5f521502008-08-21 11:52:12 +00001111vda :Denys Vlasenko - BusyBox maintainer
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001112</pre>
1113
1114<p>The following accounts used to exist on busybox.net, but don't anymore so
Bernhard Reutner-Fischerb5d701d2008-08-21 12:52:45 +00001115I can't ask /etc/passwd for their names. Rob Wentworth
1116&lt;robwen at gmail.com&gt; asked Google and recovered the names:</p>
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001117
1118<pre>
Denis Vlasenkoabfc4cf2006-11-18 16:30:04 +00001119aaronl :Aaron Lehmann
1120beppu :John Beppu
1121dwhedon :David Whedon
1122erik :Erik Andersen
Denis Vlasenkof7996f32007-01-11 17:20:00 +00001123gfeldman :Gennady Feldman
Denis Vlasenkoabfc4cf2006-11-18 16:30:04 +00001124jimg :Jim Gleason
1125kraai :Matt Kraai
1126markw :Mark Whitley
1127miles :Miles Bader
1128proski :Pavel Roskin
1129rjune :Richard June
1130tausq :Randolph Chung
1131vodz :Vladimir N. Oleynik
Rob Landleyb73d2bf2006-05-11 15:00:32 +00001132</pre>
1133
1134
Eric Andersen6c4a6b12004-10-08 10:50:08 +00001135<br>
1136<br>
1137<br>
1138
1139<!--#include file="footer.html" -->