base-files: pad root.squashfs in ubi volumes
authorChristian Lamparter <chunkeey@gmail.com>
Sat, 24 Aug 2019 10:55:40 +0000 (12:55 +0200)
committerChristian Lamparter <chunkeey@gmail.com>
Sat, 19 Oct 2019 16:50:44 +0000 (18:50 +0200)
SquashFS's HOWTO states in the section "Using mksquashfs"
<https://elinux.org/Squash_FS_Howto#Using_mksquashfs>
that a padding is necessary "for the filesystem to be used
on block devices."

OpenWrt's mksquashfs for the rootfs (which is usually
squashfs) is instructed to skip the padding via the nopad
option because the rootfs will be padded by functions like
pad-rootfs to the eraseblocksize which is usually much
bigger at somewhere 64KiB+.

But this is a problem for squashfs as rootfs in ubi
partitions. Currently no explicit padding is being
set and it currently works for the most time because
ubi volumes are always aligned to LEBs which could
be close enough for 4KiB paddings...

This patch changes sysupgrade to align squashfs rootfs
filesystem to a 1 KiB padding, while also changing the
ubinize script to apply the alignment in the same manner.

Reported-by: Russell Senior <russell@personaltelco.net>
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
package/base-files/files/lib/upgrade/nand.sh
scripts/ubinize-image.sh

index e7d7bf8..d83ac9f 100644 (file)
@@ -177,7 +177,7 @@ nand_upgrade_prepare_ubi() {
        if [ "$rootfs_type" = "ubifs" ]; then
                root_size_param="-m"
        else
-               root_size_param="-s $rootfs_length"
+               root_size_param="-s $rootfs_length -a 1024"
        fi
        if ! ubimkvol /dev/$ubidev -N $CI_ROOTPART $root_size_param; then
                echo "cannot create rootfs volume"
index d82d814..305907b 100755 (executable)
@@ -69,14 +69,10 @@ ubilayout() {
        "ubifs")
                autoresize=1
                ;;
-       "squashfs")
-               # squashfs uses 1k block size, ensure we do not
-               # violate that
-               rootsize="$( round_up "$( stat -c%s "$2" )" 1024 )"
-               ;;
        esac
        ubivol $vol_id rootfs "$2" "$autoresize" "$rootsize"
 
+       [ "$rootfs_type" = "squashfs" ] && echo "vol_alignment=1024"
        vol_id=$(( $vol_id + 1 ))
        [ "$rootfs_type" = "ubifs" ] || ubivol $vol_id rootfs_data "" 1
 }