summaryrefslogtreecommitdiffstats
path: root/builder
diff options
context:
space:
mode:
authorJonathan Bauer2019-08-01 14:57:06 +0200
committerJonathan Bauer2019-08-01 14:57:06 +0200
commit59c09749709df2537a7df06f979bf1880ea140b4 (patch)
tree7cd3c0cf0e392260192141fe5385065358cad169 /builder
parent[slx-tools] fix first time build (diff)
downloadsystemd-init-59c09749709df2537a7df06f979bf1880ea140b4.tar.gz
systemd-init-59c09749709df2537a7df06f979bf1880ea140b4.tar.xz
systemd-init-59c09749709df2537a7df06f979bf1880ea140b4.zip
[slx-dmsetup] auto increase size of rootfs
Diffstat (limited to 'builder')
-rwxr-xr-xbuilder/modules.d/slx-dmsetup/module-setup.sh13
-rwxr-xr-xbuilder/modules.d/slx-dmsetup/scripts/dmsetup-slx-device2
-rw-r--r--builder/modules.d/slx-dmsetup/scripts/grow-rootfs.sh45
3 files changed, 54 insertions, 6 deletions
diff --git a/builder/modules.d/slx-dmsetup/module-setup.sh b/builder/modules.d/slx-dmsetup/module-setup.sh
index 57a67626..596c12db 100755
--- a/builder/modules.d/slx-dmsetup/module-setup.sh
+++ b/builder/modules.d/slx-dmsetup/module-setup.sh
@@ -6,12 +6,15 @@ depends() {
echo ""
}
install() {
- # install helpers
- inst "$moddir/scripts/dmsetup-slx-device" "/usr/bin/dmsetup-slx-device"
- # install hooks
+ inst "$moddir/scripts/dmsetup-slx-device" "/usr/local/bin/dmsetup-slx-device"
+
inst_hook pre-pivot 10 "$moddir/scripts/generate-fstab-swap.sh"
- inst_multiple head tail mkfs.ext4 mkfs.xfs fsck.ext4 fsck.xfs blockdev xxd
+ inst_hook pre-pivot 00 "$moddir/scripts/grow-rootfs.sh"
+ # deliberatly left ext helpers out for now, since we don't really use it.
+ inst_multiple blockdev xxd \
+ xfs_repair xfs_growfs
}
installkernel() {
- instmods dm-thin-pool dm-snapshot dm-crypt crc32c ext4 xfs
+ # install those modules in case the used kernel does not have them builtin
+ instmods dm-thin-pool dm-snapshot dm-crypt crc32c xfs
}
diff --git a/builder/modules.d/slx-dmsetup/scripts/dmsetup-slx-device b/builder/modules.d/slx-dmsetup/scripts/dmsetup-slx-device
index 740445bb..9dc8b71d 100755
--- a/builder/modules.d/slx-dmsetup/scripts/dmsetup-slx-device
+++ b/builder/modules.d/slx-dmsetup/scripts/dmsetup-slx-device
@@ -410,7 +410,7 @@ if [ -n "$thin_snapshot" ] || [ -n "$thin_volume" ]; then
# create thin-snapshot, use first one
read -r name crypt min max ignore <<< "$thin_snapshot"
# min/max was used for the pool data device, ignore it here!
- if ! create_volume "$name 1 $read_only_device_size $read_only_device"; then
+ if ! create_volume "$name 1 $writable_device_size $read_only_device"; then
echo "Failed to create external snapshot for '$read_only_device'."
ramdisk_fallback
fi
diff --git a/builder/modules.d/slx-dmsetup/scripts/grow-rootfs.sh b/builder/modules.d/slx-dmsetup/scripts/grow-rootfs.sh
new file mode 100644
index 00000000..d76e6ab0
--- /dev/null
+++ b/builder/modules.d/slx-dmsetup/scripts/grow-rootfs.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+# This tried to call growfs helpers (xfs_growfs, resize2fs, ...) to resize
+# the root filesystem mounted on $NEWROOT to the maximum size of the backing
+# disk partition (done by dmsetup-slx-device).
+
+. /etc/openslx
+
+declare -Ag growfs_helpers growfs_targets growfs_opts
+# xfs
+growfs_helpers[xfs]="xfs_growfs"
+growfs_targets[xfs]="$NEWROOT"
+growfs_opts[xfs]="-d"
+# ext4
+growfs_helpers[ext4]="resize2fs"
+growfs_targets[ext4]="$SLX_DNBD3_DEVICE_COW"
+growfs_opts[ext4]=""
+
+resize_rootfs() {
+ # First let's check what filesystem it is
+ local fstype="$(blkid "$SLX_DNBD3_DEVICE_COW" | grep -oE 'TYPE=\S+')"
+ if [ -z "$fstype" ]; then
+ echo "Failed to detect filesystem on '$SLX_DNBD3_DEVICE_COW' - ignoring."
+ return 1
+ fi
+ fstype="${fstype#TYPE=}"
+ fstype="${fstype//\"/}"
+ if [ ! "${growfs_helpers[${fstype}]+set}" ]; then
+ echo "'$fstype' not supported - ignoring."
+ return 1
+ fi
+ if ! hash "${growfs_helpers[${fstype}]}" &> /dev/null; then
+ echo "'$fstype' is supported, but cannot find helper binary - ignoring."
+ return 1
+ fi
+ if ! "${growfs_helpers[${fstype}]}" "${growfs_opts[$fstype]}" "${growfs_targets[$fstype]}"; then
+ echo "Failed to run '${growfs_helpers[${fstype}]}' on '${growfs_targets[$fstype]}'."
+ return 1
+ fi
+ return 0
+}
+
+[ -b "$SLX_DNBD3_DEVICE_COW" ] && resize_rootfs
+# non-critical, so always fake success
+true