Red Hat 9.0. 编译busybox

本文档详细介绍了如何使用 crosstool-3.3.2 和 crosstool-3.4.1 工具链在 Red Hat 9.0 系统上为 Linux 2.4.18 内核编译 BusyBox 1.20 的过程。包括所需工具下载、配置步骤、编译选项设置以及常见问题解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://snakego.blog.163.com/blog/static/19849382200771244759656/

It's a nice day for me to write this note which will  show you the compilation process of BusyBox1.20.And what I must point out that are my linux kernel version is 2.4.18 and host computer system is Red Hat 9.0.
 
 Now you must download some tools before doing this.the list as follow:

1.BusyBox1.20; you can download it from http://www.busybox.net/    and there you can find the  FAQ.

2.crosstool-3.3.2(arm-linux 3.3.2); you can find it in http://handhelds.org/download/projects/toolchain/
please download the crosstool-3.4.1 too.It may be helpful.

3.For your embedded system you must have your embedded mainboard and root file system. And i have a SBC3410 and a yaffs file system.you can download file systems in other web sites.

 For decompressing files you may have to use the commads:
                    tar xvzf XXXX.tgz -C /address
and  
                    tar xzvj XXXX.tar.bz2 -C /address
  
  How to setup crosstools ?
                        tar xvzf arm-linux-gcc-3.3.2.tgz -C /
 Add one line to /etc/profile as follow:

# Path manipulation
if [ `id -u` = 0 ]; then
        pathmunge /sbin
        pathmunge /usr/sbin
        pathmunge /usr/local/sbin
        pathmunge /usr/local/arm/3.3.2/bin
fi

Reboot to take effect.

Now just do it!

1.
 # cd busybox1.2.0/
 # make menuconfig

 there is some suggestion for you to setup you new busybox:

Build Options->
[*]Build BusyBox as a static binary(no share libs)
             Than your busybox can be executed without share libs
[*]Do you want to BusyBox with a cross compiler
 here you can fill this :arm-linux-

Installation Options->
[*]Don't use /user
         Apples links ->
                 ./new_busybox/

 Choice this will not replace your host computer's BusyBox after you "make install", and it will build new BusyBox to "./new_busybox".

Than you choose futions which you want.
for example, I would like my embedded mainboard have futions of "mount nfs support", "telnet server" and "modules utilities"

mount nfs support
         [*]mount
                   [*]Support mounting NFS file system.

telnet server
         [*]telnetd

modules utilities
          [*]insmod
                      ...
          [*]rmmod

          [*]lmmod
                      ...
          [*]nodprobe
                       ...
exit setting and save your configuration.

# make clean

# make

#make install

  if there is no error when compiling your BusyBox, it will make two folders and one linker in ./new_buybox.
  now copy them to you root file system and replace the older,and then you make your new root file system and download it to your embedded mainboard.
  If your don't want to change  your embedded file system, replace them straightway;

Some FAQ happen to me:

1.many errors came out when i was compiling Busybox-1.2.0,1.1.3 and 1.3.0 with the crosstool-2.95.3

2.when i use crosstool-3.4.1 to compile Busybox-1.2.0,1.1.3 and 1.3.0 there are some errors if you choice any option in modules utilities.

3.crosstool-3.3.2 can complete success to build a new BusyBox1.2.0, but the telnet server doesn't work.

How did I deal with those problems?

1.Never use crosstool-2.95.3,it may just can compile BusyBox1.0.X.

2.Using crosstool-3.4.1 to compile Busybox-1.2.0 with no "modules utilities"  selection.supposing the new busybox in ./new-bosybox-3.4.1

3.Compile Busybox-1.2.0 with all futions i want by crosstool-3.3.2.It works best,and it supports 2.4 kernel well.supposing the new busybox in ./new-bosybox-3.3.2

4.Copy "insmod", "lsmod" and "rmmod" form ./new-bosybox-3.3.2/sbin  to (replace the linkers in) ./new-bosybox-3.3.2/sbin. and you can see that what you just have copy are not linkers, they are programs!
 Doing this you must not use graphical interfaces, or it will copy linkers to replace linkers.

 

