i386上的busybox

13 篇文章 0 订阅
环境:在64位机器上总莫名其妙问题,交叉编译也会有想不到的地方,
反正是虚拟机,找了个32为的centos7安装

---------------------

yum install glibc-static -y
yum install ncurses ncurses-devel gcc gcc-c++ emacs -y
yum install glibc glibc-devel glibc-static glibc-utils -y
yum install libgcc -y
yum install glib2-devel -y
yum install gcc* -y
export TOP=/root/jslinux
cd $TOP/busybox-1.23.2
#这步骤很重要,busybox不生成动态库
mkdir -pv ../obj/busybox-i386
make O=../obj/busybox-i386 defconfig
make O=../obj/busybox-i386 menuconfig
-> Busybox Settings
-> Build Options
[ ] Build BusyBox as a static binary (no shared libs)
Go to that location, select it, save, and exit.
-> Busybox Settings
-> Busybox Library Turning
-> Support for /etc/networks
-> vi-style line editing commands
-> [*] Give more precise messages when copy fails (cp, mv etc)
去掉Skip rootfs in mount table
-> Init Utilities
-> Support reading an inittab file
是否需要去掉
Enable writing to tty only by group, not by everybody

$ cd ../obj/busybox-i386
$ make -j16
$ make install

mkdir -p $TOP/initramfs/i386-busybox
$ cd $TOP/initramfs/i386-busybox
$ mkdir -pv {bin,sbin,etc,proc,sys,usr/{bin,sbin}}
$ cp -av $TOP/obj/busybox-i386/_install/* .

vim init

-------------
#!/bin/sh

mount -t proc none /proc
mount -t sysfs none /sys

echo -e "\n /init Boot took $(cut -d' ' -f1 /proc/uptime) seconds\n"
#mdev 是 busybox 自带的一个 udev ,它是用于系统启动和
#热插拔或是动态加载驱动程序的时候,而自动产生设别节点的,
#这句话如果不加上的话,这需要手动的 mknod 来挂载设备节点
/sbin/mdev -s
exec /bin/sh
--------------------

chmod +x init
[color=red]
find . -print0 | cpio --null -ov --format=newc | gzip -9 > $TOP/obj/initramfs-busybox-i386.cpio.gz
[/color]

qemu-system-i386 -kernel bzImage -initrd initramfs-busybox-i386.cpio.gz -nographic -append "console=ttyS0" -enable-kvm
qemu-system-i386 -kernel bzImage -initrd initramfs-busybox-i386.cpio.gz -vnc 0.0.0.0:1


-----------------------------
这个文件理论上是写到哪里都可以,append的时候指定一下
如果不写,则默认是/init
比如写到
/etc/init.d/rcS
等等,
这里我保存成/haha

-------------------
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
echo -e "\n Haoning Boot took $(cut -d' ' -f1 /proc/uptime) seconds\n"
/sbin/mdev -s
exec /bin/sh
-------------------------

如果生成img
[color=red]
find . | cpio -o --format=newc > $TOP/obj/rootfs.img
[/color]
这步骤有没有都行

gzip -c rootfs.img > rootfs.img.gz
#qemu-system-i386 -kernel bzImage -initrd rootfs.img.gz -append "root=/dev/ram rdinit=/etc/init.d/rcS noapic" -vnc 0.0.0.0:1
qemu-system-i386 -kernel bzImage -initrd rootfs.img -append "root=/dev/ram rdinit=/haha noapic" -vnc 0.0.0.0:1
#rdinit和init有区别
rdinit起作用,可以指定配置文件,init不行,默认找/init去了
qemu-system-i386 -kernel bzImage -initrd rootfs.img -append "root=/dev/ram rdinit=/haha noapic" -vnc 0.0.0.0:1
qemu-system-i386 -kernel bzImage -initrd rootfs.img -append "root=/dev/ram0 rw rdinit=/sbin/init notsc=1" -vnc 0.0.0.0:1

如果是
qemu-system-i386 -kernel bzImage -initrd rootfs.img -vnc 0.0.0.0:1
[color=red]
如果不用vnc 用命令行的方式,需要 -append "console=ttyS0" -nographic 配合使用
[/color]

qemu-system-i386 -kernel bzImage -initrd rootfs.img -append "console=ttyS0" -nographic

会自动去找/init
console=ttyS0 与nographic 配合使用,如果使用vnc,则去掉console=ttyS0 否则不显示

qemu-system-i386 -kernel bzImage -initrd rootfs.img -append "root=/dev/ram0 rw init=/sbin/init notsc=1" -vnc 0.0.0.0:1

比如这个
qemu-system-i386 -kernel bzImage -initrd rootfs.img -append "console=ttyS0 root=/dev/ram0 rw init=/sbin/init notsc=1" -vnc 0.0.0.0:1
显示Decompressing Linux ... Parsing ELF... No relocation needed... done.
Booting the kernel.
就不动了
console=ttyS0 root=/dev/ram0 rw init=/sbin/init notsc=1 是jslinux.js里的代码
jslinux会把这个console定向到浏览器
我们编译的rootfs.img
进入系统后df -h 什么也没有,可能是不能作为hda的原因
###########################################################
退出 QEMU 操作为:Ctrl + A ,然后按下 X 键。注意,它不会提醒你是否要退出,而是直接退出,所以操作时要小心。
############################################################
测试
qemu-system-i386 -kernel linux-x86-basic/arch/i386/boot/bzImage -initrd rootfs.img -append "console=ttyS0 root=/dev/ram0 rw rdinit=/jslinux notsc=1" -nographic
echo ':DOSCOM:E::com::/usr/bin/runcom:' > /proc/sys/fs/binfmt_misc/register


下面不好使
qemu-system-i386 -kernel bzImage -hda rootfs.img -append "console=ttyS0 root=/dev/hda ro init=/sbin/init notsc=1" -vnc 0.0.0.0:1
console=ttyS0 root=/dev/hda ro init=/sbin/init notsc=1
console=ttyS0 root=/dev/ram0 rw init=/sbin/init notsc=1
qemu-system-i386 -kernel bzImage -hda rootfs.img -append "console=ttyS0 root=/dev/hda ro init=/init notsc=1" -vnc 0.0.0.0:1


备注
内核的 .config文件
CONFIG_TUN=y
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值