From 094cef40357ce61cfe034dc25fed51060b656527 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 24 Jan 2014 18:25:48 +0100 Subject: Show a progress bar when creating RAID arrays. --- src/fripost-partman-udeb/base.sh | 66 ++++++++++++++++++++++++++++++- src/fripost-partman-udeb/debian/templates | 12 +++++- 2 files changed, 74 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/fripost-partman-udeb/base.sh b/src/fripost-partman-udeb/base.sh index 976cfb6..8080bc0 100644 --- a/src/fripost-partman-udeb/base.sh +++ b/src/fripost-partman-udeb/base.sh @@ -1,5 +1,5 @@ # Functions commonly used by fripost-partman shell scripts -# Copyright © 2013 Guilhem Moulin +# Copyright © 2013,2014 Guilhem Moulin # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -596,9 +596,71 @@ getIPv4() { fripost_rmpart () { local device="$1" part="$2" - n=$( /sbin/parted -sm "$device" p + n=$( /sbin/parted -sm "$device" p \ | sed -nr "/^[0-9].*:$part:[^:]*;$/ s/:.*//p" ) [ "$n" ] || return log "Removing partition $n ($part) from $device" /sbin/parted -sm "$device" rm "$n" } + + + +############################################################################## +# Create a RAID aray; add a progress bar to mdadm(8) --create +# +# Usage: fripost_mdadm_create device mdadm_options +# (equivalent to mdadm --create device mdadm_options) + +fripost_mdadm_create() { + local md="$1"; shift + local device level devices size info n= + + /sbin/modprobe -v md_mod + [ -e /proc/mdstat ] || fail "/proc/mdstat missing" + + log "Creating RAID device $md with $@" + /sbin/mdadm --create "$md" "$@" + + wait_for_device "$md" + device=$(/usr/bin/readlink -f "$md") + device="${device#/dev/}" + + level=$(sed -nr "/^$device\s*:/ s/.*:\s*active (\S+) .*/\1/p" /proc/mdstat) + devices=$(sed -nr "/^$device\s*:/ s/.*:\s*active \S+ //p" /proc/mdstat) + size=$(sed -nr "/^$device\s*:/ {n; s/^\s*([0-9]+)\s+blocks\s.*/\1/p}" /proc/mdstat) + info=$(sed -nr "/^$device\s*:/ {n; s/^.*\s(super\s.*)/\1/p}" /proc/mdstat) + if ! [ "$level" -a "$devices" -a "$size" -a "$info" ] && [ $size -gt 0 ]; then + log < /proc/mdstat + fail "Couldn't find entry $device ($md) in /proc/mdstat" + fi + + db_subst fripost/mdadm_create_progress_title MD "$md" + db_subst fripost/mdadm_create_progress_title LEVEL $level + db_subst fripost/mdadm_create_progress_title DEVICES "$devices" + db_progress START 0 $size fripost/mdadm_create_progress_title + + db_subst fripost/mdadm_create_progress_info CURRENT 0 + db_subst fripost/mdadm_create_progress_info SIZE $size + db_subst fripost/mdadm_create_progress_info INFO "$info" + db_progress INFO fripost/mdadm_create_progress_info + + while sed -nr "/^$device\s*:/ { p; :l; n; /^\s+\S/ {p; b l;} q }" /proc/mdstat \ + | grep -q '\bresync\b'; do + n=$(sed -nr "/^$device\s*:/ { + :l; n + s#^\s.*\sresync\s*=\s*[0-9.]+%\s*\(([0-9]+)/$size\).*#\1#p + /^\s+\S/ b l; q + }" /proc/mdstat) + if [ "$n" ]; then + db_subst fripost/mdadm_create_progress_info CURRENT $n + db_progress INFO fripost/mdadm_create_progress_info + db_progress SET $n + fi + sleep 1 + done + db_progress SET $size; sleep 0.25 + + db_progress STOP + db_unregister fripost/mdadm_create_progress_title + db_unregister fripost/mdadm_create_progress_info +} diff --git a/src/fripost-partman-udeb/debian/templates b/src/fripost-partman-udeb/debian/templates index 4f4d177..3f94e14 100644 --- a/src/fripost-partman-udeb/debian/templates +++ b/src/fripost-partman-udeb/debian/templates @@ -4,7 +4,15 @@ Description: Seeding /dev/urandom with ${BYTES} bytes from /dev/random Template: fripost/seed_urandom_progress_info Type: text -Description: This may take a while +Description: This may take some time. + +Template: fripost/mdadm_create_progress_title +Type: text +Description: Creating ${LEVEL} array on ${MD} with ${DEVICES} + +Template: fripost/mdadm_create_progress_info +Type: text +Description: ${CURRENT}/${SIZE} blocks ${INFO} Template: debian-installer/fripost-partman/title Type: text @@ -80,7 +88,7 @@ Description: Generating volume key Template: fripost/cryptsetup-genkey_progress_info Type: text -Description: This will take a while if it drains the entropy pool +Description: This may take some time. Template: fripost/mkfs_progress_title Type: text -- cgit v1.2.3