Busybox is described on its manual page as the swiss army knife of embedded Linux. It combines small versions of common UNIX utilities into a single small executable. It provides around 400 implementations of Linux commands such as more, less, head, tail, grep, awk, sed, dpkg, all compiled into a single binary.
This executable is small in size (below 1MB) and thus useful in situations whereby we are limited in terms of disk space e.g running an entire temporary operating system on a RAM disk, embedded systems, mobile devices, and such.
Busybox looks at the name by which it is called by and will act according to the desired program, for example if we call busybox through a symbolic link ls, it will perform an action resembling ls command similarly if we call it through the mkdir symbolic link, it performs actions similar to mkdir.
Installing BusyBox in Linux
On Linux, you can install BusyBox using your default package manager as shown.
$ sudo apt install busybox [On Debian, Ubuntu and Mint] $ sudo yum install busybox [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a sys-apps/busybox [On Gentoo Linux] $ sudo pacman -S busybox [On Arch Linux] $ sudo zypper install busybox [On OpenSUSE] $ sudo apk add busybox [On Alpine] $ docker run cmd.cat/busybox busybox [On Docker]
If your current Linux distribution is not mentioned here you can check out the link in the references section on how to install it.
How to Use BusyBox in Linux
To get started, execute the command busybox without any options or flags.
# busybox
The output is a list of all commands supported by the busybox along with other useful options.
To view the exact commands we can list them as follows:
# busybox --list
To view the file size of the binary we write.
# cd /usr/sbin/ && du -h busybox
A much clearer picture is obtained when we compare a command’s options from the Linux shell and the busybox shell.
# grep --help [Shell] # busybox grep --help [Busybox]
As you can see from the output of both executions some of the options from the Linux shell are not available in the output from busybox. In most cases, we will find that busybox options are all we need to perform specific tasks in common applications such as IoT devices.
To be able to use busybox commands, we write the commands preceded by the busybox keyword, for example, to search for a string using the grep command we write.
# busybox grep "SearchString" file.txt
The above command works similarly to the one in a Linux shell.
Alternatively, we can also access the busybox shell and avoid using the busybox keyword every time we need to execute commands as follows.
# busybox sh
While in the shell we can execute commands normally as if we were in a Linux shell.
# grep "SearchString" file.txt
To exit the shell write.
# exit
Busybox is written with considerations for limited resources and size optimizations. Its modularity allows inclusion and exclusion of commands/features at compile-time, in that, we can include only components we need and therefore this makes it easy to customize its implementation in systems such as mobile, embedded, etc.
Generally speaking, we don’t need a busybox in our Linux systems since we already have the full package, as mentioned it is useful in cases whereby we have a limited amount of disk space to work with.