2018-09-01 15:16:22 +02:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
2019-06-12 16:27:49 +02:00
|
|
|
# Determine partition and hard drive paths
|
|
|
|
UUID=$(/usr/bin/awk '{print substr($2,6)}' /etc/crypttab)
|
|
|
|
PART=$(/sbin/blkid -U ${UUID})
|
|
|
|
DISK=${PART%?}
|
|
|
|
DEV=$(/usr/bin/basename ${DISK})
|
|
|
|
|
2018-09-01 15:16:22 +02:00
|
|
|
# No resizing with less than 10k unused blocks
|
2019-06-12 16:27:49 +02:00
|
|
|
BLOCKS_FREE=$(/usr/bin/awk -v dev="${DEV}" '{if ($0 ~ dev "$") blocks = $3} {if ($0 ~ dev "[0-9]") blocks -= $3} END {print blocks}' /proc/partitions)
|
2018-09-01 15:16:22 +02:00
|
|
|
[ ${BLOCKS_FREE} -lt 10240 ] && exit 0
|
|
|
|
|
|
|
|
# Resize physical partition
|
|
|
|
# Force busybox fdisk as util-linux fdisk breaks subsequent partx command
|
2019-06-12 16:27:49 +02:00
|
|
|
cat <<EOF | /bin/busybox fdisk ${DISK} || /bin/true
|
2018-09-01 15:16:22 +02:00
|
|
|
d
|
|
|
|
2
|
|
|
|
n
|
|
|
|
p
|
|
|
|
2
|
|
|
|
|
|
|
|
|
|
|
|
t
|
|
|
|
2
|
|
|
|
8e
|
|
|
|
w
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Re-read partition table
|
2019-06-12 16:27:49 +02:00
|
|
|
/usr/sbin/partx -u ${PART}
|
2018-09-01 15:16:22 +02:00
|
|
|
|
|
|
|
# Resize dmcrypt and LVM PV
|
|
|
|
/sbin/cryptsetup resize system
|
|
|
|
/sbin/pvresize /dev/mapper/system
|
|
|
|
|
|
|
|
# Create swap if it doesn't exist
|
|
|
|
if [ ! -e /dev/vg0/swap ]; then
|
|
|
|
/sbin/lvcreate -L 4G vg0 -n swap
|
|
|
|
/sbin/mkswap /dev/vg0/swap
|
2018-10-31 23:09:24 +01:00
|
|
|
/sbin/swapon /dev/vg0/swap
|
2018-09-01 15:16:22 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Extend LV and underlying filesystem
|
|
|
|
/sbin/lvextend -l +100%FREE vg0/root
|
|
|
|
/usr/sbin/resize2fs /dev/vg0/root
|