NanoPi R5S resize squashfs

Hi,

I've flashed https://downloads.openwrt.org/releases/24.10.0/targets/rockchip/armv8/openwrt-24.10.0-rockchip-armv8-friendlyarm_nanopi-r5s-squashfs-sysupgrade.img.gz to the 16GB eMMC of this NanoPi R5S device, using FriendlyARM's eflasher, from an SD card, and am trying to expand the squashfs storage.

I have tried the automated script at:
https://openwrt.org/docs/guide-user/advanced/expand_root
but it doesn't appear to work.
(I have installed parted, losetup and resize2fs and also cfdisk though I only used that to look and made no changes)

root@OpenWrt:~# df -Th

Filesystem Type Size Used Available Use% Mounted on
/dev/root squashfs 3.5M 3.5M 0 100% /rom
tmpfs tmpfs 1.9G 1.2M 1.9G 0% /tmp
/dev/loop0 f2fs 98.6M 47.9M 50.7M 49% /overlay
overlayfs:/overlay overlay 98.6M 47.9M 50.7M 49% /
tmpfs tmpfs 512.0K 0 512.0K 0% /dev

root@openWrt:~# lsblk -o +FSTYPE; losetup -l

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS FSTYPE
loop0 7:0 0 14.5G 0 loop /overlay f2fs
mmcblk1 179:0 0 14.6G 0 disk
├─mmcblk1p1 179:1 0 16M 0 part ext4
└─mmcblk1p2 179:2 0 14.5G 0 part /rom squashfs
mmcblk1boot0 179:32 0 4M 1 disk
mmcblk1boot1 179:64 0 4M 1 disk
nvme0n1 259:0 0 465.8G 0 disk
└─nvme0n1p1 259:1 0 465.7G 0 part ext4

NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC
/dev/loop0 0 3538944 1 0 /mmcblk1p2 0 512

Can anyone advise why the expand-root script isn't working, please?

expanding root is not for mtd filrsystems, they are at their maximum size.
swuashfs is composed once for sysupgrade image, add more files it will be bigger and vice versa, on top of that /overlay in remaining space tracks changes you add on top of readonly squash fs

So how do I expand overlay?

I guess you can see what I want to acheive?
How best to make full use of the 16GB?

Add new partition 1gb away from openwrt
https://openwrt.org/docs/guide-user/storage/usb-drives-quickstart
all except usb drivers and your new filesystem will be mmc....p3

You have the option of using ext4 image on your device. You can use the script to expand the file system on ext4 for sure.

https://downloads.openwrt.org/releases/24.10.0/targets/rockchip/armv8/openwrt-24.10.0-rockchip-armv8-friendlyarm_nanopi-r5s-ext4-sysupgrade.img.gz

1 Like

Why do I need USB drivers?

If I'm understanding this https://forum.openwrt.org/t/resizing-overlay-partition-on-squashfs/222475
correctly, I can build my own image to have a given partition size and flash that?
But then there's not guarantee that sysupgrade will preserve the config

I just liked the idea of squashfs so I can factory restore if I ever need to

3 Likes

So I just ran owut upgrade --fstype ext4 and converted to ext4 which now occupies all the available space.

https://openwrt.org/docs/guide-user/installation/sysupgrade.owut#changing_file_system_type

Can anyone tell me what the syntax is for the uci-defaults box on the firmware selector page? How would I add the resize script(s) in that box?

The script you ran will automatically persist and run on upgrades.

It persists by writing to /etc/sysupgrade.conf. you can check this by running

cat /etc/sysupgrade.conf

You should see 2 files when you run this command

ls -l /etc/uci-defaults/*-resize

When you use owut/attendedsysupgrade to do upgrades, all packages and uci-defaults should persist.

Thanks for that.

If I was building an image using the firmware selector, how could I include 70-rootpt-resize and 80-rootfs-resize? There is a box for uci-defaults scripts.

Can I just paste

cat << "EOF" > /etc/uci-defaults/70-rootpt-resize if [ ! -e /etc/rootpt-resize ] \ && type parted > /dev/null \ && lock -n /var/lock/root-resize then ROOT_BLK="$(readlink -f /sys/dev/block/"$(awk -e \ '$9=="/dev/root"{print $3}' /proc/self/mountinfo)")" ROOT_DISK="/dev/$(basename "${ROOT_BLK%/*}")" ROOT_PART="${ROOT_BLK##*[^0-9]}" parted -f -s "${ROOT_DISK}" \ resizepart "${ROOT_PART}" 100% mount_root done touch /etc/rootpt-resize reboot fi exit 1 EOF cat << "EOF" > /etc/uci-defaults/80-rootfs-resize if [ ! -e /etc/rootfs-resize ] \ && [ -e /etc/rootpt-resize ] \ && type losetup > /dev/null \ && type resize2fs > /dev/null \ && lock -n /var/lock/root-resize then ROOT_BLK="$(readlink -f /sys/dev/block/"$(awk -e \ '$9=="/dev/root"{print $3}' /proc/self/mountinfo)")" ROOT_DEV="/dev/${ROOT_BLK##*/}" LOOP_DEV="$(awk -e '$5=="/overlay"{print $9}' \ /proc/self/mountinfo)" if [ -z "${LOOP_DEV}" ] then LOOP_DEV="$(losetup -f)" losetup "${LOOP_DEV}" "${ROOT_DEV}" fi resize2fs -f "${LOOP_DEV}" mount_root done touch /etc/rootfs-resize reboot fi exit 1 EOF cat << "EOF" >> /etc/sysupgrade.conf /etc/uci-defaults/70-rootpt-resize /etc/uci-defaults/80-rootfs-resize EOF

