summaryrefslogtreecommitdiffstats
path: root/modules.d/slx-dmsetup/scripts/grow-rootfs.sh
blob: e2603835818d8cbc209634d13b0cdea2dbc132d4 (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
#!/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
} &> /run/openslx/rootfs-grow.log

[ -b "$SLX_DNBD3_DEVICE_COW" ] && resize_rootfs
# non-critical, so always fake success
true