banner
miaoer

miaoer

喵二の小博客 xLog 分站
tg_channel
telegram

Not enough space for the software router? Expand the root of the overlay.

Previously, I shared the method of expanding the overlay by copying the original /overlay partition of OpenWrt and mounting it as an external overlay. However, in the latest OpenWrt/LEDE and CatWrt compiled based on LEDE, it is also unable to expand. Although some expansions have been successful, the success rate is not high. This time, I will share the first method summarized in the video of Bilibili UP master Hanfeng Talk. The success rate is relatively high because I did not successfully refresh the capacity in the firmware for the second method, so I gave up.

First of all, I would like to thank Hanfeng for providing the method. If you need it, you can check out his video. Here, I will summarize it.

In the v22.11 firmware, there is 100M of available space. It is strongly recommended not to choose OpenWrt as an option for installation for beginners! It has a learning curve and data is priceless. If necessary, you can back up before proceeding, or you can create a snapshot for the virtual machine.




For those who used to rely on external overlays, you can refer to my blog post on OpenWrt overlay partition expansion tutorial.


Preparation#

First, open the terminal and SSH connect to the router. Here, I use CatWrt EFI boot firmware with ttyd.

First, check the partition situation of the router with fdisk -l.

root@CatWrt:~# fdisk -l
Disk /dev/loop0: 184.88 MiB, 193855488 bytes, 378624 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
GPT PMBR size mismatch (852511 != 7129087) will be corrected by write.


Disk /dev/sda: 3.4 GiB, 3650093056 bytes, 7129088 sectors
Disk model: VMware Virtual I
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 0EAC8D5A-F014-DB49-E8EB-FA846A473B00

Device      Start    End Sectors  Size Type
/dev/sda1     512  33279   32768   16M Linux filesystem
/dev/sda2   33280 852479  819200  400M Linux filesystem
/dev/sda128    34    511     478  239K BIOS boot

Partition table entries are not in disk order.

You can see that the EFI version of the firmware has an additional 239k /dev/sda128 compared to the traditional mode, but the ending sector is still at 819200. Remember this ending sector, as many details will revolve around this ending point!

Next, we will proceed with the partitioning work. First, you need to know if your firmware needs to be upgraded. In CatWrt, we strongly recommend reserving 200M of free space. This space needs to be reserved after /dev/sda2.

First, enter the partition management tool and enter fdisk /dev/sda.

Note that the sectors cannot be duplicated!

Then enter n to create a new partition.

root@CatWrt:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.38).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

GPT PMBR size mismatch (852511 != 7129087) will be corrected by write.
This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.


Command (m for help): _