in the Script to run on first boot (uci-defaults) section, provided I have added wget, losetup, parted and resize2fs in the Installed Packages section?

That makes sense. It should work. Give it a go and report back pls.

It only created 70-rootpt-resize for some reason?
(and didn't add either to /etc/sysupgrade.conf)

Do you think it need line breaks?

Is there a reason you want to do this?

You could just keep backups using the built in system. Then if you have an issue, restore the image and then the backup.

Just want to expand the filesystem as part of flashing the image really

Are you planning on deploying many of these devices? Or is it just the one?

If it's just the one, then the script you've run has persisted now. When you upgrade using owut, the filesystem will expand after the upgrade too.

Yeah, perhaps I will just give up on this :slight_smile:

Was nearly there though, it created the first script 70-rootpt-resize, whic I've just realised is actually empty, so I guess the fireware builder doesn't like the syntax.

I know you can use the build system to create custom images with custom files in it. Depends on how much you want an image with it baked in

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

I just use the normal backups and if anything goes wrong I restore an image from the online image builder then restore my backup file. This brings me back to before I broke anything!

1 Like

Just FYI,

I got this to work by adding the following to the Script to run on first boot (uci-defaults) section:

cat << "EOF" >> /etc/sysupgrade.conf
/etc/uci-defaults/70-rootpt-resize
/etc/uci-defaults/80-rootfs-resize
EOF

cat << "EOF" > /etc/uci-defaults/70-rootpt-resize
if [ ! -e /etc/rootpt-resize ] \
&& type parted > /dev/null \
&& lock -n /var/lock/root-resize
then
ROOT_BLK="$(readlink -f /sys/dev/block/"$(awk -e \
'$9=="/dev/root"{print $3}' /proc/self/mountinfo)")"
ROOT_DISK="/dev/$(basename "${ROOT_BLK%/*}")"
ROOT_PART="${ROOT_BLK##*[^0-9]}"
parted -f -s "${ROOT_DISK}" \
resizepart "${ROOT_PART}" 100%
mount_root done
touch /etc/rootpt-resize
reboot
fi
exit 1
EOF

cat << "EOF" > /etc/uci-defaults/80-rootfs-resize
if [ ! -e /etc/rootfs-resize ] \
&& [ -e /etc/rootpt-resize ] \
&& type losetup > /dev/null \
&& type resize2fs > /dev/null \
&& lock -n /var/lock/root-resize
then
ROOT_BLK="$(readlink -f /sys/dev/block/"$(awk -e \
'$9=="/dev/root"{print $3}' /proc/self/mountinfo)")"
ROOT_DEV="/dev/${ROOT_BLK##*/}"
LOOP_DEV="$(awk -e '$5=="/overlay"{print $9}' \
/proc/self/mountinfo)"
if [ -z "${LOOP_DEV}" ]
then
LOOP_DEV="$(losetup -f)"
losetup "${LOOP_DEV}" "${ROOT_DEV}"
fi
resize2fs -f "${LOOP_DEV}"
mount_root done
touch /etc/rootfs-resize
reboot
fi
exit 1
EOF

I also added losetup, parted and resize2fs to the Installed Packages section.

It did not take after the first reboot, but did after the second (perhaps I could have added sh /etc/uci-defaults/70-rootpt-resize to make it run for the first reboot)

1 Like

I managed to grow my overlay on the R5S running the new stock OpenWRT 24.10 squashfs. It took me a while to figure out that the overlay is actually an f2fs, not ext2/3/4, so resize2fs won't work. Use resize.f2fs instead.
Essentially, you can (nearly) follow these instructions.

Here's what I used:

opkg install f2fs-tools parted losetup
parted -f -s /dev/mmcblk1 resizepart 2 100%
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}
reboot

Directly resizing /dev/loop0 doesn't work, as this is already mounted. The script above picks the next available loop device (likely /dev/loop1), maps that to /mnt/mmcblk1p2 (which also contains the RO squashfs, but then a f2fs for the overlay at an offset). After reboot, we see the expanded overlay. Note that I have the bigger R5S with 32GB eMMC and 4GB RAM.

root@friendly:~# lsblk
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
loop0          7:0    0 28.8G  0 loop /overlay
mmcblk1      179:0    0 28.9G  0 disk
├─mmcblk1p1  179:1    0   16M  0 part
└─mmcblk1p2  179:2    0 28.8G  0 part /rom
mmcblk1boot0 179:32   0    4M  1 disk
mmcblk1boot1 179:64   0    4M  1 disk
root@friendly:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 3.5M      3.5M         0 100% /rom
tmpfs                     1.9G    352.0K      1.9G   0% /tmp
/dev/loop0               28.8G    458.0M     28.4G   2% /overlay
overlayfs:/overlay       28.8G    458.0M     28.4G   2% /
tmpfs                   512.0K         0    512.0K   0% /dev

Compared to the FriendlyWRT image (with docker) I used before, the OpenWRT build doesn't come with lots of pre-installed clutter you may not need. Also, with the new image, podman seems to work, whereas docker on the FriendlyWRT had some config issues with firewall and network.
Sadly, I have so far not managed to get the SSD I stuck into the R5S to work again. It did work with FriendlyWRT. Perhaps some device tree changes are needed.

3 Likes

I had trouble getting a WD/Sandisk SSD to work with Debian 12 on the R5S.
I had to add pcie_aspm=off to the boot options
It worked with Arch though, ISTR (or one of the other flavours anyway)

https://github.com/inindev/nanopi-r5/issues/23

However, my WD/Sandisk SN570 is working on 24.10.
I take it you installed kmod-nvme and pciutils? Does it show up in /dev?