aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2014-01-24 18:25:48 +0100
committerGuilhem Moulin <guilhem@fripost.org>2015-06-07 04:28:01 +0200
commit094cef40357ce61cfe034dc25fed51060b656527 (patch)
treecb7144650e11401c0c9c7e319560249dbc899c0d
parenta6a742628b560f9d5097008940547391831762c0 (diff)
Show a progress bar when creating RAID arrays.
-rwxr-xr-xinclude/partition.sh26
-rw-r--r--src/fripost-partman-udeb/base.sh66
-rw-r--r--src/fripost-partman-udeb/debian/templates12
3 files changed, 84 insertions, 20 deletions
diff --git a/include/partition.sh b/include/partition.sh
index 1d5b4c3..d487b02 100755
--- a/include/partition.sh
+++ b/include/partition.sh
@@ -1,7 +1,7 @@
#!/bin/sh
# Simple partitioning shell script.
-# Copyright © 2013 Guilhem Moulin <guilhem@fripost.org>
+# Copyright © 2013,2014 Guilhem Moulin <guilhem@fripost.org>
#
# 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
@@ -22,8 +22,8 @@ set -ue
#device=/dev/sda
device='/dev/sda /dev/sdb' # space-separated form mutiple disks (raid)
-raidLevel=1 # raid level (leave empty for no raid)
-raidActiveDev=2 # number active devices in the array
+raidLevel=raid1 # raid level (leave empty for no raid)
+raidNumActiveDevices=2 # number of active devices in the array
n=0
@@ -90,24 +90,18 @@ for d in $device; do
done
# Create an array on top of that
-if [ ${raidLevel:-} -a ${raidActiveDev:-} ]; then
+if [ ${raidLevel:-} ]; then
[ -d /dev/md ] || mkdir /dev/md
- /sbin/modprobe -v md_mod
- [ -e /proc/mdstat ] || fail "/proc/mdstat missing"
- log "Creating RAID device /dev/md/boot with $part_boot"
- mdadm --create /dev/md/boot \
- -f -R -l raid$raidLevel -n $raidActiveDev \
- $part_boot
+ devices="$part_boot"
part_boot=/dev/md/boot
- wait_for_device $part_boot
+ fripost_mdadm_create "$part_boot" -f -R -l $raidLevel \
+ ${raidNumActiveDevices:+-n $raidNumActiveDevices} $devices
- log "Creating RAID device /dev/md/system with $part_system"
- mdadm --create /dev/md/system \
- -f -R -l raid$raidLevel -n $raidActiveDev \
- $part_system
+ devices="$part_system"
part_system=/dev/md/system
- wait_for_device $part_system
+ fripost_mdadm_create "$part_system" -f -R -l $raidLevel \
+ ${raidNumActiveDevices:+-n $raidNumActiveDevices} $devices
# They were only meant to preserve alignment accross physical
# devices.
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 <guilhem@fripost.org>
+# Copyright © 2013,2014 Guilhem Moulin <guilhem@fripost.org>
#
# 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