您的位置:首页 > 运维架构 > Linux

从无到有构建一个Mini Linux(4)

2016-12-12 08:48 281 查看
16.编译busybox
17.提供inittab文件
18.提供初始化脚本
19.第七次测试启动

16.编译busybox

BusyBox简介
BusyBox 是一个集成了一百多个最常用linux命令和工具的软件。
BusyBox 包含了一些简单的工具,例如ls、cat和echo等等,还包含了一些更大、更复杂的工具,
如grep、find、mount以及telnet.有些人将 BusyBox 称为 Linux 工具里的瑞士军刀.
简单的说BusyBox就好像是个大工具箱,它集成压缩了 Linux 的许多工具和命令,
也包含了 Android 系统的自带的shell.  --- 来源 百度百科


[root@centos6 ~]# tar xf busybox-1.22.1.tar.bz2
[root@centos6 ~]# cd busybox-1.22.1
[root@centos6 busybox-1.22.1]# less INSTALL
[root@centos6 busybox-1.22.1]# make menuconfig
//静态方式编译

Busybox Settings  --->
Build Options  --->
[*] Build BusyBox as a static binary (no shared libs)
Installation Options ("make install" behavior)  --->
(./_install) BusyBox installation prefix

[root@centos6 busybox-1.22.1]# make && make install


//删除/mnt/sysroot下的目录,重新开始从头测试
[root@centos6 busybox-1.22.1]# rm -rf /mnt/sysroot/*


[root@centos6 busybox-1.22.1]# ls _install/
bin  linuxrc  sbin  usr  //编译成功后生成的文件
[root@centos6 busybox-1.22.1]# cp -a _install/* /mnt/sysroot/
[root@centos6 busybox-1.22.1]# ls /mnt/sysroot/
bin  linuxrc  sbin  usr


简单测试
[root@centos6 ~]# chroot /mnt/sysroot/
chroot: failed to run command '/bin/bash': No such file or directory
[root@centos6 ~]# chroot /mnt/sysroot/ /bin/ash
/ #   //绝大部分命令执行成功


//创建相应的目录
[root@centos6 sysroot]# mkdir -pv etc lib lib64 proc sys dev root home boot mnt media tmp var


17.提供inittab文件

//busybox提供/sbin/init文件,我们手动编写init的配置文件/etc/inittab文件即可(参照centos 5系列)
[root@centos6 sysroot]# vim etc/inittab  //注意是相对路径
::sysinit:/etc/rc.d/rc.sysinit
console::respawn:-/bin/ash
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r


18.提供初始化脚本
[root@centos6 sysroot]# mkdir etc/rc.d/
[root@centos6 sysroot]# vim etc/rc.d/rc.sysinit
#!/bin/ash
#
echo -e "\tWelcome to Sxj \033[32mMini\033[0m Linux"
mount  -t proc proc /proc
mount  -t sysfs sysfs /sys
mount -o remount,rw /dev/sda2 /

//加执行权限
[root@centos6 sysroot]# chmod +x etc/rc.d/rc.sysinit


19.第七次测试启动









//启动成功,且绝大多数的命令都可以使用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux 构建 从零