ºìÁªLinuxÃÅ»§
Linux°ïÖú

ÓÃbusybox×öÒ»¸öÃÔÄãLinux

·¢²¼Ê±¼ä:2008-04-26 20:57:48À´Ô´:ºìÁª×÷Õß:Revenue
×÷Õߣºcutebunny

1.»ù´¡ÖªÊ¶
Ò»¸ö²Ù×÷ϵͳ¿ÉÒÔ¼òµ¥µÄ³éÏóΪ£¬Òýµ¼³ÌÐò+ÄÚºË+Îļþϵͳ¡£

vmlinuzÊÇLinux Äں˵ľµÏñÎļþ,¿ÉÒÔ±»Òýµ¼³ÌÐò¼ÓÔØ,´Ó¶øÆô¶¯Linuxϵͳ¡£

initrdµÄÈ«³ÆÊÇboot loader initialized RAM disk£¬ËüÊÇϵͳÆô¶¯Ê±ËùʹÓõĸùÎļþϵͳӳÏñÎļþ£¬Õâ¸öÎļþϵͳÖаüº¬¼¸¸öÇý¶¯Ä£¿é£¬ÓÃÀ´×°ÔØʵ¼ÊµÄ¸ùÎļþϵͳ£¬±ÈÈçÒ»¸öIDE»òSCSIÓ²Å̵ÄÇý¶¯Ä£¿é£¬ÄÚºË×°ÈëÕâ¸öÄ£¿éÖ®ºóÓÃËüÀ´Çý¶¯Ó²ÅÌ£¬¹Ò½ÓÓ²Å̵½ramdiskµÄij¸ö×ÓĿ¼£¬È»ºóÔÙÓÃÆäÖеÄpivot_rootÃüÁ½«Ó²ÅÌÎļþϵͳ±ä³É¸ùÎļþϵͳ£¬²¢¿ªÊ¼Ö´ÐÐinit½ø³Ì£¬´Ëʱinit ram disk±»umount£¬ÊÙÖÕÕýÇÞ¡£

Óɴ˿ɼû£¬ÎÒÃÇ¿ÉÒÔÓÃvmlinuz+initrd.img×öÒ»¸öÎļþϵͬ³¤×¤ÄÚ´æµÄÃÔÄãLinux¡£

ÏÖÔÚ½øÈëÕýÌâÁË£º

2.±àÒëÄÚºË
cd /usr/src/....----½øÈëÄÚºËÔ´´úÂëĿ¼£¬Ã»ÓеĻ°È¥¹Ù·½ÍøÕ¾£¬Ëæ±ãÏÂ
make menuconfig-----ÅäÖñàÒëÑ¡ÏîÇë×¢ÒâÒ»¶¨¼ÓÈëRAM disk support ºÍinitial RAM disk
(initrd) support µÄÖ§³Ö(ÔÚblock deviceÖÐ)¡£ÁíÍâ×îºÃ½«ext3Îļþϵͳ±àÈëÄںˣ¬²»Òª±à³ÉÄ£¿é¡£ÅäÖÃÍê±Ïºó±£´æΪ.config(ĬÈÏ)
make bzImage----±àÒë

ÔÚÐí¶àÄں˱àÒë²Î¿¼Öл¹ÓÐ
make modules
make modules_installÁ½²½
µ«ÎÒÃÇÕâÀïûÓмÓÈë¶ÔmodulesµÄÖ§³Ö£¬ËùÒÔ²»ÐèÒª¡£Éú³ÉµÄbzImageÎļþÔÚusr/src/linux/arch/.../bootÖУ¬Ê¡ÂԵĸù¾ÝÄãµÄ»úÆ÷¼Ü¹¹¾ö¶¨£¬make¹ý³ÌÖлáÓÐÌáʾ£¬±ÈÈçÎÒµÄÊÇx86_64. ×¢ÒâÕâ¸öÎļþ·Ç³£ÖØÒª£¬Æäʵ¾ÍÊÇÎÒÃÇ×îÖÕµÄvmlinuz.

