11

What are BusyBox and ash?

I have never seen a good explanation to what they are.

I've used ash and I know it's a Linux shell, but I would like to get a real understanding of it.

Pengor
  • 3
Kaz Wolfe
  • 34,122
  • 21
  • 114
  • 172

2 Answers2

13

Ash is a simple unix shell, as compared to bash, which is the more typical fully featured shell preferred on Linux systems.

Busybox is a program that implements an ash like shell, as well as a number of other common unix programs, though in a stripped down version, all in a single program. It is intended to provide a semi-typical unix like environment in a very space limited environment, hence, why it implements many ( stripped down ) programs as single program, and then has the separate program commands symlinked to the busybox binary, which figures out which program it is supposed to emulate and does its best to behave in a similar way to the fully featured program that it is replacing.

Busybox was originally developed for use in very space limited environments such as a single floppy boot disk, and continues to see use today in space limited environments like embedded systems such as dd-wrt.

guntbert
  • 13,134
psusi
  • 37,551
6

What is busybox and how does it contain many executables within one executable?

Let me expound upon @psusi's answer.

@psusi said (emphasis added):

Busybox is a program that implements an ash like shell, as well as a number of other common unix programs, though in a stripped down version, all in a single program...hence, why it implements many ( stripped down ) programs as single program, and then has the separate program commands symlinked to the busybox binary, which figures out which program it is supposed to emulate and does its best to behave in a similar way to the fully featured program that it is replacing.

Check this out. The following is interesting, and confirms what is said in the quote above.

Here is a snippet from the beginning of the output from ls -alF /bin on an embedded Linux device. As you can see, nearly all the executables in /bin are actually symlinks to /bin/busybox (and can be called with /bin/busybox <cmd>, by the way):

/bin# ls -alF /bin
total 1184
drwxr-xr-x    2 root     root          4096 Nov 11  2021 ./
drwxr-xr-x   22 root     root          4096 Nov 11  2021 ../
lrwxrwxrwx    1 root     root             7 Nov 11  2021 arch -> busybox*
lrwxrwxrwx    1 root     root             7 Nov 11  2021 ash -> busybox*
lrwxrwxrwx    1 root     root             7 Nov 11  2021 base64 -> busybox*
-rwsr-xr-x    1 root     root        709792 Nov 11  2021 busybox*
lrwxrwxrwx    1 root     root             7 Nov 11  2021 cat -> busybox*
-rwxr-xr-x    1 root     root         10288 Nov 11  2021 chattr*
lrwxrwxrwx    1 root     root             7 Nov 11  2021 chgrp -> busybox*
lrwxrwxrwx    1 root     root             7 Nov 11  2021 chmod -> busybox*
lrwxrwxrwx    1 root     root             7 Nov 11  2021 chown -> busybox*
-rwxr-xr-x    1 root     root          1342 Nov 11  2021 compile_et*
lrwxrwxrwx    1 root     root             7 Nov 11  2021 cp -> busybox*
lrwxrwxrwx    1 root     root             7 Nov 11  2021 cpio -> busybox*
lrwxrwxrwx    1 root     root             7 Nov 11  2021 date -> busybox*
lrwxrwxrwx    1 root     root             7 Nov 11  2021 dd -> busybox*
lrwxrwxrwx    1 root     root             7 Nov 11  2021 df -> busybox*

So, if you run ash, which ash shows that the ash executable is located at /bin/ash, and ls -alF /bin/ash shows that that executable is a symlink to busybox. Notice /bin/ash -> busybox*, where the * at the end is due to the ls -F flag and means "executable":

/bin# la -alF /bin/ash
lrwxrwxrwx    1 root     root             7 Nov 11  2021 /bin/ash -> busybox*

So, running ash is the same as running /bin/ash which is the same as running busybox ash which is the same as running /bin/busybox ash.

Once I run any of those ash or busybox ash cmds I can see that the output of echo $0 has changed from -sh to ash, meaning I am now running the ash shell inside the default -sh shell. exit will bring me back out of the ash shell and back into the -sh shell.

To see all the programs busybox can run, simply type busybox or busybox --help and it will spit out a big list of all of the programs compiled into its binary. Or, use busybox --list to see them all on a separate line. Run them as:

busybox program_name args

Anyway, busybox is a popular program for small embedded Linux devices where Linux is a custom build using build tools such as Buildroot or Yocto, the two main ones.

What is ash?

Summary:

Ash is a shell or terminal program. Kenneth Almquist made ash on 30 May 1989, barely predating bash, which was released just one week later on 8 June 1989. Herbert Xu ported ash to Debian Linux in 1997 and called it dash for "Debian Almquist shell".

Busybox contains an implementation of ash, which implementation is a derivative of dash, and which is "the most complete and most pedantically correct shell included with busybox."

Details:

In the context of busybox, ash is a shell built in to busybox and which can be run by calling busybox ash, as explained above.

The busybox source code states here that its built-in version of ash is (emphasis added):

The most complete and most pedantically correct shell included with busybox. This shell is actually a derivative of the Debian 'dash' shell (by Herbert Xu), which was created by porting the 'ash' shell (written by Kenneth Almquist) from NetBSD.

When it says that busybox's ash is "the most complete and pedantically correct shell included with busybox", it isn't 100% clear to me, but it appears that busybox's ash has a bunch of build options to make it bash-like, and more complete, like bash. Search these files for "bash" for instance to see a ton of references to what appear to be options to make ash act like bash:

  1. busybox/shell/ash.c
  2. busybox/shell/Config.src

According to Wikipedia's Almquist shell article, The original version of ash is the Almquist shell, initially released 30 May 1989.

Compare this to bash, which was released just 1 week later on 8 June 1989!

Also according to the Wikipedia Almquist shell article above, dash was a port of ash to Debian Linux (emphasis added):

In 1997 Herbert Xu ported ash from NetBSD to Debian Linux. In September 2002, with release 0.4.1, this port was renamed to Dash (Debian Almquist shell). Xu's main priorities are POSIX conformance and slim implementation.

And, based on the quote above from the busybox source code, busybox's ash "is actually a derivative of the Debian dash shell (by Herbert Xu)".

See also:

  1. https://unix.stackexchange.com/questions/82357/what-do-the-symbols-displayed-by-ls-f-mean/82358#82358
  2. What do the symbols like =, * and | in the output of "ls -F" mean?
  • 3
    This answer is just amazing, with lots of details and demystifications! I was desperately searching about it, but found it so hard to have proper in depth explanations... Thanks a lot. – DevOps Craftsman Nov 25 '22 at 21:06