Expanding the squashfs file system

I'm using openwrt-19.07.7-x86-64-combined-squashfs.img.gz on an APU4 with a 4GB sdcard

I've been trying to follow the instructions here , to resize the squashfs image and use the rest of my sdcard.

I've successfully found the offset using losetup:

NAME       SIZELIMIT  OFFSET AUTOCLEAR RO BACK-FILE  DIO LOG-SEC
/dev/loop0         0 3014656         0  0 /mmcblk0p2   0     512

And successfully resized the squashfs partion with cfdisk

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0         7:0    0 253.1M  0 loop /overlay
mmcblk0     179:0    0   3.7G  0 disk 
 ├─mmcblk0p1 179:1    0    16M  0 part /boot
 └─mmcblk0p2 179:2    0   3.7G  0 part /rom

However, attempts to loop mount the underlying f2fs partition are not working:

root@OpenWrt:/# losetup -d -o 3014656 /dev/loop0 /dev/mmcblk0p2
losetup: -o: failed to use device: No such device

I also tried using gparted to resize and it doesn't seem to recognize the squashfs file system type.

Any suggestions?

Use the ext4 instead :wink:

Do you mean resize the ext4 "/boot" partition instead? The wiki instructions posted specify modifying the squashfs "/rom" partition.

Or do you mean I should be creating a third partition using the available sdcard space and format it using ext4? Then somehow add that as the overlay?

I'm still quite new to overlay partitions and all these disk formatting CLI commands.

Ok... finally figured this out. When you said use "the ext4 instead" I thought you meant the partition type rather than the image type. Utterly confused I gave up for a couple weeks.

Now that I've flashed the sd card using the combined-ext4.img instead of the combined-squashfs.img, things have progressed. Used cfdisk to resize /dev/mmcblk0p2 partition, then struggled to resize /dev/root until I found this workaround to an apparent issue with the x86_64 image on 19.07.07.

The steps at this link worked:

mount -o remount,ro / #Remount root as ReadOnly
tune2fs -O^resize_inode /dev/mmcblk0p2 #Remove reserved GDT blocks
fsck.ext4 /dev/mmcblk0p2 #Fix part, answer yes to remove GDT blocks remnants

#reboot
resize2fs /dev/mmcblk0p2

Now df -h shows /dev/root using the rest of the resized partition...

It would be great if this page could include the steps for the ext4-image, rather than just the squashfs-image (which don't actually work).

https://openwrt.org/docs/guide-user/installation/installation_methods/sd_card

I'll try to remember to make the change.

Since you're using a SD card, you could have fired up gparted, and resized the FSes

1 Like

@vgaetera Is this workable from an online running OpenWRT install? I'm still sitting on 19.07 since the x86 image sizes for 21.02 are too small for my use. I was planning to just create at 3rd partition for my AdguardHome install since it uses 100mb on its own and mount it to /etc/AdguardHome for ease, but this would make things a smidge easier as AdguardHome's directory size gets larger the longer it runs (logs etc) which makes it near empty on a fresh install and restore of my settings.

I've been looking for a solution to the same problem lately, using the squashfs image for NanoPi R2S. I went through the same tutorial on the wiki as OP, which resulted in the same failed losetup command. Then i stumbled on this thread locating-config-files-on-sd-card/79648 which suggests using losetup with the -f flag instead of -d.

I know close to nothing about loop mounting, but It doesn't make sense to me to (-d = detach) the device i'm trying to mount, as suggested by the wiki. Maybe the -d flag did something else in previous versions of losetup? Hopefully someone who knows more can fill in on this.

Anyway i did the following today, which worked

# at OpenWrt device
root@OpenWrt:~# losetup > losetup-output

# at my laptop running linux i resized the ~100mb partition using cfdisk to a desired size and then did the following

scp root@<openwrt device ip>:/root/losetup-output .
cat losetup-output 
sudo losetup -f -o <offset from losetup-output> /dev/sdX

# above command defaults to a loop device at /dev/loop0
# from here on it's the same as in the wiki instructions

sudo fsck.f2fs /dev/loop0
sudo resize.f2fs /dev/loop0

# i also detached all loop devices with the -D flag according to losetup help before moving the sdcard back to the NanoPi R2S
sudo losetup -D
1 Like

It works for me on OpenWrt 21.02 with a few extra steps like this:
https://openwrt.org/docs/guide-user/installation/openwrt_x86#resizing_filesystem

I get:

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

root@OpenWrt:~# fsck.f2fs /dev/loop0
Info: Mounted device!
        Error: Not available on mounted device!

If you can redo your setup, if you expand the root partition before first booting OpenWrt, the first boot process will automatically create a f2fs filesystem thats takes all the available space in second partition after built in read only rootfs.

2 Likes

can confirm this on Nanopi R4S, i just did it yesterday. interestingly if you leave with the build default of 104M root partition and don't expand the partition before first boot, it creates /dev/loop0 as an ext4 filesystem, whereas when I expanded the partition to 1G before first boot, it created /dev/loop0 as a f2fs filesystem.

1 Like

For me it looks like following the linked steps leads to a read only file system as after doing https://openwrt.org/docs/guide-user/installation/openwrt_x86#resizing_f2fs_overlay i can not make any changes to any config file and reboot without loosing all the changes. Even a new ssh key is generated on every reboot.

I posted this on another one of these questions. To share what worked for me on OpenWRT 22.03.2 with SquashFS.

1. Flash image to SD as normal with the firmware selector (I added packages to mine)
2. ssh into router
3. "opkg update && opkg install cfdisk resize2fs"
4. "cfdisk /dev/mmcblk0"
5. Create a NEW PRIMARY partition in the free space at the end. Delete this new partition. Select /dev/mmcblk0p2 and RESIZE it. The default entries will take the whole space.
6. Reboot
7. ssh into router
8. "resize2fs /dev/loop0"
9. Success!