What is busybox in linux

How to use BusyBox on Linux

BusyBox is an open source (GPL) project providing simple implementations of nearly 400 common commands.

bash logo on green background

It’s easy to take Linux commands for granted. They come bundled with the system when you install Linux, and we often don’t question why they’re there. Some of the basic commands, such as cd , kill , and echo aren’t always independent applications but are actually built into your shell. Others, such as ls , mv , and cat are part of a core utility package (often GNU coreutils specifically). But there are always alternatives in the world of open source, and one of the most interesting is BusyBox.

What is BusyBox in Linux?

BusyBox is an open source (GPL) project providing simple implementations of nearly 400 common commands, including ls , mv , ln , mkdir , more , ps , gzip , bzip2 , tar , and grep . It also contains a version of the programming language awk , the stream editor sed , the filesystem checker fsck , the rpm and dpkg package managers, and of course, a shell ( sh ) that provides easy access to all of these commands. In short, it contains all the essential commands required for a POSIX system to perform common system maintenance tasks as well as many user and administrative tasks.

In fact, it even contains an init command which can be launched as PID 1 to serve as the parent process for all other system services. In other words, BusyBox can be used as an alternative to systemd, OpenRC, sinit, init, and other launch daemons.

BusyBox is very small. As an executable, it’s under 1 MB, so it has gained much of its popularity in the embedded, Edge, and IoT space, where drive space is at a premium. In the world of containers and cloud computing, it’s also popular as a foundation for minimal Linux container images.

Minimalism

Part of the appeal of BusyBox is its minimalism. All of its commands are compiled into a single binary ( busybox ), and its man page is a mere 81 pages (by my calculation of piping man to pr ) but covers nearly 400 commands.

As an example comparison, here’s the output of the shadow version of useradd —help :

 -b, --base-dir BASE_DIR base directory for home -c, --comment COMMENT GECOS field of the new account -d, --home-dir HOME_DIR home directory of the new account -D, --defaults print or change the default config -e, --expiredate EXPIRE_DATE expiration date of the new account -f, --inactive INACTIVE password inactivity -g, --gid GROUP name or ID of the primary group -G, --groups GROUPS list of supplementary groups -h, --help display this help message and exit -k, --skel SKEL_DIR alternative skeleton dir -K, --key KEY=VALUE override /etc/login.defs -l, --no-log-init do not add the user to the lastlog -m, --create-home create the user's home directory -M, --no-create-home do not create the user's home directory -N, --no-user-group do not create a group with the user's name -o, --non-unique allow users with non-unique UIDs -p, --password PASSWORD encrypted password of the new account -r, --system create a system account -R, --root CHROOT_DIR directory to chroot into -s, --shell SHELL login shell of the new account -u, --uid UID user ID of the new account -U, --user-group create a group with the same name as a user

And here’s the BusyBox version of the same command:

 -h DIR Home directory -g GECOS GECOS field -s SHELL Login shell -G GRP Group -S Create a system user -D Don't assign a password -H Don't create home directory -u UID User id -k SKEL Skeleton directory (/etc/skel)

Whether or not this difference is a feature or a limitation depends on whether you prefer to have 20 options or ten options in your commands. For some users and use-cases, BusyBox’s minimalism provides just enough for what needs to be done. For others, it’s a good minimal environment to have as a fallback or as a foundation for installing more robust tools like Bash, Zsh, GNU Awk, and so on.

Читайте также:  What is device tree in linux

Installing BusyBox

On Linux, you can install BusyBox using your package manager. For example, on Fedora and similar:

On Debian and derivatives:

On macOS, use MacPorts or Homebrew. On Windows, use Chocolatey.

You can set BusyBox as your shell using the chsh —shell command, followed by the path to the BusyBox sh application. I keep BusyBox in /lib64 , but its location depends on where your distribution installed it.

$ which busybox /lib64/busybox/busybox $ chsh --shell /lib64/busybox/sh

Replacing all common commands wholesale with BusyBox is a little more complex, because most distributions are «hard-wired» to look to specific packages for specific commands. In other words, while it’s technically possible to replace init with BusyBox’s init , your package manager may refuse to allow you to remove the package containing init for fear of you causing your system to become non-bootable. There are some distributions built upon BusyBox, so starting fresh is probably the easiest way to experience a system built around BusyBox.

Try BusyBox

You don’t have to change your shell to BusyBox permanently just to try it. You can launch a BusyBox shell from your current shell:

Your system still has the non-BusyBox versions of commands installed, though, so to experience BusyBox’s tools, you must issue commands as arguments to the busybox executable:

~ $ busybox echo $0 sh ~ $ busybox ls --help BusyBox vX.YY.Z (2021-08-25 07:31:48 NZST) multi-call binary. Usage: ls [-1AaCxdLHRFplinshrSXvctu] [-w WIDTH] [FILE]. List directory contents -1 One column output -a Include entries that start with . -A Like -a, but exclude . and .. -x List by lines [. ]

For the «full» BusyBox experience, you can create symlinks to busybox for each command. This is easier than it sounds, as long as you use a for-loop:

