Resizing the hidden overlay filesystem when it is ext4 and not f2fs

The hidden writable filesystem on my R4S squashfs image is ext4 instead of f2fs.

My first ever attempt at expanding the hidden file system for a writable overlay failed on 22.03.2 squashfs image for my R4S.
(The R4S uses an SD card for storage so there is typically extra space to expand into.)

All the directions I found for expanding the overlay filesystem on a squashfs image were for f2fs.

It looks like this one is a hybrid setup with ext4 overlay on the squashfs image.

I found a working solution. Simply use the ext4 resizing process on the loop mount.
I did the following one line at a time after having the fsck.f2fs -f ${LOOP} command fail.

This is done on the live router running OpenWrt after first boot.

opkg update
opkg install losetup e2fsprogs resize2fs 
LOOP="$(losetup -n -O NAME | sort | sed -n -e "1p")"
ROOT="$(losetup -n -O BACK-FILE ${LOOP} | sed -e "s|^|/dev|")"
OFFS="$(losetup -n -O OFFSET ${LOOP})"
LOOP="$(losetup -f)"
losetup -o ${OFFS} ${LOOP} ${ROOT}
e2fsck -f ${LOOP}
mount ${LOOP} /mnt
umount ${LOOP}
resize2fs ${LOOP}
reboot

I did not do this all in one pass from a clean installation yet so I'm not 100% that it is
good to use.

Values for variables set in above command list:

root@R4S-wrt:~# echo ${OFFS} ${LOOP} ${ROOT}
9043968 /dev/loop1 /dev/mmcblk1p2

I adapted the process for f2fs:

and ext4:

My Resizing session log after having fsck.f2fs -f ${LOOP} fail and some required programs were already installed:

root@R4S-wrt:~# LOOP="$(losetup -n -O NAME | sort | sed -n -e "1p")"
root@R4S-wrt:~# ROOT="$(losetup -n -O BACK-FILE ${LOOP} | sed -e "s|^|/dev|")"
root@R4S-wrt:~# OFFS="$(losetup -n -O OFFSET ${LOOP})"
root@R4S-wrt:~# LOOP="$(losetup -f)"
root@R4S-wrt:~# losetup -o ${OFFS} ${LOOP} ${ROOT}
root@R4S-wrt:~# fsck.ext4 -f ${LOOP}
e2fsck 1.46.5 (30-Dec-2021)
rootfs_data: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
/lost+found not found.  Create<y>? yes
Pass 4: Checking reference counts
Pass 5: Checking group summary information

rootfs_data: ***** FILE SYSTEM WAS MODIFIED *****
rootfs_data: 376/24384 files (0.3% non-contiguous), 14666/97664 blocks
root@R4S-wrt:~# mount ${LOOP} /mnt
root@R4S-wrt:~# umount ${LOOP}
root@R4S-wrt:~# resize2fs ${LOOP}
resize2fs 1.46.5 (30-Dec-2021)
Please run 'e2fsck -f /dev/loop1' first.

root@R4S-wrt:~# e2fsck -f /dev/loop1
e2fsck 1.46.5 (30-Dec-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
rootfs_data: 381/24384 files (0.3% non-contiguous), 14721/97664 blocks
root@R4S-wrt:~# resize2fs ${LOOP}
resize2fs 1.46.5 (30-Dec-2021)
Resizing the filesystem on /dev/loop1 to 4185472 (1k) blocks.
The filesystem on /dev/loop1 is now 4185472 (1k) blocks long.

root@R4S-wrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 8.8M      8.8M         0 100% /rom
tmpfs                     1.9G    996.0K      1.9G   0% /tmp
/dev/loop0               83.9M      2.9M     74.3M   4% /overlay
overlayfs:/overlay       83.9M      2.9M     74.3M   4% /
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/sda1                 9.4G     11.6M      9.4G   0% /mnt/usb-flsh-p1
root@R4S-wrt:~# reboot
root@R4S-wrt:~# Connection to 192.168.3.1 closed by remote host.
Connection to 192.168.3.1 closed.
$ ssh root@192.168.3.1
root@192.168.3.1's password: 


BusyBox v1.35.0 (2022-10-18 18:13:41 UTC) built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt 22.03.2, r19803-9a599fee93
 -----------------------------------------------------
root@R4S-wrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 8.8M      8.8M         0 100% /rom
tmpfs                     1.9G     96.0K      1.9G   0% /tmp
/dev/loop0                3.7G      2.9M      3.5G   0% /overlay
overlayfs:/overlay        3.7G      2.9M      3.5G   0% /
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/sda1                 9.4G     11.6M      9.4G   0% /mnt/usb-flsh-p1
root@R4S-wrt:~# 

Note that fsck.ext4 is just a link to e2fsck:

root@R4S-wrt:~# ls -l /usr/sbin/fsck.ext4
lrwxrwxrwx    1 root     root             6 Oct 14 18:44 /usr/sbin/fsck.ext4 -> e2fsck

My NanoPi R4S 22.03.2 squashfs image was created by adding several packages on the firmware selector and letting it generate a custom build.
https://firmware-selector.openwrt.org/?version=22.03.2&target=rockchip%2Farmv8&id=friendlyarm_nanopi-r4s

Relevant filesystems:
root@R4S-wrt:~# mount

/dev/root on /rom type squashfs (ro,relatime)
...
/dev/loop0 on /overlay type ext4 (rw,noatime)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)

