From 525a507d3fe88ece2c12b9e389f0a6daa42b474f Mon Sep 17 00:00:00 2001 From: laurencegill Date: Tue, 7 Jun 2016 15:34:00 +0100 Subject: [PATCH] Update 05-grow-rootfs Try to handle lvm root partitions, only tested on centos7 atm --- base.one/etc/one-context.d/05-grow-rootfs | 69 ++++++++++++++--------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/base.one/etc/one-context.d/05-grow-rootfs b/base.one/etc/one-context.d/05-grow-rootfs index d970d2e..00d7a8d 100755 --- a/base.one/etc/one-context.d/05-grow-rootfs +++ b/base.one/etc/one-context.d/05-grow-rootfs @@ -1,34 +1,51 @@ -#!/bin/bash +#!/bin/sh +set -e +MOUNT_LINE=$(cat /etc/mtab | grep ' / ' | grep -v '^rootfs') +DEVICE=$(echo "$MOUNT_LINE" | cut -d' ' -f1) +FSTYPE=$(echo "$MOUNT_LINE" | cut -d' ' -f3) GROWPART=$(which growpart) -if [[ ${?} -ne 0 ]] -then - echo "Skipping growfs, growpart command is missing" -else - MOUNT_LINE=$(cat /etc/mtab | grep ' / ' | grep -v '^rootfs') - DEVICE=$(echo "$MOUNT_LINE" | cut -d' ' -f1) - DEVICE=$(readlink -f "$DEVICE") - FSTYPE=$(echo "$MOUNT_LINE" | cut -d' ' -f3) +if [ $? -ne 0 ]; then + echo "growpart command is missing" + exit 1 +fi +if [ $(grep mapper /etc/fstab |grep ' / ' |wc -l) -eq 0 ]; then + DEVICE=$(readlink -f "$DEVICE") DISK=$(echo "$DEVICE" | sed 's/.$//') PARTITION=$(echo "$DEVICE" | sed "s|^$DISK||") + LVM="no" +fi + +if [ "${LVM}" != "no" ]; then + PVRESIZE=$(which pvresize) + LVEXTEND=$(which lvextend) + DISK=$(pvdisplay |grep "PV Name"|awk '{print $3}'|sed 's/.$//') + PARTITION=$(pvdisplay |grep "PV Name"|awk '{print $3}'| sed "s|^${DISK}||") + PV=$(pvdisplay |grep "PV Name"|awk '{print $3}') + LV=$(lvdisplay ${DEVICE} |grep "LV Path"|awk '{print $3}') +fi - if [ -n $DEBUG ]; then - echo DEVICE: $DEVICE - echo FSTYPE: $FSTYPE - echo DISK: $DISK - echo PARTITION: $PARTITION - fi - - growpart "$DISK" "$PARTITION" - - case "$FSTYPE" in - ext2|ext3|ext4) - resize2fs "$DEVICE" - ;; - xfs) - xfs_growfs / - ;; - esac +if [ -n "$DEBUG" ]; then + echo DEVICE: ${DEVICE} + echo FSTYPE: ${FSTYPE} + echo DISK: ${DISK} + echo PARTITION: ${PARTITION} fi + +${GROWPART} ${DISK} ${PARTITION} + +if [ "${LVM}" != "no" ]; then + ${PVRESIZE} ${PV} + ${LVEXTEND} -l +100%FREE ${LV} +fi + +case "${FSTYPE}" in + ext2|ext3|ext4) + resize2fs ${DEVICE} + ;; + xfs) + xfs_growfs / + ;; +esac