Here, we are asked to choose between primary partition and extended partition. We choose primary and enter p (I didn't encounter this, not everyone has it).

Select (default p): _

Here, we are asked to choose a partition. Since this OpenWrt has not undergone any partitioning operations, we choose 3.

Partition number (3-127, default 3): _

Here, we are asked to give the /dev/sda3 partition a starting sector. Here, according to future upgrade needs, we add 409600 to the ending sector of the /dev/sda2 partition.

That is, 2048 x 200, which is 200M partition, from the ending point (≈852479) 860000 to 1269600, reserved for upgrades, so we start partitioning from sector 1270000.

Enter 1270000 here.

First sector (852480-7129054, default 854016): _

For the ending sector of the new partition, we can directly use our familiar g unit here. It is recommended to start with +2g.

Last sector, +/-sectors or +/-size{K,M,G,T,P} (1270000-7129054, default 7127039): +2g

Enter w to save the changes.

Created a new partition 3 of type 'Linux filesystem' and of size 2 GiB.

Command (m for help): w
The partition table has been altered.
Syncing disks.

root@CatWrt:~# 

This completes the creation. You can check if the partition was successful with fdisk -l.

root@CatWrt:~# fdisk -l
Disk /dev/loop0: 184.88 MiB, 193855488 bytes, 378624 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 3.4 GiB, 3650093056 bytes, 7129088 sectors
Disk model: VMware Virtual I
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 0EAC8D5A-F014-DB49-E8EB-FA846A473B00

Device        Start     End Sectors  Size Type
/dev/sda1       512   33279   32768   16M Linux filesystem
/dev/sda2     33280  852479  819200  400M Linux filesystem
/dev/sda3   1270000 5464063 4194064    2G Linux filesystem
/dev/sda128      34     511     478  239K BIOS boot

Partition table entries are not in disk order.

Formatting#

At this point, the partitioning work is completed, but it still needs to be formatted as ext4. Enter mkfs.ext4 /dev/sda3 and press Enter.

root@CatWrt:~# mkfs.ext4 /dev/sda3
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 524258 4k blocks and 131072 inodes
Filesystem UUID: ff7a2c4a-fd56-42ad-a9ac-45ade1c5819a
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done 

Mounting#

This completes the formatting. Next, go to the LuCi web interface and proceed with the following steps. Go to System - Mount Points and click on Add at the Mount Points section.

For the UUID, select the newly created partition. In my case, it is ff7a2c4a-fd56-42ad-a9ac-45ade1c5819a (/dev/sda3, 2047 MB).

For the Mount Point, select Use as Root Filesystem (/).

Check the box for Enable this mount point.

image

When we clicked on Use as Root Filesystem, a pop-up with a series of commands appeared in the Prepare Root Directory section. This is not a problem. We need to modify these commands slightly to copy the root file to the mount point.

I have already made the modifications. If you compare them, you will see that I only changed sda1 to sda3 in the example. Just open the terminal and enter these commands.

mkdir -p /tmp/introot
mkdir -p /tmp/extroot
mount --bind / /tmp/introot
mount /dev/sda3 /tmp/extroot
tar -C /tmp/introot -cvf - . | tar -C /tmp/extroot -xf -
umount /tmp/introot
umount /tmp/extroot
reboot

The last command is to restart. Press Enter manually. If you encounter something different from mine near the end, such as (find something) or other different text, please make sure you have not skipped any steps or have firmware issues.

If you follow this article, you will definitely be able to successfully expand the capacity.

……
./www/uuandriod.png
./www/uuios.png
./boot/
./home/
./home/ftp/
./run/
./run/docker/
./run/docker/plugins/
./run/mount/
./run/blkid/
./run/blkid/blkid.tab
./run/blkid/blkid.tab.old
root@CatWrt:~# umount /tmp/introot
root@CatWrt:~# umount /tmp/extroot
root@CatWrt:~# reboot

After the restart, the easiest way to check if the expansion was successful is to check if there is any extra space in the package. Open System - Software Packages and you will see that the expansion was successful. If you have not successfully expanded, it is recommended to delete sda3 and reset the OpenWrt configuration.

image


Docker#

Regarding Docker partitioning, I won't go into too much detail here. You can combine the above content and refer to the previous blog post on expanding the overlay. Here, you can also use fdisk for the operation instead of cfdisk.

Enter fdisk /dev/sda.

Create a new partition with n.

Choose between primary and extended partition. We choose primary and enter p (I didn't encounter this, not everyone has it).

Select (default p): _

Choose a partition. Here, we choose 4.

Since the expansion (/dev/sda3) has an ending sector of 5464063, we set the starting sector to 5466000 and press Enter.

Next, enter how much space you want to allocate for the Docker partition. Here, we choose +10g.

Enter w to save the changes.

Enter mkfs.ext4 /dev/sda4 to format the Docker partition (/dev/sda4).

Go to System - Mount Points and add the newly created partition /dev/sda4.

For the Mount Point, select Use as Docker Data Partition (/opt).

Check the box for Enable this mount point.

Save and apply. It is recommended to restart to see that the Docker partition has been successfully expanded.

This article is synchronized and updated to xLog by Mix Space.
The original link is https://www.miaoer.xyz/posts/network/expansion-overlay


Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.