{"id":129,"date":"2013-07-11T20:56:05","date_gmt":"2013-07-11T12:56:05","guid":{"rendered":"http:\/\/www.datarelab.com\/blog\/?p=129"},"modified":"2013-07-11T20:56:05","modified_gmt":"2013-07-11T12:56:05","slug":"%e4%bd%bf%e7%94%a8busybox%e5%81%9a%e4%b8%80%e4%b8%aa%e5%b0%8f%e5%b7%a7%e7%9a%84linux%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%bb%9f","status":"publish","type":"post","link":"https:\/\/www.datarelab.com\/blog\/Technical_literature\/129.html","title":{"rendered":"\u4f7f\u7528BusyBox\u505a\u4e00\u4e2a\u5c0f\u5de7\u7684Linux\u64cd\u4f5c\u7cfb\u7edf"},"content":{"rendered":"<p>1.\u57fa\u7840\u77e5\u8bc6<br \/>\n\u4e00\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u53ef\u4ee5\u7b80\u5355\u7684\u62bd\u8c61\u4e3a\uff0c\u5f15\u5bfc\u7a0b\u5e8f \u5185\u6838 \u6587\u4ef6\u7cfb\u7edf\u3002<br \/>\n&nbsp;<br \/>\nvmlinuz\u662fLinux \u5185\u6838\u7684\u955c\u50cf\u6587\u4ef6,\u53ef\u4ee5\u88ab\u5f15\u5bfc\u7a0b\u5e8f\u52a0\u8f7d,\u4ece\u800c\u542f\u52a8Linux\u7cfb\u7edf\u3002<br \/>\n&nbsp;<br \/>\ninitrd\u7684\u5168\u79f0\u662fboot loader initialized RAM disk\uff0c\u5b83\u662f\u7cfb\u7edf\u542f\u52a8\u65f6\u6240\u4f7f\u7528\u7684\u6839\u6587\u4ef6\u7cfb\u7edf\u6620\u50cf\u6587\u4ef6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u7cfb\u7edf\u4e2d\u5305\u542b\u51e0\u4e2a\u9a71\u52a8\u6a21\u5757\uff0c\u7528\u6765\u88c5\u8f7d\u5b9e\u9645\u7684\u6839\u6587\u4ef6\u7cfb\u7edf\uff0c\u6bd4\u5982\u4e00\u4e2aIDE\u6216SCSI\u786c\u76d8\u7684\u9a71\u52a8\u6a21\u5757\uff0c\u5185\u6838\u88c5\u5165\u8fd9\u4e2a\u6a21\u5757\u4e4b\u540e\u7528\u5b83\u6765\u9a71\u52a8\u786c\u76d8\uff0c\u6302\u63a5\u786c\u76d8\u5230ramdisk\u7684\u67d0\u4e2a\u5b50\u76ee\u5f55\uff0c\u7136\u540e\u518d\u7528\u5176\u4e2d\u7684pivot_root\u547d\u4ee4\uff0c\u5c06\u786c\u76d8\u6587\u4ef6\u7cfb\u7edf\u53d8\u6210\u6839\u6587\u4ef6\u7cfb\u7edf\uff0c\u5e76\u5f00\u59cb\u6267\u884cinit\u8fdb\u7a0b\uff0c\u6b64\u65f6init ram disk\u88abumount\uff0c\u5bff\u7ec8\u6b63\u5bdd\u3002<br \/>\n&nbsp;<br \/>\n\u7531\u6b64\u53ef\u89c1\uff0c\u6211\u4eec\u53ef\u4ee5\u7528vmlinuz initrd.img\u505a\u4e00\u4e2a\u6587\u4ef6\u7cfb\u540c\u957f\u9a7b\u5185\u5b58\u7684\u8ff7\u4f60Linux\u3002<br \/>\n&nbsp;<br \/>\n\u73b0\u5728\u8fdb\u5165\u6b63\u9898\u4e86\uff1a<br \/>\n&nbsp;<br \/>\n2.\u7f16\u8bd1\u5185\u6838<br \/>\ncd \/usr\/src\/....----\u8fdb\u5165\u5185\u6838\u6e90\u4ee3\u7801\u76ee\u5f55\uff0c\u6ca1\u6709\u7684\u8bdd\u53bb\u5b98\u65b9\u7f51\u7ad9\uff0c\u968f\u4fbf\u4e0b<br \/>\nmake menuconfig-----\u914d\u7f6e\u7f16\u8bd1\u9009\u9879\u8bf7\u6ce8\u610f\u4e00\u5b9a\u52a0\u5165RAM disk support \u548cinitial RAM disk<br \/>\n(initrd) support \u7684\u652f\u6301(\u5728block device\u4e2d)\u3002\u53e6\u5916\u6700\u597d\u5c06ext3\u6587\u4ef6\u7cfb\u7edf\u7f16\u5165\u5185\u6838\uff0c\u4e0d\u8981\u7f16\u6210\u6a21\u5757\u3002\u914d\u7f6e\u5b8c\u6bd5\u540e\u4fdd\u5b58\u4e3a.config(\u9ed8\u8ba4)<br \/>\nmake bzImage----\u7f16\u8bd1<br \/>\n&nbsp;<br \/>\n\u5728\u8bb8\u591a\u5185\u6838\u7f16\u8bd1\u53c2\u8003\u4e2d\u8fd8\u6709<br \/>\nmake modules<br \/>\nmake modules_install\u4e24\u6b65<br \/>\n\u4f46\u6211\u4eec\u8fd9\u91cc\u6ca1\u6709\u52a0\u5165\u5bf9modules\u7684\u652f\u6301\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u3002\u751f\u6210\u7684bzImage\u6587\u4ef6\u5728usr\/src\/linux\/arch\/...\/boot\u4e2d\uff0c\u7701\u7565\u7684\u6839\u636e\u4f60\u7684\u673a\u5668\u67b6\u6784\u51b3\u5b9a\uff0cmake\u8fc7\u7a0b\u4e2d\u4f1a\u6709\u63d0\u793a\uff0c\u6bd4\u5982\u6211\u7684\u662fx86_64. \u6ce8\u610f\u8fd9\u4e2a\u6587\u4ef6\u975e\u5e38\u91cd\u8981\uff0c\u5176\u5b9e\u5c31\u662f\u6211\u4eec\u6700\u7ec8\u7684vmlinuz.<br \/>\n&nbsp;<br \/>\n3.busybox<br \/>\nbusybox\u662f\u4e00\u4e2a\u96c6\u6210\u4e86\u4e00\u767e\u591a\u4e2a\u6700\u5e38\u7528linux\u547d\u4ee4\u548c\u5de5\u5177\u7684\u8f6f\u4ef6,\u5b83\u751a\u81f3\u8fd8\u96c6\u6210\u4e86\u4e00\u4e2ahttp\u670d\u52a1\u5668\u548c\u4e00\u4e2atelnet\u670d\u52a1\u5668,\u800c\u6240\u6709\u8fd9\u4e00\u5207\u529f\u80fd\u5374\u53ea\u6709\u533a\u533a1M\u5de6\u53f3\u7684\u5927\u5c0f.\u6211\u4eec\u5e73\u65f6\u7528\u7684\u90a3\u4e9blinux\u547d\u4ee4\u5c31\u597d\u6bd4\u662f\u5206\u529b\u5f0f\u7684\u7535\u5b50\u5143\u4ef6,\u800cbusybox\u5c31\u597d\u6bd4\u662f\u4e00\u4e2a\u96c6\u6210\u7535\u8def,\u628a\u5e38\u7528\u7684\u5de5\u5177\u548c\u547d\u4ee4\u96c6\u6210\u538b\u7f29\u5728\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u91cc,\u529f\u80fd\u57fa\u672c\u4e0d\u53d8,\u800c\u5927\u5c0f\u5374\u5c0f\u5f88\u591a\u500d,\u5728\u5d4c\u5165\u5f0flinux\u5e94\u7528\u4e2d,busybox\u6709\u975e\u5e38\u5e7f\u7684\u5e94\u7528,\u53e6\u5916,\u5927\u591a\u6570linux\u53d1\u884c\u7248\u7684\u5b89\u88c5\u7a0b\u5e8f\u4e2d\u90fd\u6709busybox\u7684\u8eab\u5f71,\u5b89\u88c5linux\u7684\u65f6\u5019\u6848ctrl alt F2\u5c31\u80fd\u5f97\u5230\u4e00\u4e2a\u63a7\u5236\u53f0,\u800c\u8fd9\u4e2a\u63a7\u5236\u53f0\u4e2d\u7684\u6240\u6709\u547d\u4ee4\u90fd\u662f\u6307\u5411busybox\u7684\u94fe\u63a5.\u5728\u6211\u4eec\u7684\u8ff7\u4f60Linux\u4e2d\uff0c\u9700\u8981\u7684\u4e5f\u6b63\u662fbusybox\u7684\u547d\u4ee4\u548c\u5de5\u5177\u3002<br \/>\n&nbsp;<br \/>\n\u4e0b\u8f7d http:\/\/busybox.net\/downloads\/<br \/>\n\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u8bb8\u591a\u9ad8\u7248\u672c\u90fd\u51fa\u73b0\u7f16\u8bd1\u9519\u8bef\uff0c\u6240\u4ee5\u7528\u4e86\u4e00\u4e2a\u6700\u539f\u59cb\u7684\u7248\u672cbusybox-1.00<br \/>\n#cp busybox-1.00.tar.gz \/tmp\/bunny<br \/>\n#cd \/tmp\/bunny<br \/>\n#tar xvfz busybox-1.00.tar.gz<br \/>\n#cd busybox-1.00<br \/>\n#make menuconfig ----\u7f16\u8bd1\u914d\u7f6e<br \/>\n&nbsp;<br \/>\n\u4e0b\u9762\u662f\u9700\u8981\u7f16\u8bd1\u8fdbbusybox\u7684\u529f\u80fd\u9009\u9879,\u5176\u4ed6\u7684\u53ef\u4ee5\u6839\u636e\u9700\u8981\u81ea\u9009.<br \/>\nGeneral Configuration\u5e94\u8be5\u9009\u7684\u9009\u9879<br \/>\nShow verbose applet usage messages<br \/>\nRuntime SUID\/SGID configuration via \/etc\/busybox.conf<br \/>\nBuild Options<br \/>\nBuild BusyBox as a static binary (no shared libs)<br \/>\n&nbsp;<br \/>\n\u8fd9\u4e2a\u9009\u9879\u662f\u4e00\u5b9a\u8981\u9009\u62e9\u7684,\u8fd9\u6837\u624d\u80fd\u628abusybox\u7f16\u8bd1\u6210\u9759\u6001\u94fe\u63a5\u7684\u53ef\u6267\u884c\u6587\u4ef6,\u8fd0\u884c\u65f6\u624d\u72ec\u7acb\u4e8e\u5176\u4ed6\u51fd\u6570\u5e93.\u5426\u5219\u5fc5\u9700\u8981\u5176\u4ed6\u5e93\u6587\u4ef6\u624d\u80fd\u8fd0\u884c,\u5728\u5355\u4e00\u4e2alinux\u5185\u6838\u4e0d\u80fd\u4f7f\u4ed6\u6b63\u5e38\u5de5\u4f5c.<br \/>\n&nbsp;<br \/>\nInstallation Options<br \/>\nDon't use \/usr<br \/>\n&nbsp;<br \/>\n\u8fd9\u4e2a\u9009\u9879\u4e5f\u4e00\u5b9a\u8981\u9009,\u5426\u5219make install \u540ebusybox\u5c06\u5b89\u88c5\u5728\u539f\u7cfb\u7edf\u7684\/usr\u4e0b,\u8fd9\u5c06\u8986\u76d6\u6389\u7cfb\u7edf\u539f\u6709\u7684\u547d\u4ee4.\u9009\u62e9\u8fd9\u4e2a\u9009\u9879\u540e,make install\u540e\u4f1a\u5728busybox\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a\u53eb_install\u7684\u76ee\u5f55,\u91cc\u9762\u6709busybox\u548c\u6307\u5411\u5b83\u7684\u94fe\u63a5.<br \/>\n&nbsp;<br \/>\n\u5176\u4ed6\u9009\u9879\u90fd\u662f\u4e00\u4e9blinux\u57fa\u672c\u547d\u4ee4\u9009\u9879,\u81ea\u5df1\u9700\u8981\u54ea\u4e9b\u547d\u4ee4\u5c31\u7f16\u8bd1\u8fdb\u53bb,\u4e00\u822c\u7528\u9ed8\u8ba4\u7684\u5c31\u53ef\u4ee5\u4e86.<br \/>\n\u914d\u7f6e\u597d\u540e\u9000\u51fa\u5e76\u4fdd\u5b58.config.<br \/>\nmake<br \/>\nmake install<br \/>\n\u7f16\u8bd1\u597d\u540e\u5728busybox\u76ee\u5f55\u4e0b\u751f\u6210\u5b50\u76ee\u5f55_install,\u91cc\u9762\u7684\u5185\u5bb9:<br \/>\nbin<br \/>\nlinuxrc -&gt; bin\/busybox<br \/>\nsbin<br \/>\n\u5176\u4e2d\u53ef\u6267\u884c\u6587\u4ef6busybox\u5728bin\u76ee\u5f55\u4e0b,\u5176\u4ed6\u7684\u90fd\u662f\u6307\u5411\u4ed6\u7684\u7b26\u53f7\u94fe\u63a5.<br \/>\n&nbsp;<br \/>\n4.\u5236\u4f5c\u81ea\u5df1\u7684root fs<br \/>\n1)\u76ee\u5f55\u7ed3\u6784<br \/>\nmkdir \/tmp\/myOS\/rootfs<br \/>\ncd \/tmp\/myOS\/rootfs<br \/>\nmkdir etc usr var tmp proc home root dev<br \/>\n\u5176\u4e2detc,proc\u548cdev\u662f\u4e00\u5b9a\u8981\u5efa\u7684,bin\u548csbin\u4e0d\u7528\u5efa,\u56e0\u4e3abusybox\u4e2d\u5df2\u7ecf\u6709\u4e86.<br \/>\n\u5176\u4ed6\u7684\u53ef\u4ee5\u8c61\u5f81\u6027\u7684\u5efa\u51e0\u4e2a\u5c31\u53ef\u4ee5\u4e86.<br \/>\n\u62f7\u8d1dbusybox<br \/>\n#cp -R \/tmp\/bunny\/busybox-1.00\/_install\/* \/tmp\/myOS\/rootfs\/<br \/>\n&nbsp;<br \/>\n2)\u8bbe\u5907\u6587\u4ef6<br \/>\n\u6211\u662f\u76f4\u63a5\u4eceFC\u7cfb\u7edf\/dev\u76ee\u5f55\u91cccp\u7684,\u65b9\u6cd5\u5982\u4e0b:<br \/>\n#cp -R \/dev\/console \/tmp\/myOS\/rootfs\/dev\/<br \/>\n#cp -R \/dev\/null \/tmp\/myOS\/rootfs\/dev\/<br \/>\n#cp -R \/dev\/zero \/tmp\/myOS\/rootfs\/dev\/<br \/>\n\u4f60\u8ba4\u4e3a\u9700\u8981\u7684\u90fdcp\u8fc7\u6765<br \/>\n\u6709\u7684\u53c2\u8003\u6587\u732e\u8bf4fd0,hda,ram,ram1,tty1,loop1,fb0,fb,tty\u7b49\u662f\u5fc5\u5907\u7684\uff0c\u4f46\u662f\u597d\u50cf\u6709\u4e9b\u6587\u4ef6\u5e76\u6ca1\u6709<br \/>\n&nbsp;<br \/>\n3)\u5efa\u7acbetc\u76ee\u5f55\u4e0b\u7684\u914d\u7f6e\u6587\u4ef6<br \/>\n\u6211\u662f\u76f4\u63a5\u62f7\u8d1dbusybox\u81ea\u5e26\u7684\u4f8b\u5b50<br \/>\ncp -R tmp\/bunny\/busybox-1.00\/examples\/bootfloppy\/etc\/* \/tmp\/myOS\/rootfs\/etc<br \/>\n&nbsp;<br \/>\n4)\u5236\u4f5cinitrd.img\u6620\u8c61\u6587\u4ef6<br \/>\ncd \/tmp\/myOS\/<br \/>\ndd if=\/dev\/zero of=\/tmp\/disk bs=1M count=32 ------\u521d\u59cb\u531632M\u5185\u5b58\u7a7a\u95f4<br \/>\nmkfs.ext3 -m0 \/tmp\/disk ------\u683c\u5f0f\u5316\u4e3aext3<br \/>\nmkdir \/mnt\/ram<br \/>\nmount -o loop \/tmp\/disk \/mnt\/ram ------\u6302\u8f7d\u5230\/mnt\/ram<br \/>\ncp -R rootfs\/* \/mnt\/ram ------\u628arootfs\u5199\u5165\u5185\u5b58<br \/>\numount \/mnt\/ram<br \/>\ndd if=\/tmp\/disk of=\/tmp\/myOS\/initrd.img ------\u628a\u5185\u5b58\u4e2d\u7684\u5185\u5bb9\u4ee5\u6620\u8c61\u65b9\u5f0f\u53d6\u51fa<br \/>\nok,\u8fd9\u4e2ainitrd.img\u5c31\u662f\u6211\u4eec\u7684rootfs<br \/>\n\u6709\u7684\u6587\u732e\u4f7f\u7528ram0\uff0c\u4e5f\u5c31\u662f\u5c06\u4e0a\u8ff0\u8fc7\u7a0b\u7684\/tmp\/disk\u6539\u4e3a\/dev\/ram0\uff0c\u867d\u7136\u5236\u4f5c\u8fc7\u7a0b\u6ca1\u6709\u95ee\u9898\uff0c\u4f46\u662f\u5b83\u5b58\u5728\u5927\u5c0f\u9650\u5236<br \/>\n&nbsp;<br \/>\n5.\u6574\u5408\uff0c\u542f\u52a8<br \/>\n1)kernel<br \/>\ncp \/usr\/src\/linux\/arch\/x86_64\/bzImage \/boot\/vmlinuz<br \/>\n2)rootfs \u4e00\u822c\u547d\u540d\u4e3ainitrd.img<br \/>\ncp \/tmp\/myOS\/initrd.img \/boot<br \/>\n3)\u6709\u4e86\u4e0a\u8ff0\u4e24\u4e2a\u6587\u4ef6\uff0c\u5df2\u7ecf\u53ef\u4ee5\u901a\u8fc7\u7f51\u7edcdhcp, tftp\u670d\u52a1\u5668\u542f\u52a8\uff0ctftp\u670d\u52a1\u5668\u4e2d\u6dfb\u52a0\u542f\u52a8\u811a\u672c\u5982\u4e0b<br \/>\nDEFAULT linux<br \/>\nPROMPT 0<br \/>\nLABEL linux<br \/>\nKERNEL vmlinuz<br \/>\nappend initrd=initrd.img devfs=nomount ramdisk_size=52000<br \/>\n&nbsp;<\/p>\n<p>\n\t\u95ee\u9898\uff1a\u7406\u8bba\u4e0a\u8fd9\u4e2a\u5c0fLinux\u4e5f\u5e94\u8be5\u53ef\u4ee5\u4ecegrub\u5f15\u5bfc\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u57fa\u7840\u77e5\u8bc6 \u4e00\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u53ef\u4ee5\u7b80\u5355\u7684\u62bd\u8c61\u4e3a\uff0c\u5f15\u5bfc\u7a0b\u5e8f \u5185\u6838 \u6587\u4ef6\u7cfb\u7edf\u3002 &nbsp; vmlinuz\u662fLinu [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[151,14,37],"class_list":["post-129","post","type-post","status-publish","format-standard","hentry","category-Technical_literature","tag-busybox","tag-linux","tag-37"],"views":1721,"_links":{"self":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/comments?post=129"}],"version-history":[{"count":0,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/129\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/media?parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/categories?post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/tags?post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}