busybox

最後更新: 2019-09-13

介紹

BusyBox combines tiny versions of many common UNIX utilities into a single small executable.

好處:

  • size-optimization
  • limited resources in mind
  • extremely modular (This allows you to include only the components you need)

HomePage: http://www.busybox.net/

License: GPL

DOC: http://www.busybox.net/downloads/BusyBox.html

Trial - live_bbox (Javascript PC Emulator)

https://busybox.net/live_bbox/live_bbox.html

 


安裝

 

busybox isn't available for centos 7, 8

Get Source

cd /usr/src

wget https://busybox.net/downloads/busybox-1.30.1.tar.bz2

tar -jxf busybox-1.30.1.tar.bz2

Configure Busybox

make help

# The end result is a .config file that tells the Busybox build process what features to include.

make allnoconfig              # Disable everything.

make defconfig                 # This enables almost all features, minus things like debugging options and
                                       # features that require changes to the rest of the system to work

make menuconfig            # yum install dialog ncurses-devel

make config

Build

make clean

make defconfig

make busybox

ll -sh busybox

2.6M -rwxr-xr-x 1 root root 2.6M Oct  4 11:20 busybox

# install busybox into CONFIG_PREFIX

make install

 


Build Static Version

 

yum install glibc-static

[方式1]

set the environment variable "LDFLAGS=--static"

LDFLAGS="--static" make -j 4

[方式1]

make menuconfig

Settings --> "Build Options" Section-->[*]  Build static binary (no shared libs)

 


Usage

 

Version:

busybox -v

Help:

busybox ls --help

Usage:

busybox [function] [arguments]...

列出所有 function:

busybox --list  OR  busybox

[, [[, arp, ash, awk, basename, bash, cat, chmod, cmp, cp, cut, date, dc, dd, df,
dirname, dmesg, dnsdomainname, du, echo, egrep, env, expr, false, fgrep, find,
free, getopt, grep, gunzip, gzip, halt, head, hexdump, hostname, id, ifconfig,
insmod, install, kill, killall, klogd, less, ln, logger, login, logread, ls,
lsmod, md5sum, mkdir, mkfifo, mknod, more, mount, mv, nc, netstat, nslookup,
pidof, ping, poweroff, printf, ps, pwd, reboot, rm, rmdir, rmmod, route,
run-parts, rx, sed, sendmail, seq, sh, sleep, strings, stty, sync, syslogd, tail,
tar, telnet, telnetd, test, time, top, touch, tr, traceroute, true, umount, uname,
uniq, uptime, usleep, vconfig, vi, wc, wget, which, xargs, yes, zcat

e.g.

./busybox ls -l

./busybox ps

./busybox seq 1 5

Setup

symlinks:

This is a statically linked version of the Busybox "multiplexer",

a single command that can perform multiple actions,

the way a swiss army knife has multiple blades.

To try it out, give Busybox the command line you'd like it to execute:

ln -s busybox pwd

./pwd

Setup All Tools:

/home/chroot_ssh 是一個 chroot 環境來

mkdir /home/chroot_ssh/bin
cp busybox /home/chroot_ssh/bin
cd /home/chroot_ssh/bin
for i in $(./busybox --list)
do
    ln -s busybox $i
done

To launch Busybox's built-in command shell with the $PATH

PATH=$(pwd) ./sh

 


seq

 

SYNOPSIS

       seq [OPTION]... LAST
       seq [OPTION]... FIRST LAST
       seq [OPTION]... FIRST INCREMENT LAST

seq 3

1
2
3

seq 3 5

3
4
5

Opts

-s, --separator=STRING              # use STRING to separate numbers (default: \n)

 


Tools

 

ash

Environment Variable 設定 File

  • $HOME/.profile
  • /etc/profile

PATH

The default search path for executables. See the above section Path Search.

HISTSIZE

The number of lines in the history buffer for the shell.

PS1

The primary prompt string, which defaults to ''$ '',

unless you are the superuser, in which case it defaults to ''# ''.

PS2

The secondary prompt string, which defaults to ''> ''.

/etc/profile

PATH="/bin:/usr/bin"
HISTSIZE=1000
export PATH HISTSIZE

nslookup

# 不支援其他 records -__-

nslookup [HOST] [SERVER]

vi

vi --version

BusyBox v1.19.0 (2012-02-29 14:20:08 PST) multi-call binary.

Notes:

應用 ESXi 的 vi 是 busybox vi 來

Disable autoindent when pasting in BusyBox 's vi

由於沒有 ":no autoindent", ":set paste" 亦無效, 要用 ":set noautoindex" (:set noai)

Undo functionality

busybox vi has very limited undo functionality. All you can do is to revert all the changes in the current line using U command.
But you can only do it as long as you don't move to any other line.
Unfortunately there 's no redo, individual change undo or multilevel undo.

features - print features list

:features

 

 

Creative Commons license icon Creative Commons license icon