1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#!/bin/sh
set -e
. /lib/partman/lib/base.sh
ORIG_IFS="$IFS"
is_inactive_md() {
local number
number=$(echo "$1" | sed -n -e 's,/dev/md/\?,,p')
if [ "$number" ] && ! grep -q "^md$number : active" /proc/mdstat; then
return 0
fi
return 1
}
part_of_sataraid () {
local raiddev
for raiddev in $(dmraid -r -c); do
if [ "$(readlink -f $raiddev)" = $1 ]; then
return 0
fi
done
return 1
}
part_of_multipath() {
local mpdev
type multipath >/dev/null 2>&1 || return 1
if is_multipath_part $1; then
return 0
fi
# The block devices that make up the multipath:
# Output looks like \_ 4:0:0:1 sdc 8:32 ...
for mpdev in $(multipath -l | \
grep '_ \([#0-9]\+:\)\{3\}[#0-9]\+ [hs]d[a-z]\+ [0-9]\+:[0-9]\+' | \
cut -f4 -d' '); do
if [ "$(readlink -f /dev/$mpdev)" = $1 ]; then
return 0
fi
done
return 1
}
if [ ! -f /var/run/parted_server.pid ]; then
mkdir -p /var/run
parted_server
RET=$?
if [ $RET != 0 ]; then
# TODO: How do we signal we couldn't start parted_server properly?
exit $RET
fi
rm -rf /var/lib/partman/old_devices
if [ -d $DEVICES ]; then
mv $DEVICES /var/lib/partman/old_devices
fi
mkdir $DEVICES || true
IFS="$NL"
for partdev in $(parted_devices |
sed 's,^/dev/\(ide\|scsi\|[hs]d\|md/\?[0-9]\+\),!/dev/\1,' |
sort |
sed 's,^!,,' ); do
IFS="$TAB"
set -- $partdev
IFS="$ORIG_IFS"
device=$1
size=$2
model=$3
# Skip mtd devices since they aren't supported by parted
if echo $device | grep -q '/dev/mtd'; then
continue
fi
# Skip MD devices which are not active
if [ -e /proc/mdstat ]; then
if is_inactive_md $device; then
continue
fi
fi
# Skip devices that are part of a dmraid device
if type dmraid >/dev/null 2>&1; then
if part_of_sataraid $device; then
continue
fi
fi
# Skip devices that are part of a multipathed device
if part_of_multipath $device; then
continue
fi
dirname=$(echo $device | sed 's:/:=:g')
dev=$DEVICES/$dirname
if [ -d /var/lib/partman/old_devices/$dirname ]; then
mv /var/lib/partman/old_devices/$dirname $dev
else
mkdir $dev || continue
fi
printf "%s" "$device" >$dev/device
printf "%s" "$size" >$dev/size
printf "%s" "$model" >$dev/model
# Set the sataraid flag for dmraid arrays.
if type dmraid >/dev/null 2>&1; then
if dmraid -sa -c | grep -q $(basename $device); then
>$dev/sataraid
fi
fi
cd $dev
open_dialog OPEN "$(cat $dev/device)"
read_line response
close_dialog
if [ "$response" = failed ]; then
cd /
rm -rf $dev
fi
done
rm -rf /var/lib/partman/old_devices
fi
|