<think>好的,我现在需要解决用户的问题:当PATH环境变量已经包含/usr/bin/busybox时,为什么在其他目录执行./busybox会报错“No such file or directory”,以及如何解决这个问题。首先,我得仔细分析可能的原因。 首先,用户提到在PATH中有/usr/bin,而busybox位于该目录下。当他们在另一个目录下执行./busybox时,系统报错找不到文件或目录。这可能涉及到几个方面的问题。 第一个可能性是当前目录下的busybox文件是否存在。如果用户执行的是./busybox,而当前目录下并没有这个可执行文件,自然会报错。这时候需要检查该目录是否存在busybox,或者是否拼写错误。比如用户可能误输入了路径或者文件名。 第二个可能性是文件权限问题。即使文件存在,如果没有执行权限,系统也会拒绝执行。这时候需要检查busybox文件的权限设置,使用ls -l查看是否有x权限,如果没有,需要用chmod +x busybox添加执行权限。 第三个可能性是文件系统挂载问题。如果当前目录所在的文件系统没有正确挂载,或者busybox所在的目录(比如/usr/bin)被挂载为只读,可能导致无法执行。这时候需要检查mount命令的输出,确认相关文件系统的挂载状态和权限。 另外,用户提到PATH环境变量已经包含/usr/bin,所以直接运行busybox应该可以找到,但问题出在执行./busybox,这说明用户可能试图运行当前目录下的另一个busybox实例。这里可能存在动态链接库的问题。如果这个busybox是静态链接的,应该没问题,但如果是动态链接的,而目标系统的库路径不正确,就会导致找不到依赖库。这时候需要用ldd命令检查busybox的依赖库是否存在,并确保库路径正确,可能需要将库文件复制到文件系统的相应位置,如引用[2]提到的拷贝库文件到lib目录。 还有可能是架构不兼容的问题。比如busybox是为arm架构编译的,而当前系统是x86的,导致无法执行。需要用file命令检查busybox的架构信息,确认与当前系统匹配。 总结可能的原因: 1. 当前目录下没有busybox文件 2. 权限不足,无法执行 3. 动态链接库缺失或路径错误 4. 文件系统挂载问题 5. 架构不兼容 解决方案对应步骤: 1. 检查当前目录是否存在busybox,使用ls查看 2. 检查文件权限,使用chmod添加执行权限 3. 使用ldd检查依赖库,补充缺失的库文件 4. 检查文件系统挂载状态 5. 确认busybox的架构是否匹配 此外,引用[3]中提到在编译busybox时缺少curses.h,可能涉及依赖库安装的问题,但当前问题可能不同。引用[4]提到在Mobaxterm中设置PATH后解决git的问题,可能提示检查环境变量是否被正确覆盖或冲突。但用户的问题是在特定目录执行./busybox,可能与环境变量无关,因为./使用的是相对路径,而非PATH中的路径。 另外,引用[2]中提到的将库文件复制到lib目录,可能需要用户确保动态链接库的路径正确,尤其是在交叉编译环境下,可能需要将相应的arm库文件复制到目标文件系统的lib目录中。 可能还需要检查busybox是否被正确编译和安装,或者是否损坏。可以通过md5sum检查文件完整性,或者重新下载/编译busybox。 最后,如果用户是在chroot环境中运行,可能会遇到引用[1]中的问题,即缺少必要的二进制文件,比如/bin/bash不存在,导致无法执行。但用户的问题是关于busybox本身,所以需要确认执行环境是否正确,是否缺少依赖的组件。</think>### 问题原因分析 当系统环境变量 `PATH` 包含 `/usr/bin/busybox` 时,在另一路径下执行 `./busybox` 报错 `No such file or directory`,可能由以下原因导致: 1. **文件路径或名称错误** 执行 `./busybox` 时,系统会尝试在当前目录下查找 `busybox` 可执行文件。若当前目录不存在此文件,或文件名拼写错误(如大小写不一致),则会触发此错误。 2. **文件权限问题** 即使文件存在,若未赋予可执行权限,系统会拒绝执行。可通过以下命令检查权限: ```bash ls -l ./busybox ``` 若无 `x` 权限,需使用 `chmod +x ./busybox` 添加。 3. **动态链接库缺失** 若 `busybox` 是动态链接编译的,但目标系统缺少依赖的动态库(如 `libc.so`),则会报错。可通过以下命令检查依赖库: ```bash ldd ./busybox ``` 若显示 `not found`,需将依赖库复制到文件系统的 `/lib` 或 `/usr/lib` 目录[^2]。 4. **架构不兼容** 若 `busybox` 是为其他架构(如 ARM)编译的,而在 x86 系统上运行,会导致无法执行。可使用 `file ./busybox` 检查二进制文件架构。 --- ### 解决方案 1. **验证文件存在性** 确认当前目录下存在 `busybox` 文件: ```bash ls ./busybox ``` 2. **检查并修复权限** 添加可执行权限: ```bash chmod +x ./busybox ``` 3. **修复动态链接库问题** - 若依赖库缺失,需将编译环境的库文件(如 `/usr/local/arm/.../libc/lib` 下的 `.so` 和 `.a` 文件)复制到目标系统的 `/lib` 目录[^2]。 - 使用静态编译版本的 `busybox`(编译时添加 `CONFIG_STATIC=y` 选项)。 4. **验证架构兼容性** 确保 `busybox` 的编译架构与当前系统匹配: ```bash file ./busybox ``` 5. **检查文件系统完整性** 若在 `chroot` 环境中操作,需确保 `/bin/bash` 等基础组件存在[^1]。若使用 `busybox` 替代标准工具链,需正确配置符号链接。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值