From f6df7651da0064d4c57424a18d4cc5dd138bf1ce Mon Sep 17 00:00:00 2001 From: William Petit Date: Fri, 7 Apr 2023 11:38:27 +0200 Subject: [PATCH] feat(turris,omnia): automatically resize partition at startup --- install/turris-omnia.mk | 3 +++ misc/turris/omnia/uci-defaults/99-resize-disk.sh | 15 +++++++++++++++ targets/turris.mk | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 install/turris-omnia.mk create mode 100644 misc/turris/omnia/uci-defaults/99-resize-disk.sh diff --git a/install/turris-omnia.mk b/install/turris-omnia.mk new file mode 100644 index 0000000..d66a025 --- /dev/null +++ b/install/turris-omnia.mk @@ -0,0 +1,3 @@ +install-turris-omnia-uci-defaults: + mkdir -p files/etc/uci-defaults + cp misc/turris/omnia/uci-defaults/* files/etc/uci-defaults/ \ No newline at end of file diff --git a/misc/turris/omnia/uci-defaults/99-resize-disk.sh b/misc/turris/omnia/uci-defaults/99-resize-disk.sh new file mode 100644 index 0000000..10dc924 --- /dev/null +++ b/misc/turris/omnia/uci-defaults/99-resize-disk.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -eo pipefail + +DISK=/dev/mmcblk0 +PARTITION="${DISK}p2" + +parted -s -a opt "$DISK" "resizepart 2 100%" + +FS_SIZE="$(unsquashfs -s "$PARTITION" | grep -o 'Filesystem size [0-9]* bytes' | grep -o '[0-9][0-9]*')" +FS_OFFSET="$(expr '(' "$FS_SIZE" + 65535 ')' / 65536 '*' 65536)" +LOOP_DEVICE="$(losetup -f --show -o "$FS_OFFSET" "$PARTITION")" + +e2fsck -fy "$LOOP_DEVICE" +resize2fs "$LOOP_DEVICE" diff --git a/targets/turris.mk b/targets/turris.mk index 9a9e9c3..bff3167 100644 --- a/targets/turris.mk +++ b/targets/turris.mk @@ -4,7 +4,8 @@ turris: omnia omnia: $(MAKE) \ - ADDITIONAL_INSTALL="" \ + ADDITIONAL_INSTALL="install-turris-omnia-uci-defaults" \ + ADDITIONAL_OPENWRT_PACKAGES="losetup squashfs-tools-unsquashfs resize2fs e2fsprogs parted" \ OPENWRT_TARGET="mvebu/cortexa9" \ EMISSARY_ARCH="armv7" \ OPENWRT_PROFILE="cznic_turris-omnia" \