{"id":5895,"date":"2020-10-12T12:20:52","date_gmt":"2020-10-12T04:20:52","guid":{"rendered":"http:\/\/jc.a300.cn/luyouwang\/?p=5895"},"modified":"2020-10-12T12:20:52","modified_gmt":"2020-10-12T04:20:52","slug":"openwrt%e6%89%a9%e5%ae%b9overlay%e5%b9%b6%e5%bc%80%e5%90%afswap%e7%9a%84%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"http:\/\/jc.a300.cn/luyouwang\/5895.html","title":{"rendered":"OpenWrt\u6269\u5bb9overlay\u5e76\u5f00\u542fswap\u7684\u6559\u7a0b"},"content":{"rendered":"
Squashfs\uff08.sfs\uff09\u662f\u4e00\u5957\u4f9bLinux\u6838\u5fc3\u4f7f\u7528\u7684GPL\u5f00\u6e90\u53ea\u8bfb\u538b\u7f29\u6587\u4ef6\u7cfb\u7edf\u3002Squashfs\u80fd\u591f\u4e3a\u6587\u4ef6\u7cfb\u7edf\u5185\u7684\u6587\u4ef6\u3001inode\u53ca\u76ee\u5f55\u7ed3\u6784\u8fdb\u884c\u538b\u7f29\u3002<\/p>\n
Squashfs\u7684\u8bbe\u8ba1\u662f\u4e13\u95e8\u4e3a\u4e00\u822c\u7684\u53ea\u8bfb\u6587\u4ef6\u7cfb\u7edf\u7684\u4f7f\u7528\u800c\u8bbe\u8ba1\uff0c\u5b83\u53ef\u5e94\u7528\u4e8e\u6570\u636e\u5907\u4efd\uff0c\u6216\u662f\u7cfb\u7edf\u8d44\u6e90\u7d27\u5f20\u7684\u7535\u8111\u4e0a\u4f7f\u7528\u3002<\/p>\n
OpenWRT \u4e00\u822c\u4f7f\u7528\u7684\u6587\u4ef6\u7cfb\u7edf\u662f SquashFS \uff0c\u5efa\u8bae\u4e0b\u8f7d\u56fa\u4ef6\u7684\u65f6\u5019\u4e5f\u4e0b\u8f7d\u8fd9\u79cd\u56fa\u4ef6\u3002
\u8fd9\u4e2a\u6587\u4ef6\u7cfb\u7edf\u7684\u7279\u70b9\u5c31\u662f\uff1a\u53ea\u8bfb\u3001\u538b\u7f29\u3002<\/p>\n
\u4e00\u4e2a\u53ea\u8bfb\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u662f\u600e\u4e48\u505a\u5230\u4fdd\u5b58\u8bbe\u7f6e\u548c\u5b89\u88c5\u8f6f\u4ef6\u7684\u5462\uff1f\u7528\/overlay\u5206\u533a\u3002\u56fa\u4ef6\u4e2d\u5df2\u7ecf\u5199\u5165\u4e86\u6709\u4e2a\/overlay\u5206\u533a\uff0c\u4f46\u5b83\u7684\u6307\u5411\u53ef\u4ee5\u66f4\u6539\u3002<\/p>\n
<\/a><\/p>\n \u867d\u7136\u539f\u6765\u7684\u6587\u4ef6\u4e0d\u80fd\u4fee\u6539\uff0c\u4f46\u6211\u4eec\u628a\u4fee\u6539\u7684\u90e8\u5206\u653e\u5728 overlay \u5206\u533a\u4e0a\uff0c\u7136\u540e\u6620\u5c04\u5230\u539f\u6765\u7684\u4f4d\u7f6e\uff0c\u8bfb\u53d6\u7684\u65f6\u5019\u5c31\u53ef\u4ee5\u8bfb\u5230\u6211\u4eec\u4fee\u6539\u8fc7\u7684\u6587\u4ef6\u4e86\u3002\u5f53\u7cfb\u7edf\u6545\u969c\uff0creset\u7684\u65f6\u5019\uff0c\u628a\u56fa\u4ef6\u4e2d\u914d\u7f6e\u6587\u4ef6\u62f7\u8d1d\u5230overlay\u5c42\uff0c\u5c31\u6062\u590d\u5230\u6700\u521d\u8bbe\u7f6e\u4e86\u3002<\/p>\n \u7531\u4e8e\/overlay\u672c\u8eab\u7684\u6307\u5411\u914d\u7f6e\u4e5f\u5728overlay\u5c42\uff0c\u6240\u4ee5\u53ef\u4ee5\u65b0\u5efa\u4e00\u4e2a\u66f4\u5927\u7684\u5206\u533a\uff0c\u7136\u540e\u628aoverlay\u6307\u5411\u8fd9\u4e2a\u65b0\u5206\u533a\uff0c\u5c31\u76f8\u5f53\u4e8e\u628aoverlay\u6269\u5bb9\u4e86\u3002\u8fd9\u4e2a\u53ef\u80fd\u6709\u70b9\u7ed5\u3002<\/p>\n \u5176\u5b9e\u8fd8\u6709\u4e00\u4e9b\u67e5\u770b\u6302\u8f7d\u70b9\u7684\u547d\u4ee4\uff1a\u6bd4\u5982df\uff0cmount -l\uff0c\u67e5\u770b\/etc\/mtab\u6587\u4ef6\u5185\u5bb9\uff0c\u540e\u4e24\u8005\u662f\u7ed3\u679c\u662f\u4e00\u6837\u3002<\/p>\n \u9996\u5148lsblk\u662f\u5217\u51fablock\uff0c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n \u8fd9\u662f\u4e00\u4e2aU\u76d8\u505a\u7684\u8f6f\u8def\u7531\uff0c\u53ea\u67094G\u3002\u4f46\u53ef\u4ee5\u5206\u51fa\u5176\u4ed6\u51e0\u4e2a\u533a\u3002\u4e00\u4e2a\u7528\u6765\u6269\u5bb9overlay\uff0c\u5269\u4e0b\u5f53swap\uff0c\u51c6\u5907\u5b89\u88c5transmission\u548cdocker\u3001samba\u3002\u6302\u8f7d\u4e00\u4e2a\u786c\u76d8\u505a\u7f51\u7edc\u5171\u4eab\u3002<\/p>\n \u589e\u52a0\u5206\u533a\uff1afdisk\u547d\u4ee4\u3002\u8fd9\u4e2a\u547d\u4ee4\u9700\u8981\u53c2\u6570\uff0c\u662f\u4e00\u4e2a\u786c\u76d8\u8bbe\u5907\uff0c\u6bd4\u5982\/dev\/sda\u3002\u7136\u540e\u5c31\u8fdb\u5165fdisk\u7a0b\u5e8f\u4e2d\u7684\u547d\u4ee4\uff0c\u76f4\u5230\u9000\u51fafdisk\u3002\u8fd9\u548c\u5176\u4ed6\u547d\u4ee4\u4e0d\u540c\u3002<\/p>\n <\/p>\n \u8fd9\u65f6\u5206\u533a\u5c31\u90fd\u5b8c\u6210\u4e86\uff0c\u5e76\u4e14\u5199\u5165\u5206\u533a\u8868\u4e86\u3002<\/p>\n \u7136\u540e\u5c06\u65b0\u52a0\u7684\u5206\u533a\/dev\/sda3\u548c\/dev\/sda4\u683c\u5f0f\u5316\u3002<\/p>\n \u5c06sda3\u683c\u5f0f\u5316\u4e3aext4\uff0c\u5c06sda4\u683c\u5f0f\u5316\u4e3aswap\uff0c\u5e76\u6253\u5f00swap\u3002<\/p>\n \u91cd\u542freboot\u3002<\/p>\n \u4e0b\u4e00\u6b65\u9700\u8981\u5c06\/overlay\u4e2d\u5185\u5bb9\u62f7\u8d1d\u5230sda3\u4e2d\u3002\u4f46\u4e0d\u80fd\u76f4\u63a5\u7528\/dev\/sda3\u6765\u62f7\u8d1d\uff0c\u8fd9\u53ea\u662f\u4e00\u4e2a\u786c\u76d8\u8bbe\u5907\u6587\u4ef6\uff0c\u4e0d\u662f\u6587\u4ef6\u7cfb\u7edf\u3002\u6240\u4ee5\u9700\u8981\u5c06\u5176\u6302\u8f7d\u5230\u67d0\u4e2a\u76ee\u5f55\u4e0b\u9762\uff0c\u901a\u5e38\u6302\u8f7d\u7684\u65f6\u5019\u4f1a\u8981\u6c42\u6807\u8bc6\u6587\u4ef6\u7cfb\u7edf\uff0c\u8fd9\u6837\u628a\u4e00\u4e2a\u8bbe\u5907\u6302\u8f7d\u5728\u6587\u4ef6\u7cfb\u7edf\u4e0b\u9762\uff0c\u540c\u65f6\u6807\u8bc6\u4e86\u8be5\u6587\u4ef6\u7cfb\u7edf\uff0c\u8fd9\u6837\u6574\u4e2a\u7cfb\u7edf\u5c31\u80fd\u770b\u5230\u91cc\u9762\u7684\u6587\u4ef6\u4e86\u3002<\/p>\n \/dev\/sda3\u6302\u8f7d\u5230\u4e00\u4e2a\u76ee\u5f55\uff0c\u4e4b\u524d\u53ef\u4ee5df -h\u547d\u4ee4\u67e5\u770b\u4e00\u4e0b\uff0c\u539f\u6765\u90fd\u6302\u8f7d\u5728\u4ec0\u4e48\u5730\u65b9\u3002\u770b\u5230\u539f\u6765\u90fd\u5728\/mnt\u4e0b\u9762\u3002<\/p>\n mount -t ext4 \/dev\/sda3 \/mnt\/sda3<\/p>\n \u5982\u679c\u6ca1\u6709\/mnt\/sda3\uff0c\u53ef\u4ee5\u4f7f\u7528mkdir \/mnt\/sda3\u521b\u5efa\u3002<\/p>\n \u7136\u540e\u770b\u770bloop0\u6307\u5411\u7684\u662f\u54ea\u4e2a\u76ee\u5f55\uff0c\u53d1\u73b0overlay\u5728rom\u4e2d\uff0c<\/p>\n \u7136\u540e\u628aoverlay\u7684\u5185\u5bb9\u5168\u90e8\u62f7\u8d1d\u5230sda3<\/p>\n \u7136\u540eumount \/dev\/sda3 \u3002\u518d\u7528df -h\u770b\u770b\u6302\u8f7d\u70b9\uff0c\u5c31\u6ca1\u6709\/mnt\/sda3<\/p>\n \u9000\u51fashell\u3002\u6765\u5230\u8def\u7531\u5668web\u754c\u9762\uff1a\u3010\u7cfb\u7edf\u3011-\u3010\u6302\u8f7d\u70b9\u3011-\u3010\u6dfb\u52a0\u3011\u8fdb\u5165\u4e0b\u9762\u754c\u9762\u3002\u9009\u62e91G\u7684\u90a3\u5757\u76d8\uff0c\u6302\u8f7d\u6210overlay\u3002\u8fd9\u5c31\u6269\u5bb9\u4e86\u3002<\/p>\n <\/a> <\/a><\/p>\n","protected":false},"excerpt":{"rendered":" \u4ec0\u4e48\u662foverlay Squashfs\uff08.sfs\uff09\u662f\u4e00\u5957\u4f9bLinux\u6838\u5fc3\u4f7f\u7528\u7684GPL\u5f00\u6e90\u53ea\u8bfb\u538b\u7f29\u6587\u4ef6\u7cfb\u7edf\u3002Squashfs\u80fd\u591f\u4e3a\u6587\u4ef6\u7cfb\u7edf\u5185\u7684\u6587\u4ef6\u3001inode\u53ca\u76ee\u5f55\u7ed3\u6784\u8fdb\u884c\u538b\u7f29\u3002 S\u2026<\/p>\n","protected":false},"author":5710,"featured_media":5896,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1416,1415,66],"attr":[],"class_list":["post-5895","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruanluyou","tag-openwrtswap","tag-openwrt","tag-66","entry"],"views":7394,"_links":{"self":[{"href":"http:\/\/jc.a300.cn/luyouwang\/wp-json\/wp\/v2\/posts\/5895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/jc.a300.cn/luyouwang\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/jc.a300.cn/luyouwang\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/jc.a300.cn/luyouwang\/wp-json\/wp\/v2\/users\/5710"}],"replies":[{"embeddable":true,"href":"http:\/\/jc.a300.cn/luyouwang\/wp-json\/wp\/v2\/comments?post=5895"}],"version-history":[{"count":0,"href":"http:\/\/jc.a300.cn/luyouwang\/wp-json\/wp\/v2\/posts\/5895\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/jc.a300.cn/luyouwang\/wp-json\/wp\/v2\/media\/5896"}],"wp:attachment":[{"href":"http:\/\/jc.a300.cn/luyouwang\/wp-json\/wp\/v2\/media?parent=5895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/jc.a300.cn/luyouwang\/wp-json\/wp\/v2\/categories?post=5895"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/jc.a300.cn/luyouwang\/wp-json\/wp\/v2\/tags?post=5895"},{"taxonomy":"attr","embeddable":true,"href":"http:\/\/jc.a300.cn/luyouwang\/wp-json\/wp\/v2\/attr?post=5895"}],"curies":[{"name":"wp","href":"http:\/\/api.w.org\/{rel}","templated":true}]}}\u547d\u4ee4\u884c\u5de5\u5177<\/h2>\n
\n
root@OpenWrt:~# lsblk\r\nNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT\r\nloop0 7:0 0 41.8M 0 loop \/mnt\/loop0\r\nsda 8:0 1 3.8G 0 disk\r\n\u251c\u2500sda1 8:1 1 16M 0 part \/mnt\/sda1\r\n\u2514\u2500sda2 8:2 1 160M 0 part \/rom<\/pre>\n
root@OpenWrt:~# fdisk \/dev\/sda\r\n\r\nWelcome to fdisk (util-linux 2.33).\r\nChanges will remain in memory only, until you decide to write them.\r\nBe careful before using the write command.\r\n\r\nCommand (m for help): m\r\n\r\nHelp:\r\n\r\n DOS (MBR)\r\n a toggle a bootable flag\r\n b edit nested BSD disklabel\r\n c toggle the dos compatibility flag\r\n\r\n Generic\r\n d delete a partition\r\n F list free unpartitioned space\r\n l list known partition types\r\n n add a new partition\r\n p print the partition table\r\n t change a partition type\r\n v verify the partition table\r\n i print information about a partition\r\n\r\n Misc\r\n m print this menu\r\n u change display\/entry units\r\n x extra functionality (experts only)\r\n\r\n Script\r\n I load disk layout from sfdisk script file\r\n O dump disk layout to sfdisk script file\r\n\r\n Save & Exit\r\n w write table to disk and exit\r\n q quit without saving changes\r\n\r\n Create a new label\r\n g create a new empty GPT partition table\r\n G create a new empty SGI (IRIX) partition table\r\n o create a new empty DOS partition table\r\n s create a new empty Sun partition table<\/pre>\n
Command (m for help): p\r\nDisk \/dev\/sda: 3.8 GiB, 4026531840 bytes, 7864320 sectors\r\nDisk model: ProductCode\r\nUnits: sectors of 1 * 512 = 512 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisklabel type: dos\r\nDisk identifier: 0xd56b2d42\r\n\r\nDevice Boot Start End Sectors Size Id Type\r\n\/dev\/sda1 * 512 33279 32768 16M 83 Linux\r\n\/dev\/sda2 33792 361471 327680 160M 83 Linux\r\n\r\nCommand (m for help): n\r\nPartition type\r\n p primary (2 primary, 0 extended, 2 free)\r\n e extended (container for logical partitions)\r\nSelect (default p): 2\r\nValue out of range.\r\n p primary (2 primary, 0 extended, 2 free)\r\n e extended (container for logical partitions)\r\nSelect (default p): p\r\nPartition number (3,4, default 3): 3\r\nFirst sector (33280-7864319, default 362496):\r\nLast sector, +\/-sectors or +\/-size{K,M,G,T,P} (362496-7864319, default 7864319): +1G\r\n\r\nCreated a new partition 3 of type 'Linux' and of size 1 GiB.\r\n\r\nCommand (m for help): p\r\nDisk \/dev\/sda: 3.8 GiB, 4026531840 bytes, 7864320 sectors\r\nDisk model: ProductCode\r\nUnits: sectors of 1 * 512 = 512 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisklabel type: dos\r\nDisk identifier: 0xd56b2d42\r\n\r\nDevice Boot Start End Sectors Size Id Type\r\n\/dev\/sda1 * 512 33279 32768 16M 83 Linux\r\n\/dev\/sda2 33792 361471 327680 160M 83 Linux\r\n\/dev\/sda3 362496 2459647 2097152 1G 83 Linux\r\n\r\nCommand (m for help): n\r\nPartition type\r\n p primary (3 primary, 0 extended, 1 free)\r\n e extended (container for logical partitions)\r\nSelect (default e): p\r\n\r\nSelected partition 4\r\nFirst sector (33280-7864319, default 2459648):\r\nLast sector, +\/-sectors or +\/-size{K,M,G,T,P} (2459648-7864319, default 7864319):\r\n\r\nCreated a new partition 4 of type 'Linux' and of size 2.6 GiB.\r\n\r\nCommand (m for help): p\r\nDisk \/dev\/sda: 3.8 GiB, 4026531840 bytes, 7864320 sectors\r\nDisk model: ProductCode\r\nUnits: sectors of 1 * 512 = 512 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisklabel type: dos\r\nDisk identifier: 0xd56b2d42\r\n\r\nDevice Boot Start End Sectors Size Id Type\r\n\/dev\/sda1 * 512 33279 32768 16M 83 Linux\r\n\/dev\/sda2 33792 361471 327680 160M 83 Linux\r\n\/dev\/sda3 362496 2459647 2097152 1G 83 Linux\r\n\/dev\/sda4 2459648 7864319 5404672 2.6G 83 Linux\r\n\r\nCommand (m for help): w\r\nThe partition table has been altered.\r\nSyncing disks.<\/pre>\n
root@OpenWrt:~# mkfs.ext4 \/dev\/sda3\r\nmke2fs 1.44.3 (10-July-2018)\r\nCreating filesystem with 262144 4k blocks and 65536 inodes\r\nFilesystem UUID: 13105391-0ee0-43e9-b6d9-c2d75053b951\r\nSuperblock backups stored on blocks:\r\n 32768, 98304, 163840, 229376\r\n\r\nAllocating group tables: done\r\nWriting inode tables: done\r\nCreating journal (8192 blocks): done\r\nWriting superblocks and filesystem accounting information: done\r\n\r\nroot@OpenWrt:~# mkswap \/dev\/sda4\r\nSetting up swapspace version 1, size = 2767187968 bytes\r\nroot@OpenWrt:~# swapon \/dev\/sda4<\/pre>\n
root@OpenWrt:\/# df -h\r\nFilesystem Size Used Available Use% Mounted on\r\n\/dev\/root 118.3M 118.3M 0 100% \/rom\r\ntmpfs 487.3M 1.9M 485.4M 0% \/tmp\r\n\/dev\/loop0 36.4M 1.9M 31.6M 6% \/rom\/overlay\r\noverlayfs:\/overlay 36.4M 1.9M 31.6M 6% \/\r\n\/dev\/sda1 15.7M 3.7M 11.7M 24% \/boot\r\n\/dev\/sda1 15.7M 3.7M 11.7M 24% \/boot\r\ntmpfs 512.0K 0 512.0K 0% \/dev\r\ncgroup 487.3M 0 487.3M 0% \/sys\/fs\/cgroup\r\noverlayfs:\/overlay 36.4M 1.9M 31.6M 6% \/opt\/docker\r\n\/dev\/loop0 36.4M 1.9M 31.6M 6% \/mnt\/loop0\r\n\/dev\/sda1 15.7M 3.7M 11.7M 24% \/mnt\/sda1\r\n\/dev\/sda3 975.9M 2.5M 906.2M 0% \/mnt\/sda3<\/pre>\n
root@OpenWrt:\/rom\/overlay# cp -r \/rom\/overlay\/* \/mnt\/sda3\r\n<\/pre>\n