From 63182a02e4951d02df57b025979687b960d604eb Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 10 Feb 2016 14:02:28 +1100 Subject: [PATCH] Refactor growroot for debuggabilty This is a slight refactor I found useful when debugging. The udevadmin info query will be visbile in the output of "set -x" which helps, and is the logs/journal. We can also reduce some calls by keeping the value and just grepping with a herefile. This also does some error checking and bails out if it does not see what it needs to continue. Change-Id: I39c4d262f9c5ce53f6b83d95b1363a74834cf2c8 --- .../growroot/static/usr/local/sbin/growroot | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/elements/growroot/static/usr/local/sbin/growroot b/elements/growroot/static/usr/local/sbin/growroot index 7600a9db..ef818c01 100755 --- a/elements/growroot/static/usr/local/sbin/growroot +++ b/elements/growroot/static/usr/local/sbin/growroot @@ -6,10 +6,26 @@ set -o pipefail root_dev=$(df -P / | tail -n 1 | awk '/.*/ { print $1 }') -disk=$(find /sys/dev/block -name $(udevadm info --query=all --name $root_dev | grep ID_PART_ENTRY_DISK | cut -d= -f2)) -disk="/dev/$(source ${disk}/uevent; echo $DEVNAME)" +if [ -z "${root_dev}" ]; then + echo "*** Root device not found?" + exit 1 +fi -part_no=$(udevadm info --query=all --name $root_dev | grep ID_PART_ENTRY_NUMBER | cut -d= -f2) +udev_root=$(udevadm info --query=all --name $root_dev) + +part=$(grep ID_PART_ENTRY_DISK <<< "${udev_root}" | cut -d= -f2) +if [ -z "${part}" ]; then + echo "*** Root partition not found!" + exit 1 +fi +part_no=$(grep ID_PART_ENTRY_NUMBER <<< "${udev_root}" | cut -d= -f2) +if [ -z "${part_no}" ]; then + echo "*** Root partition number not found!" + exit 1 +fi + +disk=$(find /sys/dev/block -name ${part}) +disk="/dev/$(source ${disk}/uevent; echo $DEVNAME)" set +e growpart $disk $part_no