Monday, 5 March 2007

Busybox: a lifesaver for your Linux system

Sometimes it just happens. You do something bad with, let's say, the glibc, and suddenly you discover your command line is unusable. Even simple commands like "ls" die with a segmentation fault or similar errors. Nothing works. More often than not, chrooting won't help. Everyone would panic, unless you know you have a lifesaver: a statically linked BusyBox.

This little free software miracle contains stripped down but fully usable versions of many common UNIX utilities into a single small executable. A command line in a box. Its supported commands (actual support depends on compile configuration) include:

[, [[, addgroup, adduser, adjtimex, ar, arping, ash, awk,
basename, bbconfig, bunzip2, busybox, bzcat, cal, cat, catv,
chattr, chgrp, chmod, chown, chroot, chvt, cksum, clear, cmp,
comm, cp, cpio, crond, crontab, cut, date, dc, dd, deallocvt,
delgroup, deluser, devfsd, df, diff, dirname, dmesg, dnsd,
dos2unix, dpkg, dpkg_deb, du, dumpkmap, dumpleases, e2fsck, echo,
ed, eject, env, ether_wake, expr, fakeidentd, false, fbset,
fdflush, fdformat, fdisk, find, fold, free, freeramdisk, fsck,
fsck_minix, ftpget, ftpput, fuser, getopt, getty, grep, gunzip,
gzip, halt, hdparm, head, hexdump, hostid, hostname, httpd,
hwclock, id, ifconfig, ifdown, ifup, inetd, init, insmod,
install, ip, ipaddr, ipcalc, ipcrm, ipcs, iplink, iproute,
iptunnel, kill, killall, klogd, lash, last, length, less, ln,
loadfont, loadkmap, logger, login, logname, logread, losetup, ls,
lsattr, lsmod, lzmacat, makedevs, md5sum, mdev, mesg, mkdir,
mke2fs, mkfifo, mkfs_minix, mknod, mkswap, mktemp, modprobe,
more, mount, mountpoint, mt, mv, nameif, nc, netstat, nice,
nohup, nslookup, od, openvt, passwd, patch, pidof, ping, ping6,
pivot_root, poweroff, printenv, printf, ps, pwd, rdate, readlink,
readprofile, realpath, reboot, renice, reset, rm, rmdir, rmmod,
route, rpm, rpm2cpio, run_parts, runlevel, rx, sed, seq, setarch,
setconsole, setkeycodes, setlogcons, setsid, sha1sum, sleep,
sort, start_stop_daemon, stat, strings, stty, su, sulogin, sum,
swapoff, swapon, switch_root, sync, sysctl, syslogd, tail, tar,
tee, telnet, telnetd, test, tftp, time, top, touch, tr,
traceroute, true, tty, tune2fs, udhcpc, udhcpd, umount, uname,
uncompress, uniq, unix2dos, unlzma, unzip, uptime, usleep,
uudecode, uuencode, vconfig, vi, vlock, watch, watchdog, wc,
wget, which, who, whoami, xargs, yes, zcat, zcip

Quite impressive, isn't it? You can call busybox in various ways. The simplest is calling busybox directly with the wanted command as an argument:

busybox ls /

for example. But you can also enter a busybox shell by typing:

busybox sh

This starts a barebones shell that gives you access to all busybox commands, and allows you to have a working command line (On Gentoo Linux, you can have the same by calling /bin/bb, that is called the "rescue shell" in the docs). Another possibility is to symlink commands to the busybox binary. So, if /bin/ls is a symlink pointing to busybox, busybox will know the symlink called and execute ls. This of course has little sense when rescuing a system, but it is often used when busybox is the actual shell of an embedded or very lightweight Linux system.

Having a static busybox (static is important: you want it to be resilient to borked libraries) installed could make the difference between crying in front of a dead Linux that needs to be reinstalled and being able to grin while telling again the geeky story about how you happily rescued your system. Install it now, before it's too late.

No comments: