summaryrefslogtreecommitdiffstats
path: root/core/modules/bwlp-stage4-tweaks/data/opt/openslx/scripts/systemd-grow_rootfs
blob: a1b9d22a308fe63d5d00f6cdbf72d9cd58601f41 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash

# This tries 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).

. /opt/openslx/config

if [ -z "$SLX_DNBD3_DEVICE_COW" ]; then
	SLX_DNBD3_DEVICE_COW="$( awk '$2 == "/" {print $1; exit}' /proc/mounts )"
fi
if ! [ -b "$SLX_DNBD3_DEVICE_COW" ]; then
	echo "Cannot grow rootfs on '$SLX_DNBD3_DEVICE_COW' - not a block device"
	exit 0
fi

resize_rootfs() {
	# First let's check what filesystem it is
	local fstype helper
	declare -a options
	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//\"/}"
	case "$fstype" in
	ext?)
		helper="resize2fs"
		options=()
		;;
	xfs)
		helper="xfs_growfs"
		options=( "-d" )
		;;
	*)
		echo "'$fstype' not supported - ignoring."
		return 1
		;;
	esac
	if ! hash "${helper}" &> /dev/null; then
		echo "'$fstype' is supported, but cannot find helper binary - ignoring."
		return 1
	fi
	if ! "${helper}" "${options[@]}" "$SLX_DNBD3_DEVICE_COW"; then
		echo "Failed to run '${helper}' on '${SLX_DNBD3_DEVICE_COW}'."
		return 1
	fi
	return 0
}

resize_rootfs