FAQ.html 54 KB

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