3.busybox
busyboxÊÇÒ»¸ö¼¯³ÉÁËÒ»°Ù¶à¸ö×î³£ÓÃlinuxÃüÁîºÍ¹¤¾ßµÄÈí¼þ,ËüÉõÖÁ»¹¼¯³ÉÁËÒ»¸öhttp·þÎñÆ÷ºÍÒ»¸ötelnet·þÎñÆ÷,¶øËùÓÐÕâÒ»Çй¦ÄÜÈ´Ö»ÓÐÇøÇø1M×óÓҵĴóС.ÎÒÃÇƽʱÓõÄÄÇЩlinuxÃüÁî¾ÍºÃ±ÈÊÇ·ÖÁ¦Ê½µÄµç×ÓÔª¼þ,¶øbusybox¾ÍºÃ±ÈÊÇÒ»¸ö¼¯³Éµç·,°Ñ³£ÓõŤ¾ßºÍÃüÁ³ÉѹËõÔÚÒ»¸ö¿ÉÖ´ÐÐÎļþÀï,¹¦ÄÜ»ù±¾²»±ä,¶ø´óСȴСºÜ¶à±¶,ÔÚǶÈëʽlinuxÓ¦ÓÃÖÐ,busyboxÓзdz£¹ãµÄÓ¦ÓÃ,ÁíÍâ,´ó¶àÊýlinux·¢ÐаæµÄ°²×°³ÌÐòÖж¼ÓÐbusyboxµÄÉíÓ°,°²×°linuxµÄʱºò°¸ctrl+alt+F2¾ÍÄܵõ½Ò»¸ö¿ØÖÆ̨,¶øÕâ¸ö¿ØÖÆ̨ÖеÄËùÓÐÃüÁÊÇÖ¸ÏòbusyboxµÄÁ´½Ó.ÔÚÎÒÃǵÄÃÔÄãLinuxÖУ¬ÐèÒªµÄÒ²ÕýÊÇbusyboxµÄÃüÁîºÍ¹¤¾ß¡£

ÏÂÔØ http://busybox.net/downloads/
ʹÓùý³ÌÖÐÐí¶à¸ß°æ±¾¶¼³öÏÖ±àÒë´íÎó£¬ËùÒÔÓÃÁËÒ»¸ö×îԭʼµÄ°æ±¾busybox-1.00
#cp busybox-1.00.tar.gz /tmp/bunny
#cd /tmp/bunny
#tar xvfz busybox-1.00.tar.gz
#cd busybox-1.00
#make menuconfig ----±àÒëÅäÖÃ

ÏÂÃæÊÇÐèÒª±àÒë½øbusyboxµÄ¹¦ÄÜÑ¡Ïî,ÆäËûµÄ¿ÉÒÔ¸ù¾ÝÐèÒª×ÔÑ¡.
General ConfigurationÓ¦¸ÃÑ¡µÄÑ¡Ïî
Show verbose applet usage messages
Runtime SUID/SGID configuration via /etc/busybox.conf
Build Options
Build BusyBox as a static binary (no shared libs)

Õâ¸öÑ¡ÏîÊÇÒ»¶¨ÒªÑ¡ÔñµÄ,ÕâÑù²ÅÄÜ°Ñbusybox±àÒë³É¾²Ì¬Á´½ÓµÄ¿ÉÖ´ÐÐÎļþ,ÔËÐÐʱ²Å¶ÀÁ¢ÓÚÆäËûº¯Êý¿â.·ñÔò±ØÐèÒªÆäËû¿âÎļþ²ÅÄÜÔËÐÐ,ÔÚµ¥Ò»¸ölinuxÄں˲»ÄÜʹËûÕý³£¹¤×÷.

Installation Options
Don't use /usr

Õâ¸öÑ¡ÏîÒ²Ò»¶¨ÒªÑ¡,·ñÔòmake install ºóbusybox½«°²×°ÔÚԭϵͳµÄ/usrÏÂ,Õ⽫¸²¸ÇµôϵͳԭÓеÄÃüÁî.Ñ¡ÔñÕâ¸öÑ¡Ïîºó,make installºó»áÔÚbusyboxĿ¼ÏÂÉú³ÉÒ»¸ö½Ð_installµÄĿ¼,ÀïÃæÓÐbusyboxºÍÖ¸ÏòËüµÄÁ´½Ó.

ÆäËûÑ¡ÏÊÇһЩlinux»ù±¾ÃüÁîÑ¡Ïî,×Ô¼ºÐèÒªÄÄЩÃüÁî¾Í±àÒë½øÈ¥,Ò»°ãÓÃĬÈϵľͿÉÒÔÁË.
ÅäÖúúóÍ˳ö²¢±£´æ.config.
make
make install
±àÒëºÃºóÔÚbusyboxĿ¼ÏÂÉú³É×ÓĿ¼_install,ÀïÃæµÄÄÚÈÝ:
bin
linuxrc -> bin/busybox
sbin
ÆäÖпÉÖ´ÐÐÎļþbusyboxÔÚbinĿ¼ÏÂ,ÆäËûµÄ¶¼ÊÇÖ¸ÏòËûµÄ·ûºÅÁ´½Ó.

