{"id":68,"date":"2024-03-16T21:30:00","date_gmt":"2024-03-16T13:30:00","guid":{"rendered":"http:\/\/blog.tntinminecraft.tech\/?p=68"},"modified":"2024-04-16T19:15:27","modified_gmt":"2024-04-16T11:15:27","slug":"%e7%bc%96%e8%af%91linux%e5%b9%b6%e5%9c%a8qemu%e8%99%9a%e6%8b%9f%e6%9c%ba%e4%b8%ad%e8%bf%90%e8%a1%8c","status":"publish","type":"post","link":"http:\/\/blog.tntinminecraft.tech\/index.php\/2024\/03\/16\/%e7%bc%96%e8%af%91linux%e5%b9%b6%e5%9c%a8qemu%e8%99%9a%e6%8b%9f%e6%9c%ba%e4%b8%ad%e8%bf%90%e8%a1%8c\/","title":{"rendered":"\u7f16\u8bd1Linux\u5e76\u5728QEMU\u865a\u62df\u673a\u4e2d\u8fd0\u884c"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">0x00 \u5b89\u88c5\u6240\u9700\u8f6f\u4ef6\u5305<\/h2>\n\n\n\n<p>\u9996\u5148\u5b89\u88c5\u6240\u9700\u8f6f\u4ef6\u5305\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install gcc make fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison qemu qemu-system qemu-kvm<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u4f60\u7684\u7cfb\u7edf\u4e0d\u662fUbuntu\/Debian\uff0c\u8bf7\u7528\u5bf9\u5e94\u7684\u5305\u7ba1\u7406\u5668\u5b89\u88c5\u8f6f\u4ef6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">0x10 \u4e0b\u8f7dLinux\u5185\u6838\u6e90\u7801<\/h2>\n\n\n\n<p>\u9996\u5148\u5728<a href=\"https:\/\/kernel.org\/\">kernel.org<\/a>\u4e2d\u4e0b\u8f7d\u6e90\u7801\u538b\u7f29\u5305\uff0c\u672c\u6559\u7a0b\u4e2d\u4f7f\u7528Linux6.8\uff0c\u5efa\u8bae\u5efa\u7acb\u4e00\u4e2a\u6587\u4ef6\u5939\u6765\u5b58\u653e\u6e90\u7801\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir build\ncd build\nwget https:\/\/cdn.kernel.org\/pub\/linux\/kernel\/v6.x\/linux-6.8.tar.xz\ntar xvf linux-6.8.tar.xz\ncd linux-6.8<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">0x20 \u914d\u7f6eLinux\u7f16\u8bd1\u9009\u9879<\/h2>\n\n\n\n<p>Linux\u6709\u8bb8\u591a\u7684\u7f16\u8bd1\u9009\u9879\uff0c\u5f53\u7136\u5bf9\u4e8e\u65b0\u624b\uff0c\u4f7f\u7528\u9ed8\u8ba4\u914d\u7f6e\u65e2\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>make defconfig<\/code><\/pre>\n\n\n\n<p>\u5f53\u663e\u793a<code>configuration written to .config<\/code>\u540e\uff0c\u8bf4\u660e\u521b\u5efa\u914d\u7f6e\u6210\u529f\u3002<\/p>\n\n\n\n<div class=\"wp-block-argon-alert alert\" style=\"background-color:#7889e8\"><span class=\"alert-inner--icon\"><i class=\"fa fa-info-circle\"><\/i><\/span><span class=\"alert-inner--text\">\u5982\u679c\u4f60\u60f3\u5f00\u5173Linux\u5185\u6838\u7684\u529f\u80fd\u6216\u8005\u4ea4\u53c9\u7f16\u8bd1\uff0c\u8bf7\u4f7f\u7528&#8221;make menuconfig&#8221;\u914d\u7f6e\u5185\u6838\u529f\u80fd\u3002<\/span><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">0x30 \u5f00\u59cb\u7f16\u8bd1Linux<\/h2>\n\n\n\n<p>\u751f\u6210\u5b8c\u914d\u7f6e\u540e\u5c31\u53ef\u4ee5\u5f00\u59cb\u7f16\u8bd1Linux\u5185\u6838\u4e86\uff0c\u6211\u4eec\u53ea\u9700\u8981\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u65e2\u53ef\u5f00\u59cb\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>make -j $(nproc)<\/code><\/pre>\n\n\n\n<p>\u6839\u636e\u7535\u8111\u6027\u80fd\u4e0d\u540c\uff0c\u7f16\u8bd1\u65f6\u95f4\u4ece1\u5206\u949f\u523030\u5206\u949f\u751a\u81f3\u66f4\u4e45\u3002<\/p>\n\n\n\n<p>\u5f53\u663e\u793a<code>Kernel: arch\/x86\/boot\/bzImage is ready<\/code>\u65f6\uff0c\u610f\u5473\u7740\u7f16\u8bd1\u5df2\u7ecf\u5b8c\u6210\u4e86\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u73b0\u5728\u7f16\u8bd1\u51fa\u7684Linux\u53ea\u662f\u4e00\u4e2a\u5185\u6838\uff0c\u65e0\u6cd5\u76f4\u63a5\u8fd0\u884c\uff0c\u5982\u679c\u8981\u8fd0\u884c\u7684\u8bdd\u8fd8\u9700\u8981\u4e00\u4e2a\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf\u6765\u653e\u7f6e\u6240\u9700\u7684\u6587\u4ef6\u548c\u7a0b\u5e8f\uff0c\u6240\u4ee5\u6211\u4eec\u8fd8\u9700\u8981\u4e00\u4e2a\u5de5\u5177\uff1a<code>BusyBox<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">0x40 \u4e0b\u8f7d\u5e76\u914d\u7f6eBusyBox<\/h2>\n\n\n\n<p>\u9996\u5148\u5728<a href=\"https:\/\/busybox.net\/\">busybox.net<\/a>\u4e2d\u4e0b\u8f7d\u6e90\u7801\u538b\u7f29\u5305\u3002\u672c\u6559\u7a0b\u4f7f\u7528busybox-1.36.0\u3002<\/p>\n\n\n\n<p>\u4e0b\u8f7d\u4e4b\u524d\u8bf7\u5148\u9000\u56de\u5230\u4e0a\u5c42\u76ee\u5f55\uff0c\u4e5f\u5c31\u662f<code>build<\/code>\u76ee\u5f55\u4e2d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ..\nwget https:\/\/busybox.net\/downloads\/busybox-1.36.0.tar.bz2\ntar xvf busybox-1.36.0.tar.bz2\ncd busybox-1.36.0<\/code><\/pre>\n\n\n\n<p>\u4e4b\u540e\u6211\u4eec\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u914d\u7f6e\u7f16\u8bd1\u9009\u9879\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>make menuconfig<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528\u65b9\u5411\u952e\u6765\u5207\u6362\u5149\u6807\uff0c\u56de\u8f66\u952e\u8fdb\u5165\u6761\u76ee\u3002<\/p>\n\n\n\n<p>\u5148\u8fdb\u5165<code>Settings<\/code>\uff0c\u7136\u540e\u5411\u4e0b\u627e\u5230<code>Build Options<\/code>\uff0c\u9009\u4e2d<code>Build static binary<\/code>\uff0c\u6309\u4e0b\u7a7a\u683c\u952e\u9009\u4e2d\uff0c\u4e4b\u540e\u524d\u9762\u65b9\u6846\u4e2d\u4f1a\u4eae\u8d77\u4e00\u4e2a<code>*<\/code>\u3002<\/p>\n\n\n\n<p>\u63a5\u7740\u6309\u53f3\u65b9\u5411\u952e\uff0c\u79fb\u52a8\u5230\u4e0b\u65b9Exit\u9009\u9879\uff0c\u6309\u4e0b<kbd>enter<\/kbd>\u9000\u51fa\uff0c\u63a5\u7740\u4f1a\u5f39\u51fa\u754c\u9762\u8be2\u95ee\u662f\u5426\u4fdd\u5b58\uff0c\u9009\u62e9Yes\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">0x50 \u521b\u5efa\u78c1\u76d8\u955c\u50cf<\/h2>\n\n\n\n<p>\u8fd4\u56de\u4e0a\u4e00\u7ea7\u76ee\u5f55\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u78c1\u76d8\u955c\u50cf\u5e76\u683c\u5f0f\u5316\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ..\ndd if=\/dev\/zero of=rootfs.img bs=1M count=20\nmkfs.ext4 rootfs.img<\/code><\/pre>\n\n\n\n<p>\u63a5\u7740\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8bd1BusyBox\uff0c\u5e76\u5c06\u5b83\u88c5\u8fdb\u78c1\u76d8\u955c\u50cf\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir fs\nsudo mount -t ext4 -o loop rootfs.img .\/fs\ncd busybox-1.36.0\nsudo make install -j $(nproc) CONFIG_PREFIX=..\/fs\ncd ..\/fs\nsudo mkdir proc dev etc home mnt\nsudo cp -r ..\/busybox-1.36.0\/examples\/bootfloppy\/etc\/* etc\/\ncd ..\nsudo umount fs<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">0x60 \u542f\u52a8Linux<\/h2>\n\n\n\n<p>\u81f3\u6b64\uff0c\u6211\u4eec\u7684\u51c6\u5907\u5de5\u4f5c\u5df2\u5168\u90e8\u5b8c\u6210\uff0c\u53ef\u4ee5\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u4f7f\u7528QEMU\u542f\u52a8Linux\u5185\u6838\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>qemu-system-x86_64 -kernel .\/linux-6.8\/arch\/x86_64\/boot\/bzImage -hda rootfs.img -append \"root=\/dev\/sda\"<\/code><\/pre>\n\n\n\n<p>\u4e4b\u540e\u4f1a\u5f39\u51fa\u4e00\u4e2aQEMU\u7684\u7a97\u53e3\uff0c\u8fd9\u5c31\u662f\u4f60\u7f16\u8bd1\u51fa\u7684Linux\u5185\u6838\u4e86\uff0c\u53ef\u4ee5\u5728\u5176\u4e2d\u6267\u884c\u4e00\u4e9b\u57fa\u7840\u7684\u547d\u4ee4\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">0x70 \u4e3a\u5185\u6838\u6dfb\u52a0\u6807\u7b7e\uff08\u53ef\u9009\uff09<\/h2>\n\n\n\n<p>\u5982\u679c\u4f60\u60f3\u8bc1\u660e\u8fd9\u4e2a\u5185\u6838\u662f\u4f60\u81ea\u5df1\u7f16\u8bd1\u51fa\u6765\u7684\uff0c\u53ef\u4ee5\u5728\u7f16\u8bd1Linux\u5185\u6838\u4e4b\u524d\u5411LOCALVERSION\u53d8\u91cf\u4e2d\u6dfb\u52a0\u4f60\u7684\u540d\u5b57\uff0c\u4f8b\u5982\u6211\u6dfb\u52a0\u7684\u662f\u201c-TIM\u201d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/scripts\/config --file .config --set-str LOCALVERSION \"-TIM\"<\/code><\/pre>\n\n\n\n<p>\u4e4b\u540e\u5c06\u8fd9\u4e2a\u5185\u6838\u542f\u52a8\u540e\u53ef\u4ee5\u4f7f\u7528<code>uname -r<\/code>\u547d\u4ee4\u663e\u793a\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>6.8-TIM<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>0x00 \u5b89\u88c5\u6240\u9700\u8f6f\u4ef6\u5305 \u9996\u5148\u5b89\u88c5\u6240\u9700\u8f6f\u4ef6\u5305\u3002 \u5982\u679c\u4f60\u7684\u7cfb\u7edf\u4e0d\u662fUbuntu\/Debian\uff0c\u8bf7\u7528\u5bf9\u5e94\u7684\u5305\u7ba1\u7406\u5668 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,25,18],"tags":[],"class_list":["post-68","post","type-post","status-publish","format-standard","hentry","category-c","category-linux","category-system"],"_links":{"self":[{"href":"http:\/\/blog.tntinminecraft.tech\/index.php\/wp-json\/wp\/v2\/posts\/68","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.tntinminecraft.tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.tntinminecraft.tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.tntinminecraft.tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.tntinminecraft.tech\/index.php\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":11,"href":"http:\/\/blog.tntinminecraft.tech\/index.php\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"predecessor-version":[{"id":86,"href":"http:\/\/blog.tntinminecraft.tech\/index.php\/wp-json\/wp\/v2\/posts\/68\/revisions\/86"}],"wp:attachment":[{"href":"http:\/\/blog.tntinminecraft.tech\/index.php\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.tntinminecraft.tech\/index.php\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.tntinminecraft.tech\/index.php\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}