The openwrt router mounts the sdcard as overlay

Raw material: openwrt router (Newifi 2, pole router 1s is also possible)

This machine comes with a Micro SD slot, which has not been used much after flashing OpenWrt. Toss about freely and mount the Micro SD card to the /overlay partition to increase the available internal space.

To use the Micro SD card slot first, you need to install the following two kernel modules:

opkg install kmod-sdhci kmod-sdhci-mt7620

Next, you should see a file of mmcblk0 under /dev, which is our Micro SD.

Then install some file system-related software packages.

opkg install block-mount kmod-fs-ext4 e2fsprogs fdisk

block info//查看sdcard信息

Format sdcard as ext4 file format:

mkfs.ext4 /dev/mmcblk0p1

Next, transfer the existing files to the SD card. If you don't know the meaning of / directory and /overlay directory in OpenWrt, you can read the following.

mount /dev/mmcblk0p1 /mnt ; tar -C /overlay -cvf - . | tar -C /mnt -xf - ; umount /mnt

Next, create the mount configuration of mmcblk0p1 (make sure the restart mount directory is still there), and you can use the following commands for automatic

block detect > /etc/config/fstab; \
   sed -i s/option$'\t'enabled$'\t'\'0\'/option$'\t'enabled$'\t'\'1\'/ /etc/config/fstab; \
   sed -i s#/mnt/mmcblk0p1#/overlay# /etc/config/fstab; \
   cat /etc/config/fstab;

Mount mmcblk0p1 to /overlay:

mount /dev/mmcblk0p1 /overlay

View hanging information:


root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 2.5M      2.5M         0 100% /rom
tmpfs                    61.0M      4.6M     56.4M   8% /tmp
/dev/mmcblk0p1          975.9M     39.4M    869.3M   4% /overlay
overlayfs:/overlay      975.9M     39.4M    869.3M   4% /
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/mmcblk0p2          893.5M      2.3M    829.0M   0% /sdcard
root@OpenWrt:~#

Now you can see that the space for /overlay has increased.

At this time, you can restart your router and see if it automatically mounts successfully.

Introduction to over

What does /overlay mean?

The file system commonly used by OpenWRT is SquashFS. The feature of this file system is read-only.

So, how does a read-only file system save settings and install software?

Here is to use a /overlay partition, overlay, as the name implies, means to cover the upper layer.

Although the original file cannot be modified, we put the modified part on the overlay partition and map it to the original location. When reading, we can read the modified file.

But why use such a complicated method? Of course, OpenWRT can also use the EXT4 file system, but using SquashFS + overlay has certain advantages.

First of all, SquashFS is compressed, so you can put more things in a small ROM device such as a router.

Then OpenWRT's factory resetting also depends on this method. When you poke Reset, it only needs to clear the overlay partition, and everything is back to the way it was just brushed in.

If it is an EXT4 file system, it can only back up each modified file and copy it back when restoring the factory settings, which is very complicated.

Of course, SquashFS + overlay also has its shortcomings, it will take up more space when modifying files.

First of all, you cannot delete the file, because deleting a file actually writes a delete mark in the overlay partition, which instead takes up more space.

In addition, when modifying the file, it is equivalent to adding a copy of the file, which takes up double space.

Guess you like

Origin blog.csdn.net/sun172270102/article/details/108181858