4.ÖÆ×÷×Ô¼ºµÄroot fs
1)Ŀ¼½á¹¹
mkdir /tmp/myOS/rootfs
cd /tmp/myOS/rootfs
mkdir etc usr var tmp proc home root dev
ÆäÖÐetc,procºÍdevÊÇÒ»¶¨Òª½¨µÄ,binºÍsbin²»Óý¨,ÒòΪbusyboxÖÐÒѾ­ÓÐÁË.
ÆäËûµÄ¿ÉÒÔÏóÕ÷ÐԵĽ¨¼¸¸ö¾Í¿ÉÒÔÁË.
¿½±´busybox
#cp -R /tmp/bunny/busybox-1.00/_install/* /tmp/myOS/rootfs/

2)É豸Îļþ
ÎÒÊÇÖ±½Ó´ÓFCϵͳ/devĿ¼ÀïcpµÄ,·½·¨ÈçÏÂ:
#cp -R /dev/console /tmp/myOS/rootfs/dev/
#cp -R /dev/null /tmp/myOS/rootfs/dev/
#cp -R /dev/zero /tmp/myOS/rootfs/dev/
ÄãÈÏΪÐèÒªµÄ¶¼cp¹ýÀ´
ÓеIJο¼ÎÄÏ×˵fd0,hda,ram,ram1,tty1,loop1,fb0,fb,ttyµÈÊDZر¸µÄ£¬µ«ÊǺÃÏñÓÐЩÎļþ²¢Ã»ÓÐ

3)½¨Á¢etcĿ¼ÏµÄÅäÖÃÎļþ
ÎÒÊÇÖ±½Ó¿½±´busybox×Ô´øµÄÀý×Ó
cp -R tmp/bunny/busybox-1.00/examples/bootfloppy/etc/* /tmp/myOS/rootfs/etc

4)ÖÆ×÷initrd.imgÓ³ÏóÎļþ
cd /tmp/myOS/
dd if=/dev/zero of=/tmp/disk bs=1M count=32 ------³õʼ»¯32MÄÚ´æ¿Õ¼ä
mkfs.ext3 -m0 /tmp/disk ------¸ñʽ»¯Îªext3
mkdir /mnt/ram
mount -o loop /tmp/disk /mnt/ram ------¹ÒÔص½/mnt/ram
cp -R rootfs/* /mnt/ram ------°ÑrootfsдÈëÄÚ´æ
umount /mnt/ram
dd if=/tmp/disk of=/tmp/myOS/initrd.img ------°ÑÄÚ´æÖеÄÄÚÈÝÒÔÓ³Ïó·½Ê½È¡³ö
ok,Õâ¸öinitrd.img¾ÍÊÇÎÒÃǵÄrootfs
ÓеÄÎÄÏ×ʹÓÃram0£¬Ò²¾ÍÊǽ«ÉÏÊö¹ý³ÌµÄ/tmp/disk¸ÄΪ/dev/ram0£¬ËäÈ»ÖÆ×÷¹ý³ÌûÓÐÎÊÌ⣬µ«ÊÇËü´æÔÚ´óСÏÞÖÆ

5.ÕûºÏ£¬Æô¶¯
1)kernel
cp /usr/src/linux/arch/x86_64/bzImage /boot/vmlinuz
2)rootfs Ò»°ãÃüÃûΪinitrd.img
cp /tmp/myOS/initrd.img /boot
3)ÓÐÁËÉÏÊöÁ½¸öÎļþ£¬ÒѾ­¿ÉÒÔͨ¹ýÍøÂçdhcp, tftp·þÎñÆ÷Æô¶¯£¬tftp·þÎñÆ÷ÖÐÌí¼ÓÆô¶¯½Å±¾ÈçÏÂ
DEFAULT linux
PROMPT 0
LABEL linux
KERNEL vmlinuz
append initrd=initrd.img devfs=nomount ramdisk_size=52000

ÎÊÌ⣺ÀíÂÛÉÏÕâ¸öСLinuxÒ²Ó¦¸Ã¿ÉÒÔ´ÓgrubÒýµ¼¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