OpenWrt扩容overlay并开启swap的教程

192.168.1.1214文章10评论2020-10-12 12:20:521 字数 5178阅读17分15秒什么是overlaySquashfs(.sfs)是一套供Linux核心使用的GPL开源只读压缩文件系统 。Squashfs能够为文件系统内的文件、inode及目录结构进行压缩 。
Squashfs的设计是专门为一般的只读文件系统的使用而设计,它可应用于数据备份,或是系统资源紧张的电脑上使用 。
OpenWRT 一般使用的文件系统是 SquashFS ,建议下载固件的时候也下载这种固件 。这个文件系统的特点就是:只读、压缩 。
一个只读的文件系统,是怎么做到保存设置和安装软件的呢?用/overlay分区 。固件中已经写入了有个/overlay分区,但它的指向可以更改 。
虽然原来的文件不能修改,但我们把修改的部分放在 overlay 分区上,然后映射到原来的位置,读取的时候就可以读到我们修改过的文件了 。当系统故障,reset的时候,把固件中配置文件拷贝到overlay层,就恢复到最初设置了 。
由于/overlay本身的指向配置也在overlay层,所以可以新建一个更大的分区,然后把overlay指向这个新分区,就相称于把overlay扩容了 。这个可能有点绕 。
命令行工具lsblkblkidfdiskmkswapswapon其实还有一些查看挂载点的命令:比如df,mount -l,查看/etc/mtab文件内容,后两者是结果是一样 。
首先lsblk是列出block,结果如下:
[emailprotected]:~# lsblkNAMEMAJ:MIN RMSIZE RO TYPE MOUNTPOINTloop07:00 41.8M0 loop /mnt/loop0sda8:013.8G0 disk├─sda18:1116M0 part /mnt/sda1└─sda28:21160M0 part /rom这是一个U盘做的软路由,只有4G 。但可以分出其他几个区 。一个用来扩容overlay,剩下当swap,预备安装transmission和docker、samba 。挂载一个硬盘做网络共享 。
增加分区:fdisk命令 。这个命令需要参数,是一个硬盘设备,比如/dev/sda 。然后就进入fdisk程序中的命令,直到退出fdisk 。这和其他命令不同 。
[emailprotected]:~#fdisk /dev/sdaWelcome to fdisk (util-linux 2.33).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Command (m for help): mHelp:DOS (MBR)atoggle a bootable flagbedit nested BSD disklabelctoggle the dos compatibility flagGenericddelete a partitionFlist free unpartitioned spacellist known partition typesnadd a new partitionpprint the partition tabletchange a partition typevverify the partition tableiprint information about a partitionMiscmprint this menuuchange display/entry unitsxextra functionality (experts only)ScriptIload disk layout from sfdisk script fileOdump disk layout to sfdisk script fileSaveExitwwrite table to disk and exitqquit without saving changesCreate a new labelgcreate a new empty GPT partition tableGcreate a new empty SGI (IRIX) partition tableocreate a new empty DOS partition tablescreate a new empty Sun partition tableCommand (m for help): pDisk /dev/sda: 3.8 GiB, 4026531840 bytes, 7864320 sectorsDisk model: ProductCodeUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xd56b2d42DeviceBoot StartEnd SectorsSize Id Type/dev/sda1*512332793276816M 83 Linux/dev/sda233792 361471327680160M 83 LinuxCommand (m for help): nPartition typepprimary (2 primary, 0 extended, 2 free)eextended (container for logical partitions)Select (default p): 2Value out of range.pprimary (2 primary, 0 extended, 2 free)eextended (container for logical partitions)Select (default p): pPartition number (3,4, default 3): 3First sector (33280-7864319, default 362496):Last sector, +/-sectors or +/-size{K,M,G,T,P} (362496-7864319, default 7864319): +1GCreated a new partition 3 of type 'Linux' and of size 1 GiB.Command (m for help): pDisk /dev/sda: 3.8 GiB, 4026531840 bytes, 7864320 sectorsDisk model: ProductCodeUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xd56b2d42DeviceBootStartEnd SectorsSize Id Type/dev/sda1*512332793276816M 83 Linux/dev/sda233792361471327680160M 83 Linux/dev/sda3362496 2459647 20971521G 83 LinuxCommand (m for help): nPartition typepprimary (3 primary, 0 extended, 1 free)eextended (container for logical partitions)Select (default e): pSelected partition 4First sector (33280-7864319, default 2459648):Last sector, +/-sectors or +/-size{K,M,G,T,P} (2459648-7864319, default 7864319):Created a new partition 4 of type 'Linux' and of size 2.6 GiB.Command (m for help): pDisk /dev/sda: 3.8 GiB, 4026531840 bytes, 7864320 sectorsDisk model: ProductCodeUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xd56b2d42DeviceBootStartEnd SectorsSize Id Type/dev/sda1*512332793276816M 83 Linux/dev/sda233792361471327680160M 83 Linux/dev/sda3362496 2459647 20971521G 83 Linux/dev/sda42459648 7864319 54046722.6G 83 LinuxCommand (m for help): wThe partition table has been altered.Syncing disks.这时分区就都完成了,并且写入分区表了 。