This repository has been archived by the owner on Sep 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
/
extend-filesystems
executable file
·55 lines (48 loc) · 1.7 KB
/
extend-filesystems
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
54
55
#!/bin/bash
# Automatic resize of btrfs and ext4 filesystems.
#
# The only partitions that may be considered:
# - GPT partitions with the 'coreos-resize'
# - Have a btrfs, ext4 or xfs filesystem mounted read-write
# - Have at least 2MB of unpartitioned space to grow into (cgpt default)
#
# This last restriction means that if cgpt resize succeeds in extending
# the partition but the filesystem resize fails the operation will not
# be re-attempted by this script later unless the disk grows even more.
set -e -o pipefail
COREOS_RESIZE="3884dd41-8582-4404-b9a8-e9b84f2df50e"
declare -a DEV_LIST
mapfile DEV_LIST < <(lsblk -P -o NAME,PARTTYPE,FSTYPE,MOUNTPOINT)
for dev_info in "${DEV_LIST[@]}"; do
eval "$dev_info"
NAME=${NAME//\!//}
if [[ "${PARTTYPE}" != "${COREOS_RESIZE}" ]] || \
[[ -z "${NAME}" ]] || \
[[ -z "${MOUNTPOINT}" ]] || \
[[ ! -w "${MOUNTPOINT}" ]] || \
[[ "${FSTYPE}" != "btrfs" && "${FSTYPE}" != "ext4" && "${FSTYPE}" != "xfs" ]]
then
continue
fi
device="/dev/${NAME}"
old_size=$(blockdev --getsz "${device}")
cgpt resize "${device}"
# Only resize filesystem if the partition changed
if [[ "${old_size}" -eq $(blockdev --getsz "${device}") ]]; then
continue
fi
case "${FSTYPE}" in
"btrfs")
# map the device name to the btrfs device id
device_id=$(btrfs filesystem show -d "${device}" | \
awk -v "d=${device}" -e 'd == $8 {print $2}')
btrfs filesystem resize "${device_id}:max" "${MOUNTPOINT}"
;;
"ext4")
resize2fs "${device}"
;;
"xfs")
xfs_growfs "${MOUNTPOINT}"
;;
esac
done