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


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.第七次测试启动


wKioL1hN85uhWJlaAAACQj2_F10073.png-wh_50



wKioL1hN85ygrJAfAAAhQu-Ql4M959.png-wh_50


//启动成功,且绝大多数的命令都可以使用


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章