28
Aug

Creating Busybox Links

This tip came in from a subscriber/regular contributor. It’s a script for quickly creating busybox links based on the commands included in your build. I know it will be helpful to somebody out there.

Hi Derek,

Dunno if you are still doing your “DailyLinux” thing, but here’s
a bit of script I knocked together today to create busybox links.
Yes I know there is an “–install” option on a lot of busybox builds,
but it doesn’t seem to play well with installing in a chroot area.

So copy the busybox executable into the “bin” directory…

cp -p /bin/busybox /data/chroot/bin

and cd into that directory

cd /data/chroot/bin

Then run this shell snippet…

  ./busybox  --help | \
  sed -e '1,/^Currently defined functions:/d' \
      -e 's/[ \t]//g' -e 's/,$//' -e 's/,/\n/g' | \
  while read app ; do
    if [ "$app" != "" ]; then
      printf "linking %-12s ...\n" "$app"
      ln -sf "./busybox" "$app"
      ls -ld "$app"
    fi
  done

and all the links for the apps built-in to the busybox version you have
get built for you.

It takes advantage of the fact that “busybox –help” gives a list of the
built apps at the end of its output, after the line “Currently defined
functions:”. The sed script, removes all line upto and including this line,
and then removes spaces, tabs and trailing commas, then it converts all
commas to newlines. This gives a list of apps, one app to a line. The while
loop reads each line and does the linking.

Dunno if this would interest anyone else.

all the best
Jim

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:


There's 4 Comments So Far

  • Jim Jackson
    September 24th, 2012 at 5:33 am

    Dunno, if commenting on one’s own post is good etiquette or not, but here goes…

    Recent versions of busybox may support the command line options “–list” and “–list-full”. This obviates the need for the convoluted “sed”ery in my script. Just replace the multiline “sed” with

    busybox –list | &#92

    Check that your version of busybox supports this option first!

    Jim

  • Jim Jackson
    September 24th, 2012 at 5:34 am

    Oh dear – the “&#92” is supposed to be a backslash character ‘\’

    Jim

  • Simon
    July 10th, 2014 at 1:38 pm

    Than you very much Jim! This is exactly what I needed. The only hiccup I had was that I was using this on Android (I can’t use the graphical tool), which ships with some copies of these tools, but they are very, very basic.
    Easy enough to fix though. Since we already know there is a busybox package in the current directory, I just prepended every command with ./busybox!
    My final script is
    busybox –list | \
    while read app ; do
    if [ “$app” != “” ]; then
    ./busybox printf “linking %-12s …\n” “$app”
    ./busybox ln -sf “./busybox” “$app”
    ./busybox ls -ld “$app”
    fi
    done

  • Simon
    July 10th, 2014 at 4:40 pm

    After two hours of crashed time, I would like to tell anyone who is doing this on Android to make sure to backup and restore the original su binary (if it is going to be overwritten) because busybox’s su does not work on Android!
    Additionally, it’s not a bad idea to have an su in both /system/bin and /system/xbin, which is all that saved me from myself this time…

Share your thoughts, leave a comment!