Original filesystem sizes before resizing:
root@R4S-wrt:~# df -h

Filesystem                Size      Used Available Use% Mounted on
/dev/root                 8.8M      8.8M         0 100% /rom
tmpfs                     1.9G    100.0K      1.9G   0% /tmp
/dev/loop0               83.9M      2.8M     74.4M   4% /overlay
overlayfs:/overlay       83.9M      2.8M     74.4M   4% /
tmpfs                   512.0K         0    512.0K   0% /dev

Filesystem sizes after resizing:
root@R4S-wrt:~# df -h

Filesystem                Size      Used Available Use% Mounted on
/dev/root                 8.8M      8.8M         0 100% /rom
tmpfs                     1.9G    100.0K      1.9G   0% /tmp
/dev/loop0                3.7G      2.9M      3.5G   0% /overlay
overlayfs:/overlay        3.7G      2.9M      3.5G   0% /
tmpfs                   512.0K         0    512.0K   0% /dev

Original partition info before resizing:
root@OpenWrt:~# fdisk -l /dev/mmcblk1

Disk /dev/mmcblk1: 58.94 GiB, 63281561600 bytes, 123596800 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
Disklabel type: dos
Disk identifier: 0x5452574f

Device         Boot  Start    End Sectors  Size Id Type
/dev/mmcblk1p1 *     65536  98303   32768   16M 83 Linux
/dev/mmcblk1p2      131072 344063  212992  104M 83 Linux

Partition info after resizing:
root@R4S-wrt:~# fdisk -l /dev/mmcblk1

Disk /dev/mmcblk1: 58.94 GiB, 63281561600 bytes, 123596800 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
Disklabel type: dos
Disk identifier: 0x5452574f

Device         Boot  Start     End Sectors Size Id Type
/dev/mmcblk1p1 *     65536   98303   32768  16M 83 Linux
/dev/mmcblk1p2      131072 8519679 8388608   4G 83 Linux

I hope this helps someone else!

1 Like

How does one find out if their R4S squashfs has ext4?

Edit:

opkg install lsblk losetup
lsblk -o +FSTYPE,UUID; losetup -l
root@OpenWrt:~# lsblk -o +FSTYPE; losetup -l
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS FSTYPE
loop0         7:0    0 14.8G  0 loop /overlay    f2fs
mmcblk1     179:0    0 14.8G  0 disk             
├─mmcblk1p1 179:1    0   16M  0 part             ext4
└─mmcblk1p2 179:2    0 14.8G  0 part /rom        squashfs
NAME       SIZELIMIT  OFFSET AUTOCLEAR RO BACK-FILE  DIO LOG-SEC
/dev/loop0         0 3538944         1  0 /mmcblk1p2   0     512

I think mine is f2fs.

Yes, it looks like your overlayfs is type f2fs.

A slightly easier version of the lsblk command to see that info is lsblk -f .
I think blkid is already installed as is mount and they both show the filesystem types without installing a new package to see the filesystem types. I do like lsblk though.

