{"id":53340,"date":"2023-06-13T09:38:12","date_gmt":"2023-06-13T01:38:12","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=53340"},"modified":"2023-06-13T09:38:12","modified_gmt":"2023-06-13T01:38:12","slug":"linux-root-file","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-root-file.html","title":{"rendered":"Linux\u6839\u6587\u4ef6\u5236\u4f5c"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u6839\u6587\u4ef6\u7cfb\u7edf\u9996\u5148\u662f\u5185\u6838\u542f\u52a8\u65f6\u6240mount\u7684\u7b2c\u4e00\u4e2a\u6587\u4ef6\u7cfb\u7edf\uff0c\u5185\u6838\u4ee3\u7801\u6620\u50cf\u6587\u4ef6\u4fdd\u5b58\u5728\u6839\u6587\u4ef6\u7cfb\u7edf\u4e2d\uff0c\u800c\u7cfb\u7edf\u5f15\u5bfc\u542f\u52a8\u7a0b\u5e8f\u4f1a\u5728\u6839\u6587\u4ef6\u7cfb\u7edf\u6302\u8f7d\u4e4b\u540e\u4ece\u4e2d\u628a\u4e00\u4e9b\u57fa\u672c\u7684\u521d\u59cb\u5316\u811a\u672c\u548c\u670d\u52a1\u7b49\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u53bb\u8fd0\u884c\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n 1.\u6839\u6587\u4ef6\u7cfb\u7edf<\/strong><\/div>\n \u6587\u4ef6\u7cfb\u7edf\u662f\u5305\u62ec\u5728\u4e00\u4e2a\u78c1\u76d8\uff08\u5305\u62ec\u5149\u76d8\u3001\u8f6f\u76d8\u3001\u95ea\u76d8\u53ca\u5176\u5b83\u5b58\u50a8\u8bbe\u5907\uff09\u6216\u5206\u533a\u7684\u76ee\u5f55\u7ed3\u6784\uff1b\u4e00\u4e2a\u53ef\u5e94\u7528\u7684\u78c1\u76d8\u8bbe\u5907\u53ef\u4ee5\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u6587\u4ef6\u7cfb\u7edf\uff1b\u5982\u679c\u60a8\u60f3\u8fdb\u5165\u4e00\u4e2a\u6587\u4ef6\u7cfb\u7edf\uff0c\u9996\u5148\u60a8\u8981\u505a\u7684\u662f\u6302\u8f7d\uff08mount\uff09\u6587\u4ef6\u7cfb\u7edf\uff1b\u4e3a\u4e86\u6302\u8f7d\uff08mount\uff09\u6587\u4ef6\u7cfb\u7edf\uff0c\u60a8\u5fc5\u987b\u6307\u5b9a\u4e00\u4e2a\u6302\u8f7d\u70b9\u3002<\/p>\n \u6ce8\uff1a\u5bf9\u4e8e\u6211\u4eec\u5e94\u7528\u5f00\u53d1\u6765\u8bf4\uff0c\u8d2d\u4e70\u5f00\u53d1\u677f\u7684\u65f6\u5019\uff0c\u5382\u5bb6\u4f1a\u63d0\u4f9b\u597d\u73b0\u6210\u7684\u6839\u6587\u4ef6\u7cfb\u7edf\u548cBootLoader\u7b49\uff0c\u5982\u679c\u9700\u8981\uff0c\u6211\u4eec\u53ef\u4ee5\u6539\u53d8\u5176\u4e2d\u7684\u547d\u4ee4\u800c\u65e0\u9700\u4ece\u5934\u5f00\u59cb\u5236\u4f5c\u4e00\u4e2a\u65b0\u7684\u6839\u6587\u4ef6\u7cfb\u7edf\u3002\u4e0d\u8fc7\u8fd9\u513f\u7684\u5236\u4f5c\u8fc7\u7a0b\u53ef\u4ee5\u8ba9\u6211\u4eec\u66f4\u6df1\u4e00\u70b9\u7406\u89e3Linux\u7684\u6587\u4ef6\u7cfb\u7edf\u3002<\/p>\n 2.\u4e3b\u8981\u7684\u6839\u6587\u4ef6\u7cfb\u7edf<\/strong><\/div>\n * Linux \u4e2d\uff0crootfs \u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002PC \u4e0a\u4e3b\u8981\u5b9e\u73b0\u6709 ramdisk \u548c\u76f4\u63a5\u6302\u8f7d HD\uff08Harddisk\uff0c\u786c\u76d8\uff09\u4e0a\u7684\u6839\u6587\u4ef6\u7cfb\u7edf\uff1b\u5d4c\u5165\u5f0f\u4e2d\u4e00\u822c\u4e0d\u4ece HD \u542f\u52a8\uff0c\u800c\u662f\u4ece Flash \u542f\u52a8\uff0c\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u5c06 rootfs load \u5230 RAM \u7684RAMDisk\uff0c\u7a0d\u590d\u6742\u7684\u5c31\u662f\u76f4\u63a5\u4eceFlash \u8bfb\u53d6\u7684 Cramfs\uff0c\u66f4\u590d\u6742\u7684\u662f\u5728 Flash \u4e0a\u5206\u533a\uff0c\u5e76\u6784\u5efa JFFS2 \u7b49\u6587\u4ef6\u7cfb\u7edf\u3002<\/p>\n * RAMDisk \u5c06\u5236\u4f5c\u597d\u7684 rootfs \u538b\u7f29\u540e\u5199\u5165 Flash\uff0c\u542f\u52a8\u7684\u65f6\u5019\u7531 Bootloader load \u5230RAM\uff0c\u89e3\u538b\u7f29\uff0c\u7136\u540e\u6302\u8f7d\u5230 \/\u3002\u8fd9\u79cd\u65b9\u6cd5\u64cd\u4f5c\u7b80\u5355\uff0c\u4f46\u662f\u5728 RAM \u4e2d\u7684\u6587\u4ef6\u7cfb\u7edf\u4e0d\u662f\u538b\u7f29\u7684\uff0c\u56e0\u6b64\u9700\u8981\u5360\u7528\u8bb8\u591a\u5d4c\u5165\u5f0f\u7cfb\u7edf\u4e2d\u7a00\u6709\u8d44\u6e90 RAM\u3002<\/p>\n ramdisk \u5c31\u662f\u7528\u5185\u5b58\u7a7a\u95f4\u6765\u6a21\u62df\u51fa\u786c\u76d8\u5206\u533a,ramdisk\u901a\u5e38\u4f7f\u7528\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf\u7684\u538b\u7f29\u5b58\u653e\u5728flash\u4e2d,\u5728\u7cfb\u7edf\u521d\u59cb\u5316\u65f6,\u89e3\u538b\u7f29\u5230SDRAM\u5e76\u6302\u8f7d\u6839\u6587\u4ef6\u7cfb\u7edf, \u5728linux\u7cfb\u7edf\u4e2d,ramdisk\u6709\u4e8c\u79cd,\u4e00\u79cd\u5c31\u662f\u53ef\u4ee5\u683c\u5f0f\u5316\u5e76\u52a0\u8f7d,\u5728linux\u5185\u68382.0\/2.2\u5c31\u5df2\u7ecf\u652f\u6301,\u5176\u4e0d\u8db3\u4e4b\u5904\u662f\u5927\u5c0f\u56fa\u5b9a;\u53e6\u4e00\u79cd\u662f 2.4\u7684\u5185\u6838\u624d\u652f\u6301,\u901a\u8fc7,ramfs\u6765\u5b9e\u73b0,\u4ed6\u4e0d\u80fd\u88ab\u683c\u5f0f\u5316,\u4f46\u7528\u8d77\u6765\u65b9\u4fbf,\u5176\u5927\u5c0f\u968f\u6240\u9700\u8981\u7684\u7a7a\u95f4\u589e\u52a0\u6216\u51cf\u5c11,\u662f\u76ee\u524dlinux\u5e38\u7528\u7684ramdisk\u6280 \u672f\u3002<\/p>\n * initrd \u662f RAMDisk \u7684\u683c\u5f0f\uff0ckernel 2.4 \u4e4b\u524d\u90fd\u662f image-initrd\uff0cKernel 2.5 \u5f15\u5165\u4e86 cpio-initrd\uff0c\u5927\u5927\u7b80\u5316\u4e86 Linux \u7684\u542f\u52a8\u8fc7\u7a0b\uff0c\u9644\u5408 Linux \u7684\u57fa\u672c\u54f2\u5b66\uff1aKeep it simple, stupid(KISS). \u4e0d\u8fc7cpio-initrd \u4f5c\u4e3a\u65b0\u7684\u683c\u5f0f\uff0c\u8fd8\u6ca1\u6709\u7ecf\u8fc7\u5e7f\u6cdb\u6d4b\u8bd5\uff0c\u5d4c\u5165\u5f0f Linux \u4e2d\u4e3b\u8981\u91c7\u7528\u7684\u8fd8\u662f image-initrd\u3002<\/p>\n * Cramfs \u662f Linus \u5199\u7684\u5f88\u7b80\u5355\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u6709\u5f88\u597d\u7684\u538b\u7f29\u7eff\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4ece Flash \u4e0a\u8fd0\u884c\uff0c\u4e0d\u987b load \u5230 RAM \u4e2d\uff0c\u56e0\u6b64\u8282\u7ea6\u4e86 RAM\u3002\u4f46\u662f Cramfs \u662f\u53ea\u8bfb\u7684\uff0c\u5bf9\u4e8e\u9700\u8981\u8fd0\u884c\u65f6\u4fee\u6539\u7684\u76ee\u5f55\uff08\u5982\uff1a \/etc, \/var, \/tmp\uff09\u591a\u6709\u4e0d\u4fbf\uff0c\u56e0\u6b64\uff0c\u4e00\u822c\u5c06\u8fd9\u4e9b\u76ee\u5f55\u505a\u6210ramfs \u7b49\u53ef\u5199\u7684 fs\u3002<\/p>\n * SquashFS \u662f\u5bf9 Cramfs \u7684\u589e\u5f3a\u3002\u7a81\u7834\u4e86 Cramfs \u7684\u4e00\u4e9b\u9650\u5236\uff0c\u5728 Flash \u548c RAM \u7684\u4f7f\u7528\u91cf\u65b9\u9762\u4e5f\u5177\u6709\u4f18\u52bf\u3002\u4e0d\u8fc7\uff0c\u636e\u5f00\u53d1\u8005\u4ecb\u7ecd\uff0c\u5728\u6027\u80fd\u4e0a\u53ef\u80fd\u4e0d\u5982 Cramfs\u3002\u8fd9\u4e5f\u662f\u4e00\u79cd\u65b0\u65b9\u6cd5\uff0c\u5728\u5d4c\u5165\u5f0f\u7cfb\u7edf\u91c7\u7528\u4e4b\u524d\uff0c\u9700\u8981\u7ecf\u8fc7\u66f4\u591a\u7684\u6d4b\u8bd5\u3002<\/p>\n 3.Ramdisk\u5236\u4f5c<\/strong><\/div>\n RAMDisk\u7684\u5236\u4f5c\u65b9\u6cd5\u5982\u4e0b\uff1a $ dd if=\/dev\/zero of=init.img bs=4096 count=1024<\/pre>\n |