Click the card below to follow and star!
Reply “1024” to receive2TB of learning resources!
Introduction to Busybox
Busybox is an open-source, lightweight collection of software tools designed to provide a streamlined set of Unix tools for embedded systems and resource-constrained environments. It combines many commonly used Unix tools (like ls, cp, cat, mv, grep, find, telnet, etc.) into a single executable file, thus reducing system storage space and resource usage.
-
Official website: https://busybox.net/
The main features of Busybox include:
Streamlined: The design philosophy of Busybox is to combine multiple tools into a single executable file to reduce system storage space and resource usage.
Customizability: Busybox provides many compilation options to select the required tools and exclude unnecessary ones, further reducing the size of the executable file.
Compatibility: The tools of Busybox have similar command-line interfaces and functionalities as traditional Unix tools, making it easy to replace them.
Using Busybox
The compilation process of busybox is similar to that of the Linux kernel.
There are three ways to use busybox:
-
Directly follow the command with busybox, such as busybox ls -
Rename busybox directly, such as cp busybox tar -
Create symbolic links, such as ln -s busybox rm
Among these methods, the third method is the most convenient, but it creates a soft link for each command in busybox, which can be cumbersome. Busybox provides an automatic method: after compiling busybox successfully, execute make install, which will create an _install directory containing busybox and soft links for each command.
The usage of Busybox is similar to traditional Unix tools, with the usual syntax format being:
busybox [options] [command] [arguments]
Arguments
The commands and arguments of Busybox depend on the specific tools, and help information can be obtained in the following ways:
busybox --help
Advantages and Disadvantages of Busybox Tools
Advantages
-
Lightweight: The executable file is very small, suitable for resource-constrained environments. -
Flexibility: Provides many compilation options to select required tools and exclude unnecessary ones. -
Compatibility: The tools of Busybox have similar command-line interfaces and functionalities as traditional Unix tools, making it easy to replace them.
Disadvantages
-
Functionality Limitations: Due to the design goal of Busybox to provide a streamlined toolset, certain advanced features may not be supported. -
Learning Curve: Users unfamiliar with Busybox may need some time to adapt to its command-line interface and tool usage.
Other Features
In addition to the previously mentioned content, Busybox also has the following features:
-
Support for Cross-Compilation: Busybox can be cross-compiled on one host to generate executable files suitable for different architectures. -
Provides some additional tools: Besides common Unix tools, Busybox also provides some additional tools, such as network tools, file system tools, etc.
Compiling and Installing Busybox
The compilation and installation process of Busybox:
Install Dependencies
yum -y install gcc gcc-c++ glibc glibc-devel make pcre pcredevel openssl openssl-devel systemd-devel zlib-devel glibc-static ncurses-devel
Download Busybox source code:
wget https://busybox.net/downloads/busybox-x.x.x.tar.bz2
Extract the source code package:
tar -xvf busybox-x.x.x.tar.bz2
Enter the source code directory:
cd busybox-x.x.x
Configure compilation options:
make menuconfig
# Select below to compile busybox as a static binary without shared libraries:Settings -->Build Options -->[*] Build static binary (no sharedlibs)
Compile the source code:
make
Install Busybox:
make install
The installation process will copy the Busybox executable file to the specified directory.
Configure Environment Variables
Add the directory where the Busybox executable file resides to the system’s PATH environment variable so that Busybox tools can be used directly.
Verify the installation result: Run the following command to verify if Busybox is installed successfully:
busybox
If installed successfully, the help information of Busybox will be displayed. During the compilation and installation of Busybox, some common problems and pitfalls may occur.
Here are some common problems and solutions summarized
Problem 1: Compilation or linking errors.
Solution: Check if the compilation environment meets the requirements, ensure that the required dependency libraries are installed, and configure correctly according to the compilation options.
Problem 2: Unable to execute Busybox commands after installation.
Solution: Check if the environment variable configuration is correct, ensure that the directory where the Busybox executable file resides is added to the system’s PATH environment variable.
Problem 3: Some tools do not work properly.
Solution: Check if the compilation options are configured correctly, ensure that the required tools are included in the compilation options, and recompile and reinstall Busybox.
Case 1: File System Repair
Assuming that the file system of the embedded device has issues, you can use the tools in Busybox to repair it.
First, check the available file system repair tools with the following command:
busybox --list | grep fsck
This will list the available file system repair tools in Busybox, such as fsck.ext2, fsck.ext3, etc.
Select the appropriate tool for the file system to perform repairs:
busybox fsck.<file system type> <device path>
For example, if your file system is ext4 and the device path is /dev/sda1, the command would be:
busybox fsck.ext4 /dev/sda1
Busybox will run the corresponding file system repair tool to check and fix errors in the file system.
Case 2: Network Configuration
Check the available network tools with the following command:
busybox --list | grep ifconfig
This will list the corresponding available network tools in Busybox, such as ifconfig, ip, etc.
Configure the IP address and subnet mask for the network interface:
busybox ifconfig <network interface> <IP address> netmask <subnet mask>
For example, to configure the eth0 interface with an IP address of 192.168.1.10 and a subnet mask of 255.255.255.0:
busybox ifconfig eth0 192.168.1.10 netmask 255.255.255.0
Busybox will configure the specified network interface’s IP address and subnet mask.
Add a default gateway:
busybox route add default gw <default gateway IP> <network interface>
For example, if the default gateway is 192.168.1.1 and the network interface is eth0:
busybox route add default gw 192.168.1.1 eth0
That’s all for today’s sharing. If it helps, please give us a thumbs up and support us!
MySQL|PostgreSQL|Redis|MongoDB|Tools
ElasticSearch|Kubernetes|Docker|Hadoop
Kafka|RabbitMQ|Zookeeper|OpenStack
Enterprise Monitoring Platform|Applications and Services|DevOps|Cluster Management
Building a high-quality technical exchange community, welcome those engaged in backend development and operation and maintenance technology to join (please note your position, do not re-add if already in the technical exchange group). Mainly focused on technical exchange, internal referrals, and industry discussions, please speak civilly. Advertisers are not allowed, do not trust private messages to avoid being scammed.
Scan to add me as a friend, and I will pull you into the group
PS: Because the WeChat official account platform has changed the push rules, if you don’t want to miss the content, remember to finish reading and click“Looking”, and add a“Star” so that new articles will appear in your subscription list as soon as they are pushed. Click“Looking” to support us!