It looks like the OpenWrt wiki documentation that I referred to has changed.
I suspect that the git repository that you linked in the other thread has what should be the exact steps you need ( I don't have an R2S ). Be sure to enter the commands one line at a time and wait for the prompt to come back before entering the next command. It may matter for one or more commands.
.

Good Luck!

1 Like

thanks for the tip and the link :slight_smile:
Will try with the spare R4s (just received) .
If didn't work out at the end, another route for me would be to put as much as I can with the firmware selector bot, then create an extra ext4 partition on my sd card and mount that.

Needed!!

1 Like

On the R4S, hopefully one of the scripted processes will work.
Mine for overlay filesystem type ext4, or Anaelorlinski's script for type f2fs. They only differ in the fsck and resize commands based of matching the filesystem type.

Also, it may be a good idea to reboot again before expanding the overlay filesystem, after firstboot and setting address, password etc.

I think it has been stated that the overlay filesystem gets setup on firstboot along with the default settings etc. A reboot before expanding the overlay may put everything in a "normal" state if it isn't on the firstboot.

EDIT: Fixed typo fsdk -> fsck

Firmware selector bot gives me and ext4 overlay this time. :slight_smile:

root@OpenWrt:~# cfdisk /dev/mmcblk1
      - resize lower partition, my case is mmcblk1p2 
      - write, yes, quit
root@OpenWrt:~# lsblk -o +FSTYPE; losetup -l
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS FSTYPE
loop0         7:0    0 14.8G  0 loop /overlay    ext4
mmcblk1     179:0    0 14.8G  0 disk             
├─mmcblk1p1 179:1    0   16M  0 part             ext4
└─mmcblk1p2 179:2    0 14.8G  0 part /rom        squashfs
NAME       SIZELIMIT   OFFSET AUTOCLEAR RO BACK-FILE  DIO LOG-SEC
/dev/loop0         0 15138816         1  0 /mmcblk1p2   0     512
root@OpenWrt:/mnt# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                14.3M     14.3M         0 100% /rom
tmpfs                     1.9G      2.4M      1.9G   0% /tmp
/dev/loop0               78.6M      1.4M     70.9M   2% /overlay
overlayfs:/overlay       78.6M      1.4M     70.9M   2% /
tmpfs                   512.0K         0    512.0K   0% /dev

reboot
root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                14.5M     14.5M         0 100% /rom
tmpfs                     1.9G    596.0K      1.9G   0% /tmp
/dev/loop0               78.4M     59.1M     13.0M  82% /overlay
overlayfs:/overlay       78.4M     59.1M     13.0M  82% /
tmpfs                   512.0K         0    512.0K   0% /dev
root@OpenWrt:~# LOOP="$(losetup -n -O NAME | sort | sed -n -e "1p")"
root@OpenWrt:~# ROOT="$(losetup -n -O BACK-FILE ${LOOP} | sed -e "s|^|/dev|")"
root@OpenWrt:~# OFFS="$(losetup -n -O OFFSET ${LOOP})"
root@OpenWrt:~# LOOP="$(losetup -f)"
root@OpenWrt:~# echo ${OFFS} ${LOOP} ${ROOT}
15138816 /dev/loop1 /dev/mmcblk1p2
root@OpenWrt:~# losetup -o ${OFFS} ${LOOP} ${ROOT}
root@OpenWrt:~# e2fsck -f ${LOOP}
e2fsck 1.46.5 (30-Dec-2021)
rootfs_data: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
/lost+found not found.  Create<y>? yes
Pass 4: Checking reference counts
Pass 5: Checking group summary information

rootfs_data: ***** FILE SYSTEM WAS MODIFIED *****
rootfs_data: 114/22944 files (0.0% non-contiguous), 71969/91712 blocks
root@OpenWrt:~# 
root@OpenWrt:~# mount ${LOOP} /mnt
root@OpenWrt:~# umount ${LOOP}
root@OpenWrt:~# resize2fs ${LOOP}
resize2fs 1.46.5 (30-Dec-2021)
Please run 'e2fsck -f /dev/loop1' first.

root@OpenWrt:~# e2fsck -f /dev/loop1
e2fsck 1.46.5 (30-Dec-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
rootfs_data: 114/22944 files (0.0% non-contiguous), 71969/91712 blocks
root@OpenWrt:~# resize2fs ${LOOP}
resize2fs 1.46.5 (30-Dec-2021)
Resizing the filesystem on /dev/loop1 to 15477824 (1k) blocks.
The filesystem on /dev/loop1 is now 15477824 (1k) blocks long.

root@OpenWrt:~# reboot
root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                14.5M     14.5M         0 100% /rom
tmpfs                     1.9G    592.0K      1.9G   0% /tmp
/dev/loop0               13.9G     59.1M     13.1G   0% /overlay
overlayfs:/overlay       13.9G     59.1M     13.1G   0% /
tmpfs                   512.0K         0    512.0K   0% /dev

:slight_smile:

1 Like

Does the system report the correct larger file system size as well?
df -h

Ah, I see you added that.

Nice work! :slight_smile:

yea. I did it.
1st try panic after seeing " Please run 'e2fsck -f /dev/loop1' first."

Re-read your top post, realized you had that too.
Decided to reflash and redo.
2nd try managed it.

I advanced a lot today (first time using firmware selector, and that script), thanks!

1 Like

Maybe it is hit or miss with needing that. A reflash should not be needed.
At least it wasn't a "Bad super block" message.

1 Like

Not sure I've read the question completely right, but just in case the solution I'm thinking of is really simple, just use the following command to check on the file type

df -hT