i386上的busybox

环境:在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

find . -print0  | cpio --null -ov --format=newc  | gzip -9 > $TOP/obj/initramfs-busybox-i386.cpio.gz

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

find . | cpio -o --format=newc > $TOP/obj/rootfs.img

这步骤有没有都行
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

如果不用vnc 用命令行的方式,需要 -append "console=ttyS0" -nographic  配合使用

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
         

猜你喜欢

转载自haoningabc.iteye.com/blog/2294172
今日推荐