Adopting the solution for resizing root from openwrt expand_root guide

This commit is contained in:
Lee Miller 2023-12-05 04:02:57 +02:00
parent 163a547051
commit 5c990c3fcd
Signed by: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
4 changed files with 51 additions and 0 deletions

View File

@ -118,6 +118,7 @@ chmod 0400 files/etc/dropbear/authorized_keys
mkdir -p files/etc/docker
chmod 0750 files/etc/docker
cp ${pwd}/daemon.json files/etc/docker
cp ${pwd}/sysupgrade.conf files/etc
mkdir -p files/etc/uci-defaults
cp ${pwd}/defaults/* files/etc/uci-defaults

21
defaults/70-rootpt-resize Normal file
View File

@ -0,0 +1,21 @@
# Copied from https://openwrt.org/docs/guide-user/advanced/expand_root
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 -l ---pretend-input-tty << EOI
ok
fix
EOI
parted -s "${ROOT_DISK}" \
resizepart "${ROOT_PART}" 100%
mount_root done
touch /etc/rootpt-resize
reboot
fi
exit 1

24
defaults/80-rootfs-resize Normal file
View File

@ -0,0 +1,24 @@
# Copied from https://openwrt.org/docs/guide-user/advanced/expand_root
if [ ! -e /etc/rootfs-resize ] \
&& [ -e /etc/rootpt-resize ] \
&& type losetup > /dev/null \
&& type resize.f2fs > /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
resize.f2fs "${LOOP_DEV}"
mount_root done
touch /etc/rootfs-resize
reboot
fi
exit 1

5
sysupgrade.conf Normal file
View File

@ -0,0 +1,5 @@
## This file contains files and directories that should
## be preserved during an upgrade.
/etc/uci-defaults/70-rootpt-resize
/etc/uci-defaults/80-rootfs-resize