{"id":294091,"date":"2024-11-01T20:04:54","date_gmt":"2024-11-01T12:04:54","guid":{"rendered":"https:\/\/lrxjmw.cn\/ljxypqdzmygd.html"},"modified":"2024-11-01T20:04:54","modified_gmt":"2024-11-01T12:04:54","slug":"ljxypqdzmygd","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/ljxypqdzmygd.html","title":{"rendered":"linux vm \u89e3\u6790\u786c\u76d8\u542f\u52a8\u4e2d MBR \u4e0e GRUB \u7684\u5173\u7cfb\u53ca 16 \u4f4d\u5b9e\u6a21\u5f0f\u4ee3\u7801\u7684\u4f5c\u7528"},"content":{"rendered":"

\n

......<\/code><\/pre>\n<\/p>\n

\u4e0a\u9762\u63d0\u53ca\u8fc7\uff0c\u786c\u789f\u4e2dMBR\u662f\u7531GRUB\u5199\u5165\u7684boot.img\uff0c\u56e0\u800c\u8fd9\u513f\u7684linux\/arch\/x86\/boot\/head.S\u4e2d\u7684bootsector\u5bf9\u4e8e\u786c\u789f\u542f\u52a8\u662f\u65e0\u7528\u7684\u3002GRUB\u5c06vmlinuz\u7684setup.bin\u90e8\u4efd\u8bfb\u5230\u663e\u5b58\u5730\u57400x90000\u5904\uff0c\u4e4b\u540e\u8df3\u8f6c\u52300x90200\u5f00\u59cb\u6267\u884c\uff0c\u6b63\u597d\u8df3\u8fc7\u4e86\u4e0a\u9762512\u5b57\u8282\u7684bootsector\uff0c\u4ece_start\u5f00\u59cb\u3002<\/p>\n

16\u4f4d\u7684main\u51fd\u6570<\/p>\n

\u6211\u4eec\u4e00\u822c\u7528C\u7f16\u8bd1\u5668\u7f16\u8bd1\u7684\u4ee3\u7801\uff0c\u662f32\u4f4d\u4fdd\u62a4\u6a21\u5f0f\u4e0b\u7684\u6216\u5219\u662f64\u4f4d\u957f\u6a21\u5f0f\u7684\uff0c\u5374\u6781\u5c11\u7f16\u8bd1\u621016\u4f4d\u5b9e\u6a21\u5f0f\u4e0b\u7684\uff0c\u867d\u7136setup.bin\u5927\u90e8\u4efd\u4ee3\u7801\u90fd\u662f16\u4f4d\u5b9e\u6a21\u5f0f\u4e0b\u7684\u3002\u4ece\u4e0a\u9762\u7684\u4ee3\u7801\u91cc\uff0c\u6211\u4eec\u5c31\u80fd\u770b\u89c1\u5728linux\/arch\/x86\/boot\/head.S\u4e2d\u8c03\u7528\u4e86main\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5728linux\/arch\/x86\/boot\/main.c\u6587\u4ef6\u4e2d\uff0c\u4ee3\u7801\u5982\u4e0b<\/p>\n

\u91cc\u9762\u90a3\u4e9b\u51fd\u6570\u90fd\u5728linux\/arch\/x86\/boot\/\u76ee\u5f55\u5bf9\u5e94\u7684\u6587\u4ef6\u4e2d\uff0c\u90fd\u662f\u8c03\u7528BIOS\u4e2d\u65ad\u5b8c\u6210\u7684\uff0c\u5177\u4f53\u7ec6\u8282\uff0c\u4f60\u53ef\u4ee5\u81ea\u884c\u67e5\u770b\u3002\u6211\u8fd9\u513f\u5217\u4e3e\u7684\u4ee3\u7801\u53ea\u662f\u5e2e\u52a9\u4f60\u7406\u6e05\u6d41\u7a0b\uff0c\u6211\u4eec\u7ee7\u7eed\u77a7\u77a7go_to_protected_mode()\u51fd\u6570\uff0c\u5728linux\/arch\/x86\/boot\/pm.c\u4e2d\uff0c\u4ee3\u7801\u5982\u4e0b\u3002<\/p>\n

protected_mode_jump\u662f\u4e2a\u6c47\u7f16\u51fd\u6570\uff0c\u5728linux\/arch\/x86\/boot\/pmjump.S\u6587\u4ef6\u4e2d\u5373\u8df3\u8f6c\u5230boot_params.hdr.code32_start\u4e2d\u7684\u5730\u5740\u3002\u8fd9\u4e2a\u5730\u5740\u5728linux\/arch\/x86\/boot\/head.S\u6587\u4ef6\u4e2d\u8bbe\u4e3a0x100000\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n

\u987b\u8981\u6ce8\u610f\u7684\u662f\uff0cGRUB\u4f1a\u628avmlinuz\u4e2d\u7684vmlinux.bin\u90e8\u4efd\uff0c\u7f6e\u4e8e1MB\u5f00\u59cb\u7684\u663e\u5b58\u7a7a\u95f4\u4e2d\u3002\u901a\u8fc7\u8fd9\u4e00\u8df3\u8f6c\uff0c\u5373\u5c06\u6b65\u5165vmlinux.bin\u4e2d\u3002<\/p>\n

startup_32\u51fd\u6570<\/p>\n

startup_32\u4e2d\u987b\u8981\u91cd\u65b0\u52a0\u8f7d\u6bb5\u63cf\u8ff0\u7b26\uff0c\u7136\u540e\u4f30\u7b97vmlinux.bin\u6587\u4ef6\u7684\u7f16\u8bd1\u751f\u6210\u7684\u5730\u5740\u548c\u5b9e\u9645\u52a0\u8f7d\u5730\u5740\u7684\u504f\u659c\uff0c\u4e4b\u540e\u91cd\u65b0\u8bbe\u7f6e\u5185\u6838\u6808linux\u670d\u52a1\u5668\u4ee3\u7ef4\uff0c\u6d4b\u91cfCPU\u662f\u5426\u652f\u6301\u957f\u6a21\u5f0f\uff0c\u63a5\u7740\u518d\u5ea6\u4f30\u7b97vmlinux.bin\u52a0\u8f7d\u5730\u5740\u7684\u504f\u659c\uff0c\u6765\u786e\u5b9a\u5bf9\u5176\u4e2dvmlinux.bin.gz\u89e3\u538b\u7f29\u7684\u5730\u5740\u3002\u5047\u5982CPU\u652f\u6301\u957f\u6a21\u5f0f\u7684\u8bdd\uff0c\u5c31\u8981\u8bbe\u7f6e64\u4f4d\u7684\u5168\u5c40\u63cf\u8ff0\u8868\uff0c\u5f00\u542fCPU\u7684PAE\u5316\u5b66\u5730\u5740\u6269\u5c55\u7279\u70b9\u3002\u518d\u8bbe\u7f6e\u6700\u521d\u7684MMU\u9875\u8868\uff0c\u6700\u540e\u5f00\u542f\u5206\u9875\u5e76\u6b65\u5165\u957f\u6a21\u5f0f\uff0c\u8df3\u8f6c\u5230startup_64\uff0c\u4ee3\u7801\u5982\u4e0b\u3002<\/p>\n

startup_64\u51fd\u6570\u5982\u4eca\uff0c\u6211\u4eec\u603b\u7b97\u5f00\u542f\u4e86CPU\u957f\u6a21\u5f0f\uff0c\u4ecestartup_64\u5f00\u59cb\u771f\u6b63\u6b65\u5165\u4e8664\u4f4d\u7684\u65f6\u4ee3\uff0c\u53ef\u559c\u53ef\u8d3a\u3002startup_64\u51fd\u6570\u540c\u6837\u4e5f\u662f\u5728linux\/arch\/x86\/boot\/compressed\/head64.S\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\u3002startup_64\u51fd\u6570\u4e2d\uff0c\u521d\u59cb\u5316\u957f\u6a21\u5f0f\u4e0b\u6570\u636e\u6bb5\u5bc4\u5b58\u5668\uff0c\u786e\u5b9a\u6700\u7ec8\u89e3\u538b\u7f29\u5730\u5740\uff0c\u4e4b\u540e\u62f7\u8d1d\u538b\u7f29vmlinux.bin\u5230\u8be5\u5730\u5740\uff0c\u8df3\u8f6c\u5230decompress_kernel\u5730\u5740\u5904\uff0c\u5f00\u59cb\u89e3\u538bvmlinux.bin.gz\uff0c<\/p>\n

\u4e0a\u8ff0\u4ee3\u7801\u4e2d\u6700\u540e\u5230\u4e86extract_kernel\u51fd\u6570\uff0c\u5b83\u5c31\u662f\u89e3\u538b\u5185\u6838\u7684\u51fd\u6570\uff0c\u4e0b\u8fb9\u6211\u4eec\u5c31\u6765\u7814\u7a76\u5b83\u3002<\/p>\n

extract_kernel\u51fd\u6570<\/p>\n

\u4ecestartup_32\u51fd\u6570\u5230startup_64\u51fd\u6570\uff0c\u5176\u95f4\u7ecf\u8fc7\u4e86\u4fdd\u62a4\u6a21\u5f0f\u3001\u957f\u6a21\u5f0f\uff0c\u6700\u7ec8\u62b5\u8fbe\u4e86extract_kernel\u51fd\u6570\uff0cextract_kernel\u51fd\u6570\u4f9d\u636epiggy.o\u4e2d\u7684\u4fe1\u606f\u4ecevmlinux.bin.gz\u4e2d\u89e3\u538b\u51favmlinux\u3002\u4f9d\u7167\u4e0a\u9762\u7684\u77e5\u8bc6\u70b9\uff0c\u6211\u4eec\u6653\u5f97vmlinux\u6b63\u662f\u7f16\u8bd1\u51faLinux<\/a>\u5185\u6838elf\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u53ea\u4e0d\u8fc7\u5b83\u88ab\u9664\u53bb\u4e86\u7b26\u53f7\u4fe1\u606f\u3002\u6240\u4ee5\uff0cextract_kernel\u51fd\u6570\u4e0d\u4ec5\u4ec5\u662f\u89e3\u538b\uff0c\u8fd8\u987b\u8981\u89e3\u6790elf\u683c\u5f0f\u3002extract_kernel\u51fd\u6570\u662f\u5728linux\/arch\/x86\/boot\/compressed\/misc.c\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684<\/p>\n

\u6b63\u5982\u524d\u9762\u4ee3\u7801\u6240\u793a\uff0cextract_kernel\u51fd\u6570\u8c03\u7528__decompress\u51fd\u6570\uff0c\u5bf9vmlinux.bin.gz\u4f7f\u7528\u7279\u5b9a\u7684\u89e3\u538b\u7b97\u6cd5\u8fdb\u884c\u89e3\u538b\u3002\u89e3\u538b\u7b97\u6cd5\u662f\u7f16\u8bd1\u5185\u6838\u7684\u914d\u7f6e\u9009\u9879\u51b3\u5b9a\u7684\u3002\u5e76\u4e14\uff0c__decompress\u51fd\u6570\u89e3\u538b\u4e0b\u6765\u7684\u662fvmlinux\u6587\u4ef6\u662felf\u683c\u5f0f\u7684\uff0c\u6240\u4ee5\u8fd8\u8981\u8c03\u7528parse_elf\u51fd\u6570\u8fdb\u4e00\u6b65\u89e3\u6790elf\u683c\u5f0f\uff0c\u628avmlinux\u4e2d\u7684\u6307\u4ee4\u6bb5\u3001\u6570\u636e\u6bb5\u3001BSS\u6bb5\uff0c\u6309\u7167elf\u4e2d\u4fe1\u606f\u548c\u8981\u6c42\u88c5\u5165\u7279\u5b9a\u7684\u663e\u5b58\u7a7a\u95f4\uff0c\u8fd4\u56de\u6307\u4ee4\u6bb5\u7684\u5165\u53e3\u5730\u5740\u3002<\/p>\n

\u8bf7\u4f60\u6ce8\u610f\uff0c\u5728Lrelocated\u51fd\u6570\u7684\u6700\u540e\u4e00\u6761\u6307\u4ee4\uff1ajmp*rax\uff0c\u5176\u4e2d\u7684rax\u4e2d\u5c31\u662f\u4fdd\u5b58\u7684extract_kernel\u51fd\u6570\u8fd4\u56de\u7684\u5165\u53e3\u70b9\uff0c\u5c31\u662f\u4ece\u8fd9\u513f\u5f00\u59cb\u6b65\u5165\u4e86Linux\u5185\u6838<\/p>\n

Linux\u5185\u6838\u7684startup_64<\/p>\n

\u8fd9\u513f\u6211\u63d0\u9192\u4f60\u7559\u5fc3\uff0c\u6b64\u65f6\u7684startup_64\u51fd\u6570\u5e76\u4e0d\u662f\u4e4b\u524d\u7684startup_64\u51fd\u6570\uff0c\u4e5f\u4e0d\u53c2\u4e0e\u540e\u9762\u7684\u94fe\u63a5\u5de5\u4f5c\u3002\u8fd9\u4e2astartup_64\u51fd\u6570\u5b9a\u4e49\u5728linux\/arch\/x86\/kernel\/head_64.S\u6587\u4ef6\u4e2d\uff0c\u5b83\u662f\u5185\u6838\u7684\u5165\u53e3\u51fd\u6570\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n

\u4e0a\u8ff0\u4ee3\u7801\u4e2d\u7701\u7565\u4e86\u548c\u6d41\u7a0b\u65e0\u5173\u7684\u4ee3\u7801\uff0c\u5bf9\u4e8eSMP\u7cfb\u7edf\u52a0\u7535\u4ee5\u540e\uff0c\u603b\u7ebf\u4ef2\u88c1\u673a\u5236\u4f1a\u9009\u51fa\u591a\u4e2aCPU\u4e2d\u7684\u4e00\u4e2aCPU\uff0c\u79f0\u4e3aBSP\uff0c\u4e5f\u53eb\u7b2c\u4e00\u4e2aCPU\u3002\u5b83\u8d1f\u8d23\u8ba9BSPCPU\u5148\u542f\u52a8\uff0c\u5176\u5b83CPU\u5219\u7b49\u5f85BSPCPU\u7684\u5524\u8d77\u3002<\/p>\n

\u8fd9\u513f\u6211\u6765\u5206\u60c5\u51b5\u7ed9\u4f60\u804a\u804a\u3002\u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u542f\u52a8\u7684CPU\uff0c\u4f1a\u8df3\u8f6csecondary_startup_64\u51fd\u6570\u4e2d1\u6807\u53f7\u5904\uff0c\u5bf9\u4e8e\u5176\u5b83\u88ab\u5524\u8d77\u7684CPU\u5219\u4f1a\u76f4\u63a5\u6267\u884csecondary_startup_64\u51fd\u6570\u3002\u63a5\u51fa\u6765\uff0c\u6211\u7ed9\u4f60\u5feb\u901f\u8fc7\u4e00\u904dsecondary_startup_64\u51fd\u6570\uff0c\u65c1\u8fb9\u7684\u4ee3\u7801\u6211\u7701\u7565\u4e86\u8fd9\u4e2a\u51fd\u6570\u5bf9\u66f4\u591aCPU\u7279\u70b9\uff08\u8bbe\u7f6eGDT\u3001IDT\uff0c\u5904\u7406\u4e86MMU\u9875\u8868\u7b49\uff09\u7684\u68c0\u6d4b\uff0c\u7531\u4e8e\u8fd9\u79cd\u5de5\u4f5c\u6211\u4eec\u5df2\u7ecf\u5f88\u719f\u6089\u4e86\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\u3002<\/p>\n

\u5728secondary_startup_64\u51fd\u6570\u4e00\u5207\u6253\u7b97\u5c31\u7eea\u4ee5\u540e\uff0c\u6700\u540e\u90fd\u4f1a\u8c03\u7528x86_64_start_kernel\u51fd\u6570\uff0c\u770b\u5b83\u7684\u540d\u5b50\u4f3c\u4e4e\u662f\u5185\u6838\u7684\u5f00\u59cb\u51fd\u6570\uff0c\u4f46\u771f\u7684\u662f\u8fd9\u6837\u5417\uff0c\u6211\u4eec\u4e00\u8d77\u77a7\u77a7\u624d\u6653\u5f97<\/p>\n

Linux\u5185\u6838\u7684\u7b2c\u4e00\u4e2aC\u51fd\u6570<\/p>\n

\u82e5\u4e0d\u662f\u7ecf\u5386\u4e86\u4e0a\u9762\u7684\u5256\u6790\u8bb2\u89e3\u3002\u8981\u662f\u6211\u95ee\u4f60Linux\u5185\u6838\u7684\u7b2c\u4e00\u4e2aC\u51fd\u6570\u662f\u54ea\u4e9b\uff0c\u4f60\u53ef\u80fd\u65e0\u4ece\u8bf4\u8d77\uff0c\u5373\u4f7f\u4e00\u901a\u767e\u5ea6\u4ee5\u540e\uff0c\u4e00\u76f4\u672a\u80fd\u786e\u5b9a.<\/p>\n

\u7136\u800c\uff0c\u53ea\u8981\u6211\u4eec\u8ddf\u968f\u4ee3\u7801\u7684\u6267\u884c\u6d41\u7a0b\uff0c\u90fd\u4f1a\u53d1\u89c9\u5728secondary_startup_64\u51fd\u6570\u7684\u6700\u540e\uff0c\u8c03\u7528\u7684x86_64_start_kernel\u51fd\u6570\u662f\u7528C\u8bed\u8a00\u5199\u7684\uff0c\u8fd9\u4e48\u5b83\u4e00\u5b9a\u5c31\u662fLinux\u5185\u6838\u7684\u7b2c\u4e00\u4e2aC\u51fd\u6570\u3002\u5b83\u5728linux\/arch\/x86\/kernel\/head64.c\u6587\u4ef6\u4e2d\u88ab\u5b9a\u4e49\uff0c\u8fd9\u4e2a\u6587\u4ef6\u540d\u4f60\u751a\u81f3\u90fd\u80fd\u731c\u4e0b\u6765\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n

x86_64_start_kernel\u51fd\u6570\u4e2d\u53c8\u4e00\u6b21\u5904\u7406\u4e86\u9875\u8868\uff0c\u5904\u7406\u9875\u8868\u5c31\u662f\u5904\u7406Linux\u5185\u6838\u865a\u62df\u5730\u5740\u7a7a\u95f4\uff0cLinux\u865a\u62df\u5730\u5740\u7a7a\u95f4\u662f\u4e00\u6b65\u6b65\u6784\u5efa\u7684\u3002\u4e4b\u540e\uff0cx86_64_start_kernel\u51fd\u6570\u590d\u5236\u4e86\u5f15\u5bfc\u4fe1\u606f\uff0c\u5373structboot_params\u7ed3\u6784\u4f53\u3002\u6700\u540e\u8c03\u7528\u4e86x86_64_start_reservations\u51fd\u6570\uff0c\u5176\u4e2d\u5904\u7406\u4e86\u5e73\u53f0\u56fa\u4ef6\u76f8\u5173\u7684\u4e1c\u897f\uff0c\u5c31\u662f\u8c03\u7528\u4e86\u5927\u540d\u9f0e\u9f0e\u7684start_kernel\u51fd\u6570\u3002<\/p>\n

\u6709\u540d\u7684start_kernel\u51fd\u6570<\/p>\n

start_kernel\u51fd\u6570\u4e4b\u6240\u4ee5\u6709\u540dlinux vm<\/strong>\uff0c\u8fd9\u662f\u7531\u4e8e\u5728\u4e92\u8054\u7f51\u4e0a\uff0c\u5728\u5404\u5927Linux\u540d\u8457\u4e4b\u4e2d\uff0c\u5c31\u4f1a\u5927\u91cf\u5ba3\u4f20\u5b83Linux\u5185\u6838\u4e2d\u7684\u5730\u4f4d\u548c\u4f5c\u7528linux\u64cd\u4f5c\u7cfb\u7edf\u8bba\u6587\uff0c\u6b63\u5982\u5176\u540d\u5b50\u6292\u53d1\u7684\u542b\u4e49\uff0c\u8fd9\u662f\u5185\u6838\u7684\u5f00\u59cb\u3002\u5e76\u4e14\u95ee\u9898\u6765\u4e86\u3002\u6211\u4eec\u4e00\u8def\u8d70\u6765\uff0c\u53d1\u89c9start_kernel\u51fd\u6570\u4e4b\u524d\u6709\u5927\u91cf\u7684\u4ee3\u7801\u6267\u884c\uff0c\u90a3\u8fd9\u79cd\u4ee3\u7801\u7b97\u4e0d\u7b97\u5185\u6838\u7684\u5f00\u59cb\u5462\uff1f\u5176\u5b9e\u4e5f\u53ef\u4ee5\u8bf4\u90a3\u5c31\u662f\u5185\u6838\u7684\u5f00\u59cb\uff0c\u4e5f\u53ef\u4ee5\u8bf4\u662f\u524d\u671f\u5de5\u4f5c\u3002<\/p>\n

\u867d\u7136\uff0cstart_kernel\u51fd\u6570\u4e2d\u8c03\u7528\u4e86\u5927\u91cfLinux\u5185\u6838\u529f\u80fd\u7684\u521d\u59cb\u5316\u51fd\u6570\uff0c\u5b83\u5b9a\u4e49\u5728\/linux\/init\/main.c\u6587\u4ef6\u4e2d\u3002<\/p>\n

start_kernel\u51fd\u6570\u6211\u82e5\u679c\u4e0d\u505a\u7cbe\u7b80\uff0c\u4f1a\u6709200\u591a\u884c\uff0c\u5168\u90e8\u90fd\u662f\u521d\u59cb\u5316\u51fd\u6570\uff0c\u6211\u53ea\u7559\u4e0b\u51e0\u4e2a\u4e3b\u8981\u7684\u521d\u59cb\u5316\u51fd\u6570\uff0c\u8fd9\u79cd\u51fd\u6570\u7684\u5b9e\u73b0\u7ec6\u8282\u6211\u4eec\u65e0\u9700\u5173\u5fc3\u3002\u53ef\u4ee5\u770b\u89c1\uff0cLinux\u5185\u6838\u6240\u6709\u529f\u80fd\u7684\u521d\u59cb\u5316\u51fd\u6570\u90fd\u662f\u5728start_kernel\u51fd\u6570\u4e2d\u8c03\u7528\u7684\uff0c\u8fd9\u4e5f\u662f\u5b83\u8fd9\u4e48\u51fa\u540d\uff0c\u8fd9\u4e48\u91cd\u8981\u7684\u8bf1\u56e0\u3002\u4e00\u65e6start_kernel\u51fd\u6570\u6267\u884c\u5b8c\u6210\uff0cLinux\u5185\u6838\u5c31\u5177\u5907\u4e86\u5411\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4e00\u7cfb\u5217\u529f\u80fd\u670d\u52a1\u7684\u80fd\u529b\u3002\u8fd9\u513f\u5bf9\u6211\u4eec\u800c\u8a00\uff0c\u6211\u4eec\u53ea\u5173\u6ce8\u4e00\u4e2aarch_call_rest_init\u51fd\u6570\u3002\u4e0b\u8fb9\u6211\u4eec\u5c31\u6765\u7814\u7a76\u5b83\u3002\u5982\u4e0b\u6240\u793a\u3002<\/p>\n

rest_init\u51fd\u6570\u7684\u91cd\u8981\u529f\u80fd\u5c31\u662f\u6784\u5efa\u4e86\u4e24\u4e2aLinux\u5185\u6838\u7ebf\u7a0b\uff0c\u6211\u4eec\u77a7\u77a7\u7cbe\u7b80\u540e\u7684rest_init\u51fd\u6570\uff1a<\/p>\n

Linux\u5185\u6838\u7ebf\u7a0b\u53ef\u4ee5\u6267\u884c\u4e00\u4e2a\u5185\u6838\u51fd\u6570\uff0c\u53ea\u4e0d\u8fc7\u8fd9\u4e2a\u51fd\u6570\u6709\u72ec\u7acb\u7684\u7ebf\u7a0b\u4e0a\u4e0b\u6587\uff0c\u53ef\u4ee5\u88abLinux\u7684\u8fdb\u7a0b\u8c03\u5ea6\u5668\u8c03\u5ea6\uff0c\u5bf9\u4e8ekernel_init\u7ebf\u7a0b\u6765\u8bf4\uff0c\u6267\u884c\u7684\u5c31\u662fkernel_init\u51fd\u6570<\/p>\n

Linux\u7684\u7b2c\u4e00\u4e2a\u7528\u6237\u8fdb\u7a0b<\/p>\n

\u5f53\u6211\u4eec\u53ef\u4ee5\u6784\u5efa\u7b2c\u4e00\u4e2a\u7528\u6237\u8fdb\u7a0b\u7684\u65f6\u4faf\uff0c\u5c31\u4ee3\u8868Linux\u5185\u6838\u7684\u521d\u59cb\u6d41\u7a0b\u65e9\u5df2\u57fa\u672c\u5b8c\u6210\u3002\u7ecf\u5386\u4e86\u201c\u957f\u9014\u8dcb\u6d89\u201d\uff0c\u6211\u4eec\u4e5f\u603b\u7b97\u8d70\u5230\u4e86\u8fd9\u513f\u3002Linux\u5185\u6838\u7684\u7b2c\u4e00\u4e2a\u7528\u6237\u6001\u8fdb\u7a0b\u662f\u5728kernel_init\u7ebf\u7a0b\u6784\u5efa\u7684\uff0c\u800ckernel_init\u7ebf\u7a0b\u6267\u884c\u7684\u5c31\u662fkernel_init\u51fd\u6570\u3002\u90a3kernel_init\u51fd\u6570\u7a76\u7adf\u505a\u4e86\u54ea\u4e9b\u5462\uff1f<\/p>\n

\u7ed3\u5408\u4e0a\u8ff0\u4ee3\u7801\uff0c\u53ef\u4ee5\u53d1\u89c9ramdisk_execute_command\u548cexecute_command\u90fd\u662f\u5185\u6838\u542f\u52a8\u65f6\u4f20\u9012\u7684\u53c2\u6570\uff0c\u5b83\u4eec\u53ef\u4ee5\u5728GRUB\u542f\u52a8\u9009\u9879\u4e2d\u8bbe\u7f6e\u3002\u6bd4\u65b9\u8bf4\uff0c\u4e00\u822c\u5f15\u5bfc\u5185\u6838\u65f6\u5411commandline\u4f20\u9012\u7684\u53c2\u6570\u90fd\u662finit=xxx\uff0c\u800c\u5bf9\u4e8einitrd\u5219\u662f\u4f20\u9012rdinit=xxx\u3002<\/p>\n

\u7136\u800c\uff0c\u4e00\u822c\u6211\u4eec\u4e0d\u4f1a\u4f20\u9012\u53c2\u6570\uff0c\u6240\u4ee5\u8fd9\u4e2a\u51fd\u6570\u4f1a\u6267\u884c\u5230\u4e0a\u8ff0\u4ee3\u7801\u768415\u884c\uff0c\u4f9d\u6b21\u5c1d\u8bd5\u4ee5\/sbin\/init\u3001\/etc\/init\u3001\/bin\/init\u3001\/bin\/sh\u90a3\u4e9b\u6587\u4ef6\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u6784\u5efa\u8fdb\u7a0b\uff0c\u800c\u4e14\u53ea\u8981\u5176\u4e2d\u4e4b\u4e00\u6210\u529f\u5c31\u884c\u4e86\u3002<\/p>\n

try_to_run_init_process\u548crun_init_process\u51fd\u6570\u7684\u6838\u5fc3\u90fd\u662f\u8c03\u7528sys_fork\u51fd\u6570\u6784\u5efa\u8fdb\u7a0b\u7684\uff0c\u8fd9\u513f\u6211\u4eec\u4e0d\u7528\u5173\u6ce8\u5b83\u7684\u5b9e\u73b0\u7ec6\u8282\u3002\u5230\u8fd9\u513f\uff0cLinux\u5185\u6838\u65e9\u5df2\u6784\u5efa\u4e86\u7b2c\u4e00\u4e2a\u8fdb\u7a0b\uff0cLinux\u5185\u6838\u7684\u521d\u59cb\u5316\u6d41\u7a0b\u4e5f\u5230\u6b64\u4e3a\u6b62\u3002<\/p>\n

\u91cd\u70b9\u56de\u987e<\/p>\n

\u53c8\u5230\u4e86\u8bfe\u7a0b\u5c3e\u58f0\uff0cLinux\u521d\u59cb\u5316\u6d41\u7a0b\u7684\u5b66\u4e60\u6211\u4eec\u5c31\u544a\u4e00\u6bb5\u843d\u4e86\uff0c\u6211\u6765\u7ed9\u4f60\u505a\u4e2a\u603b\u7ed3\u3002<\/p>\n

\u660e\u5929\u6211\u4eec\u8bb2\u5f97\u5185\u5bb9\u6709\u70b9\u591a\uff0c\u6211\u4eec\u4ece_start\u5f00\u59cb\u5230startup32\u3001startup64\u51fd\u6570\uff0c\u5230extract_kernel\u51fd\u6570\u89e3\u538b\u51fa\u771f\u6b63\u7684Linux\u5185\u6838\u6587\u4ef6vmlinux\u5f00\u59cb\uff0c\u4e4b\u540e\u4eceLinux\u5185\u6838\u7684\u5165\u53e3\u51fd\u6570startup_64\u5230Linux\u5185\u6838\u7b2c\u4e00\u4e2aC\u51fd\u6570\uff0c\u6700\u540e\u63a5\u7740\u4eceLinux\u5185\u6838start_kernel\u51fd\u6570\u7684\u5b8c\u5584\uff0c\u8bf4\u5230\u4e86\u7b2c\u4e00\u4e2a\u7528\u6237\u8fdb\u7a0b\u3002<\/p>\n

\u4e00\u4e0a\u53bb\u56de\u987e\u4e00\u4e0b\u8fd9\u8282\u8bfe\u7684\u91cd\u70b9\uff1a<\/p>\n

1.GRUB\u52a0\u8f7dvmlinuz\u6587\u4ef6\u4ee5\u540e\uff0c\u4f1a\u628a\u63a7\u5236\u6743\u4ea4\u7ed9vmlinuz\u6587\u4ef6\u7684setup.bin\u7684\u90e8\u4efd\u4e2d_start\uff0c\u5b83\u4f1a\u8bbe\u7f6e\u597d\u6808\uff0c\u6e05\u7a7abss\uff0c\u8bbe\u7f6e\u597dsetup_header\u7ed3\u6784linux vm<\/strong>\uff0c\u8c03\u752816\u4f4dmain\u5207\u6362\u5230\u4fdd\u62a4\u6a21\u5f0f\uff0c\u6700\u540e\u8df3\u8f6c\u52301MB\u5904\u7684vmlinux.bin\u6587\u4ef6\u4e2d\u3002<\/p>\n

2.\u4ecevmlinux.bin\u6587\u4ef6\u4e2dstartup32\u3001startup64\u51fd\u6570\u5f00\u59cb\u6784\u5efa\u65b0\u7684\u5168\u5c40\u6bb5\u63cf\u8ff0\u7b26\u8868\u548cMMU\u9875\u8868\uff0c\u5207\u6362\u5230\u957f\u6a21\u5f0f\u4e0b\u89e3\u538bvmlinux.bin.gz\u3002\u91ca\u653e\u51favmlinux\u6587\u4ef6\u4ee5\u540e\uff0c\u7531\u89e3\u6790elf\u683c\u5f0f\u7684\u51fd\u6570\u8fdb\u884c\u89e3\u6790\uff0c\u91ca\u653evmlinux\u4e2d\u7684\u4ee3\u7801\u6bb5\u548c\u6570\u636e\u6bb5\u5230\u6307\u5b9a\u7684\u663e\u5b58\u3002\u4e4b\u540e\u8c03\u7528\u5176\u4e2d\u7684startup_64\u51fd\u6570\uff0c\u5728\u8fd9\u4e2a\u51fd\u6570\u7684\u6700\u540e\u8c03\u7528Linux\u5185\u6838\u7684\u7b2c\u4e00\u4e2aC\u51fd\u6570\u3002<\/p>\n

3.Linux\u5185\u6838\u7b2c\u4e00\u4e2aC\u51fd\u6570\u91cd\u65b0\u8bbe\u7f6eMMU\u9875\u8868\uff0c\u6b64\u540e\u4fbf\u8c03\u7528\u4e86\u6700\u6709\u540d\u7684start_kernel\u51fd\u6570\uff0cstart_kernel\u51fd\u6570\u4e2d\u8c03\u7528\u4e86\u5927\u591a\u6570Linux\u5185\u6838\u529f\u80fd\u6027\u521d\u59cb\u5316\u51fd\u6570\uff0c\u5728\u6700\u540e\u8c03\u7528rest_init\u51fd\u6570\u6784\u5efa\u4e86\u4e24\u4e2a\u5185\u6838\u7ebf\u7a0b\uff0c\u5728\u5176\u4e2d\u7684kernel_init\u7ebf\u7a0b\u6784\u5efa\u4e86\u7b2c\u4e00\u4e2a\u7528\u6237\u6001\u8fdb\u7a0b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5bf9\u4e8e\u786c\u76d8\u542f\u52a8\u662f\u65e0\u7528\u7684\u3002\u6587\u4ef6\u4e2d\uff0c\u4ee3\u7801\u5982\u4e0b\u7528\u7279\u5b9a\u7684\u89e3\u538b\u7b97\u6cd5\u8fdb\u884c\u89e3\u538b\u3002\u89e3\u538b\u7b97\u6cd5\u662f\u7f16\u8bd1\u5185\u6838\u7684\u914d\u7f6e\u9009\u9879\u51b3\u5b9a\u7684\u3002\u7801\u7b97\u4e0d\u7b97\u5185\u6838\u7684\u5f00\u59cb\u5462\uff1f\u4e3b\u8981\u7684\u521d\u59cb\u5316\u51fd\u6570\uff0c\u8fd9\u4e9b\u51fd\u6570\u7684\u5b9e\u73b0\u7ec6\u8282\u6211\u4eec\u65e0\u9700\u5173\u5fc3\u3002\u5185\u6838\u7684\u521d\u59cb\u6d41\u7a0b\u5df2\u7ecf\u57fa\u672c\u5b8c\u6210\u3002\u5185\u6838\u7684\u521d\u59cb\u5316\u6d41\u7a0b\u4e5f\u5230\u6b64\u4e3a\u6b62\u3002\u4e2d\u7684\u4ee3\u7801\u6bb5\u548c\u6570\u636e\u6bb5\u5230\u6307\u5b9a\u7684\u5185\u5b58\u3002\u7ebf\u7a0b\u5efa\u7acb\u4e86\u7b2c\u4e00\u4e2a\u7528\u6237\u6001\u8fdb\u7a0b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[3995,3996,3997,3994],"class_list":["post-294091","post","type-post","status-publish","format-standard","hentry","category-tougao","tag-211636609d203f181e45154c637355be","tag-lnhdm","tag-laxbhlaxbhla","tag-wsmsdm"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/294091","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=294091"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/294091\/revisions"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=294091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=294091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=294091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}