Expanding OpenWrt squashfs image (SDcard)

I waited to reply in hopes that someone with direct experience would reply.
I suspect that the git repository that you linked to has a document for what should be the exact steps needed to expand the f2fs overlay on an R2S.

https://github.com/anaelorlinski/OpenWrt-NanoPi-R2S-R4S-Builds/blob/main/docs/resize-f2fs.md

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.

Be aware that the expanded filesystem gets reset with an upgrade, rest or new installation and all files added before hand disappear. You would need to back-up all files before any upgrade, reset or OpenWrt installation, redo the filesystem expansion and restore the backed-up files each time ensuring that you don't restore any packages or components that were upgraded.

If you are looking for more space to install more/bigger packages, then the "Customize installed packages" part of the OpenWrt firmware selector site may be an easy and appropriate way to get there with entering the list of added packages needed.
https://firmware-selector.openwrt.org/?version=22.03.4&target=rockchip%2Farmv8&id=friendlyarm_nanopi-r2s

After that, Attended System Upgrade (AUC) makes for an easy upgrade keeping all added packages and config. Make good backups before though. :-)

2 Likes

As mentioned in the second post, instead of growing/enlarging the filesystem on a running system, you can alternatively instruct the ImageBuilder to create images with larger partitions. With the script below you can copy files from the target and restore them automatically after the update.

I am using this now for several releases (21.02.3 --> 22.03.2 --> 22.03.3 --> 22.03.4). I keep a "chroot" and a couple of shell-scripts, that are backed-up and restored automatically, by this script:

Perhaps you want to consider this option, instead of growing the partitions.

#!/bin/bash

#Documentation: https://openwrt.org/docs/guide-user/additional-software/imagebuilder

HOST="192.168.1.123"
OUTPUT="$(pwd)/images"
BUILDER="https://downloads.openwrt.org/releases/21.02.3/targets/bcm27xx/bcm2710/openwrt-imagebuilder-21.02.3-bcm27xx-bcm2710.Linux-x86_64.tar.xz"
BUILDER="https://downloads.openwrt.org/releases/22.03.2/targets/bcm27xx/bcm2710/openwrt-imagebuilder-22.03.2-bcm27xx-bcm2710.Linux-x86_64.tar.xz"
BUILDER="https://downloads.openwrt.org/releases/22.03.3/targets/bcm27xx/bcm2710/openwrt-imagebuilder-22.03.3-bcm27xx-bcm2710.Linux-x86_64.tar.xz"
BUILDER="https://downloads.openwrt.org/releases/22.03.4/targets/bcm27xx/bcm2710/openwrt-imagebuilder-22.03.4-bcm27xx-bcm2710.Linux-x86_64.tar.xz"

KERNEL_PARTSIZE=$((2*1024)) #Kernel-Partitionsize in MB
ROOTFS_PARTSIZE=$((5*1024)) #Rootfs-Partitionsize in MB

# download image builder
if [ ! -f "${BUILDER##*/}" ]; then
	wget "$BUILDER" || exit 1
	tar xJvf "${BUILDER##*/}" || exit 1
fi

mkdir "$OUTPUT"
cd openwrt-*/ || exit 1

# list all targets for this image builder, consider 'make help' as well
#make info

# clean previous images
make clean || exit 1

#adjust partition sizes
sed -i "s/CONFIG_TARGET_KERNEL_PARTSIZE=.*/CONFIG_TARGET_KERNEL_PARTSIZE=$KERNEL_PARTSIZE/g" .config || exit 1
sed -i "s/CONFIG_TARGET_ROOTFS_PARTSIZE=.*/CONFIG_TARGET_ROOTFS_PARTSIZE=$ROOTFS_PARTSIZE/g" .config || exit 1

# Packages are added if no prefix is given, '-packagename' does not integrate/removes a package
make image  PROFILE="rpi-3" \
           PACKAGES="luci-base luci-ssl luci-mod-admin-full luci-theme-bootstrap \
                     collectd-mod-ping collectd-mod-wireless luci-app-statistics pingcheck collectd-mod-uptime \
                     kmod-usb-storage kmod-usb-ohci kmod-usb-uhci e2fsprogs fdisk resize2fs \
                     htop debootstrap debian-archive-keyring gpgv2 gcc python3-pip block-mount \
                     openssh-sftp-server \
                     mosquitto-client-ssl mosquitto-ssl screen socat unshare kmod-usb-serial-cp210x ip-full kmod-veth luci-app-ser2net \
                     shadow-useradd tar" \
            BIN_DIR="$OUTPUT" || exit 1

#save config and copy across
ssh root@$HOST "sysupgrade -v --create-backup /tmp/$HOST.backup.tar.gz" || exit 1
scp root@$HOST:/tmp/$HOST.backup.tar.gz "$OUTPUT/" || exit 1

#preserve a chroot located at /root/mychroot (bind mount it, create tarball, copy across)
ssh root@$HOST 'mkdir -p /root/mychroot_bindmount && mount --bind /root/mychroot/ /root/mychroot_bindmount && tar -c -z -p -v --numeric-owner -f - /root/mychroot_bindmount' > "$OUTPUT/$HOST.mychroot.tgz" || exit 1