$ mkdir bbx $ for i in $(bbx --list); do \ ln -s /path/to/busybox bbx/$i \ done

Add your directory of symlinks at the start of your path, and launch BusyBox:

Читайте также:  Mac os make linux usb

Get busy

BusyBox is a fun project and an example of just how minimal computing can be. Whether you use BusyBox as a lightweight environment for an ancient computer you’ve rescued, as the userland for an embedded device, to trial a new init system, or just as a curiosity, it can be fun reacquainting yourself with old familiar, yet somehow new, commands.

Command line prompt

20 essential Linux commands for every user

From new user to power user, here are 20 Linux commands that will make your life easier.

Источник

What is BusyBox in Linux? How to Use it?

Learn why BusyBox has suddenly gained a following among certain Linux users.

BusyBox is getting popular these days, specially among Docker users. Many Docker images use BusyBox to provide you with a minimal image.

And this could leave many users confused specially if you take Linux commands for granted. You think ls, mv and other such commands are part of Linux, while the truth is that these commands are part of GNU Coreutils package and most Linux distributions have it preinstalled.

GNU Coreutils is almost the de facto provider of various UNIX/Linux commands. Almost because there are always alternatives and BusyBox is one such alternative to GNU Coreutils.

What is BusyBox?

BusyBox is an open source project that provides a stripped down implementation of around 400 common UNIX/Linux commands. Stripped down? Yes. BusyBox implementation removes the uncommon, rarely used command options. Everything fits under 1 MB and this minimal image is the reason why it has gained popularity among embedded system and IoT domain as well as in the cloud computing world.

Don’t go by its size. BusyBox has scope for sed and awk like classic editors (stripped down version again) and it contains its own shell too. It even contains an init command which can be launched as PID 1. This means that BusyBox can be configured as an alternative to Systemd, OpenRC etc.

BusyBox is superb alternative to GNU Coreutils specially in cases where the small size of the operating system matters big.

BusyBox gives you popular Linux commands like mv, mkdir, ls etc but it contains only the common used options of these commands. This minimalism is the USP of BusyBox.

Is it a problem that you don’t get the full Linux command options with BusyBox?

That’s depend on your need, really. Most people will never need all the options of a command. Some Linux commands have more than 50 options and I bet you never used all the options of even a single Linux command.

BusyBox cuts down on the rarely used options. For example, the ls command has option G which removes the group name from the long list output (ls -l).

Now, I think you never needed this option. This is why it is not present in the ls implementation of BusyBox. If you really need an output where the group name is not included, all you have to do is to use the cut or awk command for that purpose.

Читайте также:  Установить opera astra linux

Take another example. This is the help page of the mv command from GNU Coreutils:

Usage: mv [OPTION]. [-T] SOURCE DEST or: mv [OPTION]. SOURCE. DIRECTORY or: mv [OPTION]. -t DIRECTORY SOURCE. Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY. Mandatory arguments to long options are mandatory for short options too. --backup[=CONTROL] make a backup of each existing destination file -b like --backup but does not accept an argument -f, --force do not prompt before overwriting -i, --interactive prompt before overwrite -n, --no-clobber do not overwrite an existing file If you specify more than one of -i, -f, -n, only the final one takes effect. --strip-trailing-slashes remove any trailing slashes from each SOURCE argument -S, --suffix=SUFFIX override the usual backup suffix -t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY -T, --no-target-directory treat DEST as a normal file -u, --update move only when the SOURCE file is newer than the destination file or when the destination file is missing -v, --verbose explain what is being done -Z, --context set SELinux security context of destination file to default type --help display this help and exit --version output version information and exit 

Now, here is the mv command help page from BusyBox:

Usage: mv [-fin] SOURCE DEST or: mv [-fin] SOURCE. DIRECTORY Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY -f Don't prompt before overwriting -i Interactive, prompt before overwrite -n Don't overwrite an existing file 

How to get BusyBox?

There are various ways you get BusyBox.

If you simply want to experience BusyBox on your current Linux distribution, you can install it using your distribution’s package manager like Apt or DNF or Yum.

On Ubuntu, you can use this command to install BusyBox:

After that, if you want to run the BusyBox version of a command, you have to add busybox before it.

If a command is not implemented by BusyBox, it throws an error that ‘applet not found’.

[email protected]:~$ busybox xyz xyz: applet not found 

Alternatively, you can download the Docker image of BusyBox and experience it in a running container.

Please make sure that you have Docker installed. Pull the official docker image:

Run a container from the image and enter the BusyBox shell:

Every Linux command you run here comes from BusyBox. You don’t need to specify it explicitly.

BusyBox in docker container

Altogether, you don’t need BusyBox on a regular Linux system. You already have full version of the Linux commands from GNU Coreutils there. There is no need to install a stripped down version.

But BusyBox has its usage in special areas like when you are configuring a minimal Linux OS for embedded or IoT device. The same goes when you want to keep the size of your Docker image small.

I hope you have a better understanding of BusyBox. If you need any clarification or have a suggestion, please let me know in the comments.

Источник

Оцените статью
Adblock
detector