移植BusyBox

来源:互联网 发布:怎么申请做淘宝客 编辑:程序博客网 时间:2024/06/04 18:41

转载一篇文章:过程很详细,值得参考

一)移植BusyBox
下载busybox的源码包,最新版本为busybox-1.15.0
http://www.busybox.net/downloads/

解压并进入目录:
# tar jxvf busybox-1.15.0.tar.bz2
# cd busybox-1.15.0

修改Makefile:
# gedit Makefile &

把 164 行修改为:
CROSS_COMPILE = /opt/arm-2009q1/bin/arm-linux-

把 189 行修改为:
ARCH = arm

配置:
# make menuconfig

选上以下几项:
Busybox Settings --->
         Build Options --->
               [*] Build BusyBox as a static binary (no shared libs)
               [*] Build with Large File Support (for accessing files > 2 GB)
         Busybox Library Tuning --->
               [*] vi-style line editing commands
               [*] Fancy shell prompts
Linux Module Utilities --->
        [ ] Simplified modutils
        [*] insmod
        [*] rmmod
        [*] lsmod
        [*] modprobe
        [*] depmod
 

退出并保存配置。

编译:
# make

安装:
# make install

在busybox-1.15.0目录下可以找到_install子目录,这就是刚才的安装目录。

二)加入必要的目录与文件
改名为最小化根文件系统目录:
# mv _install mini_rootfs

进入最小化根文件系统目录:
# cd mini_rootfs

在mini_rootfs目录里建立一个名为create_rootfs.sh的脚本文件:
#!/bin/sh

#root dir
mkdir bin sbin lib etc dev sys proc tmp var opt mnt usr home root media

#usr sub dir
cd usr
mkdir bin sbin lib local
#usr/local sub dir
cd local
mkdir bin sbin lib
cd ../..

#etc sub dir
cd etc
touch inittab
touch fstab
touch profile
touch passwd
touch group
touch shadow
touch resolv.conf
touch mdev.conf

touch inetd.conf

mkdir rc.d
mkdir init.d
touch init.d/rcS
chmod +x init.d/rcS
mkdir sysconfig
touch sysconfig/HOSTNAME
cd ..

#dev sub dir
cd dev
mknod console c 5 1
chmod 777 console
mknod null c 1 3
chmod 777 null
cd ..

#var sub dir
cd var
mkdir log
cd ..
 

为create_rootfs.sh脚本加上可执行权限:
# chmod +x create_rootfs.sh

执行该脚本以生成最小化根文件系统所需要的目录与文件:
# ./create_rootfs.sh

拷贝交叉编译器里的动态链接库到最小化根文件系统的 lib 和 usr/lib 目录:

# cp -f /opt/arm-2009q1/arm-none-linux-gnueabi/libc/armv4t/lib/*so* lib -a

# cp -f /opt/arm-2009q1/arm-none-linux-gnueabi/libc/armv4t/usr/lib/*so* usr/lib -a

etc/fatab文件的内容为:
# /etc/fstab: static file system information.
#
# Use 'vol_id --uuid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#

proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /var tmpfs defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
tmpfs /dev tmpfs defaults 0 0
 

etc/inittab文件的内容为:
::sysinit:/etc/init.d/rcS
s3c2410_serial0::askfirst:-/bin/sh
::ctrlaltdel:-/sbin/reboot
::shutdown:/bin/umount -a -r
::restart:/sbin/init
 

etc/profile文件的内容为:
# Ash profile
# vim: syntax=sh

# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

USER="`id -un`"
LOGNAME=$USER
PS1='[\u@\h \W]\# '
PATH=$PATH

HOSTNAME=`/bin/hostname`

export USER LOGNAME PS1 PATH

 


export LD_LIBRARY_PATH=lib:/usr/lib:$LD_LIBRARY_PATH

 

etc/init.d/rcS文件的内容为:
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin

runlevel=S
prevlevel=N

umask 022

export PATH runlevel prevlevel

mount -a

mkdir /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s

/bin/hostname -F /etc/sysconfig/HOSTNAME

ifconfig eth0 192.168.0.80
 

resolv.conf文件的内容为:
nameserver 202.96.128.166
 

etc/inetd.cof是inetd的配置文件,它的内容为:# It is generally considered safer to keep these off.
echo stream tcp nowait root internal
echo dgram udp wait root internal
daytime stream tcp nowait root internal
daytime dgram udp wait root internal
time stream tcp nowait root internal
time dgram udp wait root internal

# These are standard services.
ftp    stream tcp nowait root /usr/sbin/tcpd in.ftpd
telnet stream tcp nowait root /sbin/telnetd  /sbin/telnetd
 

etc/sysconfig/HOSTNAME文件的内容为你的英文名字。

etc/passwd、etc/group、etc/shadow文件的内容为空。

etc/mdev.conf是mdev设备文件系统的配置文件,可以参考:
busybox下mdev的使用以及mdev.conf的规则配置
mdev实现U盘和SD卡的自动挂载

OK,算是做好了~~

三)用户管理
在文件系统正常运行起来后,使用adduser命令:
# adduser root

会打印出如下消息:
passwd:unknown uid 0

这表示不能为该用户设置密码,此时你会发现passwd命令也无法使用。

解决的办法是,打开/etc/passwd文件,其内容为:
root:x:1000:1000:Linux User…:/home/root:/bin/sh

将用户ID和组ID均修改为0。

打开/etc/group文件,其内容为:
root:x:1000:

同样将组ID修改为0。

然后,passwd命令就可以正常使用了。

这时为root用户设置口令:
# passwd root

根据提示输入密码。