#copy all *.sh files across
scp root@$HOST:/root/*.sh "$OUTPUT/" || exit 1

#perform the actual update
scp "$OUTPUT"/openwrt-*-bcm27xx-bcm2710-rpi-3-squashfs-sysupgrade.img.gz root@$HOST:/tmp/ || exit 1
ssh root@$HOST 'sysupgrade -v -c -u /tmp/openwrt*img.gz && exit'

#wait till HOST is online again
echo "wait..."
sleep 10
while true; do
	echo -n .
	ping -c 1 $HOST > /dev/null && break
	sleep 1
done
echo " OK!"

#restore the chroot (copy across, untar, reboot) and the *.sh files
scp "$OUTPUT/$HOST.mychroot.tgz" root@$HOST:/root/ || exit 1
scp $OUTPUT/*.sh root@$HOST:/root/ || exit 1
ssh root@$HOST "cd /root && tar -xvpzf $HOST.mychroot.tgz -C / --numeric-owner" || exit 1
ssh root@$HOST "mv /root/mychroot_bindmount/ /root/mychroot/" || exit 1
ssh root@$HOST 'reboot && exit'

echo "wait..."
sleep 10
while true; do
	echo -n .
	ping -c 1 $HOST > /dev/null && break
	sleep 1
done
echo " OK!"

exit 0

2 Likes

That's next on the list. :slight_smile:

1 Like

Seems to be a bit of a problem on R2S, am I the only one?

I expanded of the second hide partition f2fs of the squashfs filesystem on the VM,
form this
https://forum.openwrt.org/t/howto-resizing-root-partition-on-x86/140631,

but on R2S after reboot it won't start.
Since I don't know how use the serial port to debug R2S, I can't get the startup logs

fsck.f2fs -f ${LOOP}

+ fsck.f2fs -f /dev/loop1
Info: Force to fix corruption
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 62275968 (30408 MB)
Info: MKFS version
  "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
Info: FSCK version
  from "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
    to "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
Info: superblock features = 0 :
Info: superblock encrypt level = 0, salt = 00000000000000000000000000000000
Info: total FS sectors = 641408 (313 MB)
Info: CKPT version = 61222f68
Info: Corrupted valid nat_bits in checkpoint
Info: Write valid nat_bits in checkpoint
Info: checkpoint state = c4 :  nat_bits crc compacted_summary sudden-power-off

[FSCK] Unreachable nat entries                        [Ok..] [0x0]
[FSCK] SIT valid block bitmap checking                [Ok..]
[FSCK] Hard link checking for regular file            [Ok..] [0x1]
[FSCK] valid_block_count matching with CP             [Ok..] [0x1bcd]
[FSCK] valid_node_count matching with CP (de lookup)  [Ok..] [0x7f2]
[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [0x7f2]
[FSCK] valid_inode_count matched with CP              [Ok..] [0x7f2]
[FSCK] free segment_count matched with CP             [Ok..] [0x7f]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Ok..]
Info: Duplicate valid checkpoint to mirror position 1024 -> 512
Info: Write valid nat_bits in checkpoint
Info: Write valid nat_bits in checkpoint

Done: 1.119534 sec

resize.f2fs ${LOOP}

+ resize.f2fs /dev/loop1
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 62275968 (30408 MB)
Info: MKFS version
  "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
Info: FSCK version
  from "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
    to "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
Info: superblock features = 0 :
Info: superblock encrypt level = 0, salt = 00000000000000000000000000000000
Info: total FS sectors = 641408 (313 MB)
Info: CKPT version = 61222f68
[migrate_block:  56] Migrate node block 1003 -> ce00
[migrate_block:  56] Migrate node block 101d -> ce01
[migrate_block:  56] Migrate node block 101e -> ce02
[migrate_block:  56] Migrate node block 1020 -> ce03
[migrate_block:  56] Migrate node block 1027 -> ce04
[migrate_block:  56] Migrate node block 1029 -> ce05
[migrate_block:  56] Migrate node block 102a -> ce06
[migrate_block:  56] Migrate node block 102b -> ce07
[migrate_block:  56] Migrate node block 102c -> ce08
[migrate_block:  56] Migrate node block 102d -> ce09

[migrate_block:  56] Migrate data block a3fa -> eeec
[migrate_block:  56] Migrate data block a3fb -> eeed
[migrate_block:  56] Migrate data block a3fc -> eeee
[migrate_block:  56] Migrate data block a3fd -> eeef
[migrate_block:  56] Migrate data block a3fe -> eef0
[migrate_block:  56] Migrate data block a3ff -> eef1
[FIX] (move_one_curseg_info:2798)  --> Move curseg[0] 11 -> 6d after ce00

[FIX] (move_one_curseg_info:2798)  --> Move curseg[1] 6 -> 6f after ce00

[FIX] (move_one_curseg_info:2798)  --> Move curseg[2] 10 -> 6e after ce00

[FIX] (move_one_curseg_info:2798)  --> Move curseg[3] 0 -> 5f after ce00

[FIX] (move_one_curseg_info:2798)  --> Move curseg[4] 12 -> 6b after ce00

[FIX] (move_one_curseg_info:2798)  --> Move curseg[5] 2 -> 70 after ce00

Info: Write valid nat_bits in checkpoint
Try to do defragement: Done
[migrate_ssa: 270] Info: Done to migrate SSA blocks: sum_blkaddr = 0xe00 -> 0x9200
[migrate_nat: 386] Info: Done to migrate NAT blocks: nat_blkaddr = 0xa00 -> 0xa00
[migrate_sit: 444] Info: Done to restore new SIT blocks: 0x600
Info: Write valid nat_bits in checkpoint
[rebuild_checkpoint: 585] Info: Done to rebuild checkpoint blocks
[update_superblock: 695] Info: Done to update superblock

Done: 13.329668 secs

I made several attempts and I noticed a lot of modifications on resize.f2fs,
tried fsck.f2fs again after resize.f2fs and got a Checkpoint is polluted error, which I think should have failed.

I tried using the tune2fs method. Stuck in resource busy when remount.

mount -o remount,ro /

Is there any way to fix this?
Thanks


Update 1:

The reason I seem to have discovered is that those built using firmware selector will use ext4 as the overlay,
same as this [https://forum.openwrt .org/t/resizing-the-hidden-overlay-filesystem-when-it-is-ext4-and-not-f2fs/140490](https://forum.openwrt .org/t/resizing-the-hidden-overlay-filesystem-when-it-is-ext4-and-not-f2fs/140490),
and when I use imager-builder on my windows wsl, it will use f2fs as overlay.

I suspect that the existing filesystem is not fixable at this point. You should be able to get a larger filesystem after re-installing an image to your sd-card and first boot.

Since you are using image-builder, you probably can build the image with the larger filesystem. See this thread specific to the R2S for info: ImageBuilder - How to create an image with a custom filesystem

It looks like some people have had success with expanding the second partition before first boot and the writable overlay filesystem gets created larger at first boot.

If you want to continue with the expanding method, I have a few thoughts to share.
I suspect the errors you ran into may have been caused by using the wrong tools for the filesystem you have, you had the wrong offset for the loop device you created or you pasted all the commands together rather than one at a time and waiting for the prompt (or error message) between each command. In the set of commands in the method I shared and you linked, you need to type them as-is and don't try to substitute values for variables yourself.

I have an R4S and not and R2S but I think others have said they use the same basic storage layout.
If you want some specific help, please reply with some info from the R2S after re-installing your image and booting it:
Output of df -hT
Output of losetup

Good luck!

  1. This is the information of image-builder

    image-builder .config bigger rootfs for install dockerd

    CONFIG_TARGET_ROOTFS_PARTSIZE=384
    

    image-builder command for install dockerd

    make image FILES=/mnt/f/code/seed-lab4x/seed-homelab-workspace/.config/dev@home/openwrt@home/image/r2s.lan/any/file 'PACKAGES=base-files busybox ca-bundle dnsmasq dropbear e2fsprogs firewall4 fstools kmod-gpio-button-hotplug kmod-nft-offload kmod-usb-net-rtl8152 libc libgcc libustream-wolfssl logd mkf2fs mtd netifd nftables odhcp6c odhcpd-ipv6only opkg partx-utils ppp ppp-mod-pppoe procd procd-seccomp procd-ujail uboot-envtools uci uclient-fetch urandom-seed urngd -dnsmasq dnsmasq-full fdisk cfdisk parted lsblk losetup resize2fs f2fs-tools python3 luci luci-app-firewall luci-app-opkg luci-base luci-lib-base luci-lib-ip luci-lib-jsonc luci-lib-nixio luci-mod-admin-full luci-mod-network luci-mod-status luci-mod-system luci-proto-ipv6 luci-proto-ppp luci-ssl luci-theme-bootstrap docker dockerd docker-compose luci-lib-docker luci-app-dockerman fuse-overlayfs ' PROFILE=friendlyarm_nanopi-r2s
    

    The system information produced by image-builder is as follows

    BusyBox v1.35.0 (2023-09-29 09:56:24 UTC) built-in shell (ash)
    
      _______                     ________        __
     |       |.-----.-----.-----.|  |  |  |.----.|  |_
     |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
     |_______||   __|_____|__|__||________||__|  |____|
              |__| W I R E L E S S   F R E E D O M
     -----------------------------------------------------
     OpenWrt 22.03.5, r20134-5f15225c1e
     -----------------------------------------------------
    root@R2S:~# set -x
    root@R2S:~# parted -l
    + parted -l
    Model: SD  (sd/mmc)
    Disk /dev/mmcblk0: 32.0GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags: 
    
    Number  Start   End     Size    Type     File system  Flags
     1      33.6MB  50.3MB  16.8MB  primary  ext2         boot
     2      67.1MB  470MB   403MB   primary
    
    
    root@R2S:~# lsblk -l -o+FSTYPE
    + lsblk -l -o+FSTYPE
    NAME      MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS FSTYPE
    loop0       7:0    0 313.2M  0 loop /overlay    f2fs
    mmcblk0   179:0    0  29.8G  0 disk
    mmcblk0p1 179:1    0    16M  0 part             ext4
    mmcblk0p2 179:2    0   384M  0 part /rom        squashfs
    
    root@R2S:~# losetup -l
    + losetup -l
    NAME       SIZELIMIT   OFFSET AUTOCLEAR RO BACK-FILE  DIO LOG-SEC
    /dev/loop0         0 74252288         1  0 /mmcblk0p2   0     512
    
    root@R2S:~# df -hT
    + df -hT
    Filesystem           Type            Size      Used Available Use% Mounted on
    /dev/root            squashfs       71.0M     71.0M         0 100% /rom
    tmpfs                tmpfs         494.4M   1004.0K    493.4M   0% /tmp
    /dev/loop0           f2fs          311.2M    108.4M    202.8M  35% /overlay
    overlayfs:/overlay   overlay       311.2M    108.4M    202.8M  35% /
    tmpfs                tmpfs         512.0K         0    512.0K   0% /dev
    overlayfs:/overlay   overlay       311.2M    108.4M    202.8M  35% /opt/docker
    
  2. The same custom packages cannot be built in firmware-selector, dockerd must be removed

    customize installed packages

    base-files busybox ca-bundle dropbear e2fsprogs firewall4 fstools kmod-gpio-button-hotplug kmod-nft-offload kmod-usb-net-rtl8152 libc libgcc libustream-wolfssl logd mkf2fs mtd netifd nftables odhcp6c odhcpd-ipv6only opkg partx-utils ppp ppp-mod-pppoe procd procd-seccomp procd-ujail uboot-envtools uci uclient-fetch urandom-seed urngd dnsmasq-full fdisk cfdisk parted lsblk losetup resize2fs f2fs-tools python3 luci luci-app-firewall luci-app-opkg luci-base luci-lib-base luci-lib-ip luci-lib-jsonc luci-lib-nixio luci-mod-admin-full luci-mod-network luci-mod-status luci-mod-system luci-proto-ipv6 luci-proto-ppp luci-ssl luci-theme-bootstrap
    

    I've also tried lowering the version for install dockerd

    Unsupported version: 22.03.3
    Unsupported version: 22.03.2
    Unsupported version: 22.03.1
    

    The system information produced by firmware-selector is as follows

    BusyBox v1.35.0 (2023-09-29 09:56:24 UTC) built-in shell (ash)
    
      _______                     ________        __
     |       |.-----.-----.-----.|  |  |  |.----.|  |_
     |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
     |_______||   __|_____|__|__||________||__|  |____|
              |__| W I R E L E S S   F R E E D O M
     -----------------------------------------------------
     OpenWrt 22.03.5, r20134-5f15225c1e
     -----------------------------------------------------
    root@R2S:~# set -x
    root@R2S:~# parted -l
    + parted -l
    Model: SD  (sd/mmc)
    Disk /dev/mmcblk0: 32.0GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:
    
    Number  Start   End     Size    Type     File system  Flags
     1      33.6MB  50.3MB  16.8MB  primary  ext2         boot
     2      67.1MB  176MB   109MB   primary
    
    
    root@R2S:~# lsblk -l -o+FSTYPE
    + lsblk -l -o+FSTYPE
    NAME      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS FSTYPE
    loop0       7:0    0 93.3M  0 loop /overlay    ext4
    mmcblk0   179:0    0 29.8G  0 disk
    mmcblk0p1 179:1    0   16M  0 part             ext4
    mmcblk0p2 179:2    0  104M  0 part /rom        squashfs
    
    root@R2S:~# losetup -l
    + losetup -l
    NAME       SIZELIMIT   OFFSET AUTOCLEAR RO BACK-FILE  DIO LOG-SEC
    /dev/loop0         0 11206656         1  0 /mmcblk0p2   0     512
    
    root@R2S:~# df -hT
    + df -hT
    Filesystem           Type            Size      Used Available Use% Mounted on
    /dev/root            squashfs       10.8M     10.8M         0 100% /rom
    tmpfs                tmpfs         494.4M     60.0K    494.4M   0% /tmp
    /dev/loop0           ext4           81.9M     28.0K     75.4M   0% /overlay
    overlayfs:/overlay   overlay        81.9M     28.0K     75.4M   0% /
    tmpfs                tmpfs         512.0K         0    512.0K   0% /dev
    

The two are not quite the same,

  1. /dev/loop0(/overlay), firmware-selector is ext4, and image-builder is f2fs.

    I successfully expanded the firmware-selector ext4, but the image-builder f2fs is stuck at startup.

  2. the firmware-selector build is not stable.

    same customize installed packages sometimes succeed and sometimes fail.
    i cannot install dockerd on firmware-selector


Update 2:

When I removed dockerd in the image-builder custom package,
and CONFIG_TARGET_ROOTFS_PARTSIZE=384 no longer needs and removed,
the /dev/loop0(/overlay) turned into ext4

Is the image-builder image stuck on first boot or after expanding the f2fs filesystem?
If after expanding, did you use the f2fs tools and did they run without errors?

The steps in the list at https://github.com/anaelorlinski/OpenWrt-NanoPi-R2S-R4S-Builds/blob/main/docs/resize-f2fs.md are reported to work and is the basis for my version for ext4. Issue the commands one at a time and proceed only if no errors show up at each step.

It may be good to check your loop device settings before trying to resize it.
Try adding it as a new loop device and mounting it read-only and browsing it.
If that works, unmount it and resize it with the steps in the github link above.

From your reply:

root@R2S:~# losetup -l
+ losetup -l
NAME       SIZELIMIT   OFFSET AUTOCLEAR RO BACK-FILE  DIO LOG-SEC
/dev/loop0         0 74252288         1  0 /mmcblk0p2   0     512

root@R2S:~#

Add new loop1 device with the current offset:
losetup -o 74252288 /dev/loop1 /dev/mmcblk1p2
( adjust offset to match current info )

Mount it read only to /mnt and try navigating directories and reading files.
mount -r /dev/loop1 /mnt

Unmount it and fsck it.
cd ~
umount /dev/loop1
fsck.f2fs /dev/loop1
You should not get any errors. You may see info or warnings though. Proceed accordingly.

After resizing, try remounting read-only and browsing it before rebooting.

If you get errors in any of the process, post your terminal session log showing all the commands and the output so we can possibly help more.

If your goal is simply to have room to add all the packages you want, perhaps use which ever image generation works with filesystem expansion, expand and add packages after.

For more help with image-builder or firmware-selector it is probably a good idea to pen a new question for that. It is more likely to be seen by more people.

P.S. I think I've seen posts indicating similar issues in image-builder and firmware-selector with adding packages that put storage way beyond 100MB. You could search the forum for info or ask, especially if you can share a repeatable scenario.

Good luck!

This is a complete process log, from partition expansion to file system expansion.
This is an example of no restart after partition expansion.
I have tried the restart scenario, and the file system expansion also failed.

No read-only mount is used here. If use read-only mount, will be prompted with "Mount unclean image to replay log first" and cannot expand the root file system.

root@R2S:~# 
root@R2S:~# parted -l
Model: SD SA08G (sd/mmc)
Disk /dev/mmcblk0: 7973MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      33.6MB  50.3MB  16.8MB  primary  ext2         boot
 2      67.1MB  604MB   537MB   primary


root@R2S:~# lsblk -l
NAME      MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0       7:0    0 438.5M  0 loop /overlay
mmcblk0   179:0    0   7.4G  0 disk
mmcblk0p1 179:1    0    16M  0 part
mmcblk0p2 179:2    0   512M  0 part /rom
root@R2S:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                73.5M     73.5M         0 100% /rom
tmpfs                   494.4M     80.0K    494.4M   0% /tmp
/dev/loop0              436.5M    107.0M    329.5M  25% /overlay
overlayfs:/overlay      436.5M    107.0M    329.5M  25% /
tmpfs                   512.0K         0    512.0K   0% /dev
overlayfs:/overlay      436.5M    107.0M    329.5M  25% /opt/docker
root@R2S:~# losetup -l
NAME       SIZELIMIT   OFFSET AUTOCLEAR RO BACK-FILE  DIO LOG-SEC
/dev/loop0         0 77070336         1  0 /mmcblk0p2   0     512
root@R2S:~#
root@R2S:~# parted -s /dev/mmcblk0 resizepart 2 100%
root@R2S:~# losetup -o 77070336 /dev/loop1 /dev/mmcblk0p2
root@R2S:~# fsck.f2fs /dev/loop1
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 15291392 (7466 MB)
Info: MKFS version
  "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
Info: FSCK version
  from "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
    to "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
Info: superblock features = 0 :
Info: superblock encrypt level = 0, salt = 00000000000000000000000000000000
Info: total FS sectors = 898048 (438 MB)
Info: CKPT version = d4b2973
Info: Checked valid nat_bits in checkpoint
Info: checkpoint state = c4 :  nat_bits crc compacted_summary sudden-power-off

[FSCK] Unreachable nat entries                        [Ok..] [0x0]
[FSCK] SIT valid block bitmap checking                [Ok..]
[FSCK] Hard link checking for regular file            [Ok..] [0x1]
[FSCK] valid_block_count matching with CP             [Ok..] [0x6c]
[FSCK] valid_node_count matching with CP (de lookup)  [Ok..] [0x53]
[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [0x53]
[FSCK] valid_inode_count matched with CP              [Ok..] [0x53]
[FSCK] free segment_count matched with CP             [Ok..] [0xcd]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Ok..]

Done: 0.967377 secs
root@R2S:~# mount -r /dev/loop1 /mnt
root@R2S:~# ls -l /mnt/upper/etc
-rw-r--r--    1 root     root           581 Jan 21  2016 board.json
drwxr-xr-x    2 root     root          3488 Jan 21  2016 config
drwxr-xr-x    2 root     root          3488 Oct 11 10:49 docker
drwx------    2 root     root          3488 Jan 21  2016 dropbear
drwxrwxrwx    2 root     root          3488 Jan 21  2016 uci-defaults
-rw-r--r--    1 root     root           749 Jan 21  2016 uhttpd.crt
-rw-r--r--    1 root     root           121 Jan 21  2016 uhttpd.key
-rw-------    1 root     root           512 Jan 21  2016 urandom.seed
root@R2S:~# umount /dev/loop1
root@R2S:~# fsck.f2fs /dev/loop1
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 15291392 (7466 MB)
Info: MKFS version
  "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
Info: FSCK version
  from "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
    to "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
Info: superblock features = 0 :
Info: superblock encrypt level = 0, salt = 00000000000000000000000000000000
Info: total FS sectors = 898048 (438 MB)
Info: CKPT version = d4b2976
Info: checkpoint state = 45 :  crc compacted_summary unmount

[FSCK] Unreachable nat entries                        [Ok..] [0x0]
[FSCK] SIT valid block bitmap checking                [Ok..]
[FSCK] Hard link checking for regular file            [Ok..] [0x1]
[FSCK] valid_block_count matching with CP             [Ok..] [0x7d]
[FSCK] valid_node_count matching with CP (de lookup)  [Ok..] [0x56]
[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [0x56]
[FSCK] valid_inode_count matched with CP              [Ok..] [0x56]
[FSCK] free segment_count matched with CP             [Ok..] [0xcc]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Ok..]

Done: 0.160005 secs
root@R2S:~# resize.f2fs /dev/loop1
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 15291392 (7466 MB)
Info: MKFS version
  "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
Info: FSCK version
  from "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
    to "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
Info: superblock features = 0 :
Info: superblock encrypt level = 0, salt = 00000000000000000000000000000000
Info: total FS sectors = 898048 (438 MB)
        Invalid CP CRC offset: 0
Info: CKPT version = d4b2975
Info: Duplicate valid checkpoint to mirror position 512 -> 1024
Info: Write valid nat_bits in checkpoint
[migrate_block:  56] Migrate node block 1003 -> 3e00
[migrate_block:  56] Migrate node block 101d -> 3e01
[migrate_block:  56] Migrate node block 1020 -> 3e02
[migrate_block:  56] Migrate node block 1021 -> 3e03
[migrate_block:  56] Migrate node block 1023 -> 3e04
[migrate_block:  56] Migrate node block 1025 -> 3e05
[migrate_block:  56] Migrate node block 1028 -> 3e06
[migrate_block:  56] Migrate node block 102a -> 3e07
[migrate_block:  56] Migrate node block 102b -> 3e08
[migrate_block:  56] Migrate node block 102c -> 3e09
[migrate_block:  56] Migrate node block 102d -> 3e0a
[migrate_block:  56] Migrate node block 102e -> 3e0b
[migrate_block:  56] Migrate node block 102f -> 3e0c
[migrate_block:  56] Migrate node block 1030 -> 3e0d
[migrate_block:  56] Migrate node block 1031 -> 3e0e
[migrate_block:  56] Migrate node block 1032 -> 3e0f
[migrate_block:  56] Migrate node block 1033 -> 3e10
[migrate_block:  56] Migrate node block 1034 -> 3e11
[migrate_block:  56] Migrate node block 1036 -> 3e12
[migrate_block:  56] Migrate node block 1037 -> 3e13
[migrate_block:  56] Migrate node block 1038 -> 3e14
[migrate_block:  56] Migrate node block 1039 -> 3e15
[migrate_block:  56] Migrate node block 103a -> 3e16
[migrate_block:  56] Migrate node block 103b -> 3e17
[migrate_block:  56] Migrate node block 103c -> 3e18
[migrate_block:  56] Migrate node block 103d -> 3e19
[migrate_block:  56] Migrate node block 103e -> 3e1a
[migrate_block:  56] Migrate node block 103f -> 3e1b
[migrate_block:  56] Migrate node block 1040 -> 3e1c
[migrate_block:  56] Migrate node block 1041 -> 3e1d
[migrate_block:  56] Migrate node block 1042 -> 3e1e
[migrate_block:  56] Migrate node block 1043 -> 3e1f
[migrate_block:  56] Migrate node block 1044 -> 3e20
[migrate_block:  56] Migrate node block 1045 -> 3e21
[migrate_block:  56] Migrate node block 1046 -> 3e22
[migrate_block:  56] Migrate node block 1047 -> 3e23
[migrate_block:  56] Migrate node block 1048 -> 3e24
[migrate_block:  56] Migrate node block 104a -> 3e25
[migrate_block:  56] Migrate node block 104b -> 3e26
[migrate_block:  56] Migrate node block 104c -> 3e27
[migrate_block:  56] Migrate node block 104d -> 3e28
[migrate_block:  56] Migrate node block 104e -> 3e29
[migrate_block:  56] Migrate node block 104f -> 3e2a
[migrate_block:  56] Migrate node block 1050 -> 3e2b
[migrate_block:  56] Migrate node block 1051 -> 3e2c
[migrate_block:  56] Migrate node block 1055 -> 3e2d
[migrate_block:  56] Migrate node block 1056 -> 3e2e
[migrate_block:  56] Migrate node block 1058 -> 3e2f
[migrate_block:  56] Migrate node block 1059 -> 3e30
[migrate_block:  56] Migrate node block 105a -> 3e31
[migrate_block:  56] Migrate node block 105b -> 3e32
[migrate_block:  56] Migrate node block 105c -> 3e33
[migrate_block:  56] Migrate node block 105d -> 3e34
[migrate_block:  56] Migrate node block 105f -> 3e35
[migrate_block:  56] Migrate node block 1060 -> 3e36
[migrate_block:  56] Migrate node block 1062 -> 3e37
[migrate_block:  56] Migrate node block 1200 -> 4000
[migrate_block:  56] Migrate node block 1206 -> 4001
[migrate_block:  56] Migrate node block 1208 -> 4002
[migrate_block:  56] Migrate node block 1211 -> 4003
[migrate_block:  56] Migrate node block 1214 -> 4004
[migrate_block:  56] Migrate node block 1216 -> 4005
[migrate_block:  56] Migrate node block 121b -> 4006
[migrate_block:  56] Migrate node block 121c -> 4007
[migrate_block:  56] Migrate node block 121d -> 4008
[migrate_block:  56] Migrate node block 1228 -> 4009
[migrate_block:  56] Migrate node block 1229 -> 400a
[migrate_block:  56] Migrate node block 122a -> 400b
[migrate_block:  56] Migrate node block 122d -> 400c
[migrate_block:  56] Migrate node block 122e -> 400d
[migrate_block:  56] Migrate node block 122f -> 400e
[migrate_block:  56] Migrate node block 1230 -> 400f
[migrate_block:  56] Migrate node block 1231 -> 4010
[migrate_block:  56] Migrate node block 1236 -> 4011
[migrate_block:  56] Migrate node block 1237 -> 4012
[migrate_block:  56] Migrate node block 1238 -> 4013
[migrate_block:  56] Migrate node block 123b -> 4014
[migrate_block:  56] Migrate node block 123c -> 4015
[migrate_block:  56] Migrate node block 123f -> 4016
[migrate_block:  56] Migrate node block 1241 -> 4017
[migrate_block:  56] Migrate node block 1243 -> 4018
[migrate_block:  56] Migrate node block 124a -> 4019
[migrate_block:  56] Migrate node block 124b -> 401a
[migrate_block:  56] Migrate node block 124c -> 401b
[migrate_block:  56] Migrate node block 124d -> 401c
[migrate_block:  56] Migrate node block 124e -> 401d
[migrate_block:  56] Migrate data block 1605 -> 4200
[migrate_block:  56] Migrate data block 1606 -> 4201
[migrate_block:  56] Migrate data block 1607 -> 4202
[migrate_block:  56] Migrate data block 1608 -> 4203
[migrate_block:  56] Migrate data block 1609 -> 4204
[migrate_block:  56] Migrate data block 160a -> 4205
[migrate_block:  56] Migrate data block 160b -> 4206
[migrate_block:  56] Migrate data block 160c -> 4207
[migrate_block:  56] Migrate data block 160d -> 4208
[migrate_block:  56] Migrate data block 160e -> 4209
[migrate_block:  56] Migrate data block 160f -> 420a
[migrate_block:  56] Migrate data block 1610 -> 420b
[migrate_block:  56] Migrate data block 1611 -> 420c
[migrate_block:  56] Migrate data block 1612 -> 420d
[migrate_block:  56] Migrate data block 1613 -> 420e
[migrate_block:  56] Migrate data block 1614 -> 420f
[migrate_block:  56] Migrate data block 1615 -> 4210
[migrate_block:  56] Migrate data block 1616 -> 4211
[migrate_block:  56] Migrate data block 1617 -> 4212
[migrate_block:  56] Migrate data block 1618 -> 4213
[migrate_block:  56] Migrate data block 1619 -> 4214
[migrate_block:  56] Migrate data block 161a -> 4215
[migrate_block:  56] Migrate data block 161b -> 4216
[migrate_block:  56] Migrate data block 161c -> 4217
[migrate_block:  56] Migrate data block 161d -> 4218
[migrate_block:  56] Migrate data block 161e -> 4219
[migrate_block:  56] Migrate data block 161f -> 421a
[migrate_block:  56] Migrate data block 1620 -> 421b
[migrate_block:  56] Migrate data block 1621 -> 421c
[migrate_block:  56] Migrate data block 1622 -> 421d
[migrate_block:  56] Migrate data block 1623 -> 421e
[migrate_block:  56] Migrate data block 1624 -> 421f
[migrate_block:  56] Migrate data block 1625 -> 4220
[migrate_block:  56] Migrate data block 1626 -> 4221
[migrate_block:  56] Migrate data block 1627 -> 4222
[migrate_block:  56] Migrate data block 1628 -> 4223
[migrate_block:  56] Migrate data block 1629 -> 4224
[migrate_block:  56] Migrate data block 162a -> 4225
[migrate_block:  56] Migrate data block 162b -> 4226
[FIX] (move_one_curseg_info:2798)  --> Move curseg[0] 4 -> 19 after 3e00

[FIX] (move_one_curseg_info:2798)  --> Move curseg[1] 68 -> 1a after 3e00

[FIX] (move_one_curseg_info:2798)  --> Move curseg[2] 33 -> 1b after 3e00

[FIX] (move_one_curseg_info:2798)  --> Move curseg[3] 0 -> 17 after 3e00

[FIX] (move_one_curseg_info:2798)  --> Move curseg[4] 1 -> 18 after 3e00

[FIX] (move_one_curseg_info:2798)  --> Move curseg[5] 2 -> 1c after 3e00

Info: Write valid nat_bits in checkpoint
Try to do defragement: Done
[migrate_ssa: 270] Info: Done to migrate SSA blocks: sum_blkaddr = 0xe00 -> 0x2e00
[migrate_nat: 386] Info: Done to migrate NAT blocks: nat_blkaddr = 0xa00 -> 0xa00
[migrate_sit: 444] Info: Done to restore new SIT blocks: 0x600
Info: Write valid nat_bits in checkpoint
[rebuild_checkpoint: 585] Info: Done to rebuild checkpoint blocks
[update_superblock: 695] Info: Done to update superblock

Done: 14.460683 secs

There is no error prompt at this point, but I will not be able to enter the system after reboot at this time, I suspect that the file system expansion has failed,
so I just run fsck.f2fs again it fail and stuck.

root@R2S:~# fsck.f2fs /dev/loop1
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 15291392 (7466 MB)
Info: MKFS version
  "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
Info: FSCK version
  from "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
    to "Linux version 5.10.176 (builder@buildhost) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r20134-5f15225c1e) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP PREEMPT Thu Apr 27 20:28:15 2023"
Info: superblock features = 0 :
Info: superblock encrypt level = 0, salt = 00000000000000000000000000000000
Info: total FS sectors = 15291392 (7466 MB)
        Invalid CP CRC offset: 0
Info: CKPT version = d4b2976
Info: Checked valid nat_bits in checkpoint
Info: checkpoint state = 81 :  nat_bits unmount
[ASSERT] (sanity_check_nid: 417)  --> nid[0x6d] nat_entry->ino[0x6d] footer.ino[0x46]
[ASSERT] (fsck_chk_inode_blk:1015)  --> ino: 0x33 i_links: 14, real links: 13

NID[0x6d] is unreachable, blkaddr:0x3e37
NID[0x6e] is unreachable, blkaddr:0x3e35
NID[0x6f] is unreachable, blkaddr:0x3e36
NID[0x70] is unreachable, blkaddr:0x401a
NID[0x71] is unreachable, blkaddr:0x401b
NID[0x72] is unreachable, blkaddr:0x401c
NID[0x74] is unreachable, blkaddr:0x401d
[FSCK] Unreachable nat entries                        [Fail] [0x7]
[FSCK] SIT valid block bitmap checking                [Fail]
[FSCK] Hard link checking for regular file            [Ok..] [0x1]
[FSCK] valid_block_count matching with CP             [Fail] [0x64]
[FSCK] valid_node_count matching with CP (de lookup)  [Fail] [0x4f]
[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [0x56]
[FSCK] valid_inode_count matched with CP              [Fail] [0x4f]
[FSCK] free segment_count matched with CP             [Ok..] [0xe70]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Fail]

^C

I invite others to try to assist if you think you know a solution.

xiaoyao9184 - That is strange, although a couple other people reported failures for their R2S earlier in this thread.

My thoughts at this point are to:
Follow anaelorlinski's method exactly using the same utilities (cfdisk instead of parted etc)

If that still fails, try resizing to a size a bit under 1GB with something like:
resize.f2fs -t 2000000 /dev/loop1

If that fails, try starting from a standard build instead of one from firmware-selector or image-builder, maybe even an older image:
https://downloads.openwrt.org/releases/22.03.5/targets/rockchip/armv8/openwrt-22.03.5-rockchip-armv8-friendlyarm_nanopi-r2s-squashfs-sysupgrade.img.gz
or this older image just as a resize test:
https://archive.openwrt.org/releases/21.02.6/targets/rockchip/armv8/openwrt-21.02.6-rockchip-armv8-friendlyarm_nanopi-r2s-squashfs-sysupgrade.img.gz

Another idea is to :
flash the image to the card,
boot it on the R2S,
do a clean shutdown with the /sbin/poweroff command to avoid an unclean filesystem,
move the sd-card to your linux PC and expand the f2fs filesystem there
If the resize works there then boot it in the R2S.

Good luck!

I used the standard build and created an SD card from it. Before booting into R2S, I enlarged the partition with the squashfs image to larger size (6GB, since card is 64GB), nothing more. Afterwards I used the card to boot the R2S and the remaining size of the partition after the squashfs file system is used for the overlay partition (currently 5.5GB free). But you have to make the change before first booting.

1 Like

After changing parted to cfdisk, sfdisk and fdisk, and trying 2 times with each process and the third time formatting the entire SD card to 0x00, I gave up.

Currently only cfdisk is successful in shell mode

  1. step 1

    cfdisk /dev/mmcblk0
    

    no reboot

  2. step 2

    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}
    fsck.f2fs -f ${LOOP}
    mount ${LOOP} /mnt
    umount ${LOOP}
    resize.f2fs ${LOOP}
    
  3. step 3

    fsck.f2fs -f ${LOOP}
    
  4. step 4

    reboot
    

fdisk may or may not succeed, but it usually print some 'migrate block' prompts when resize.f2fs

sfdisk will not succeed. It always prompts 'Nothing to resize' when resize.f2fs.
If reboot after sfdisk, it will prompt many lines of 'migrate block' and fail.

When I found that cfdisk and fdisk could work normally,
then i switched step 2 from interactive shell to ansible tasks
(my final idea was to batch expand multiple openwrt systems through ansible-playbook),
but all failed, no matter cfdisk or fdisk will prompt many lines of 'migrate block'.

I guess the reason for the failure may be some write operations was performed on /dev/loop0 when /dev/loop1 was expanded, which eventually destroyed the file system,
but this cannot explain that the same process has no problem on the x86 platform.

I can no longer find other way to experiment, I will give up and try to create a new partition and mount it

Thanks guys

1 Like