#!/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_mdraid () { local holder local dev=${1#/dev/} for holder in /sys/block/$dev/holders/*; do local mddev=${holder##*/} case "$mddev" in md[0-9]|md[0-9][0-9]|md[0-9][0-9][0-9]) return 0 ;; esac 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 "(decoration-symbols) 4:0:0:1 sdc 8:32 ..." # (decoration-symbols are not matched; they may change again, and the spaces differ for last device) for mpdev in $(multipath -l | \ grep -o '\([#0-9]\+:\)\{3\}[#0-9]\+ [hs]d[a-z]\+ [0-9]\+:[0-9]\+' | \ cut -f2 -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 db_get partman/alignment PARTMAN_ALIGNMENT="$RET" 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\|[hsw]d\|md/\?[0-9]\+\),!/dev/\1,' | sort | sed 's,^!,,' ); do IFS="$TAB" set -- $partdev IFS="$ORIG_IFS" device=$1 size=$2 model=$3 label=$4 # Skip mtd (not supported by parted) and mmcblk odities case "${device#/dev/}" in mtd* | mmcblk?rpmb | mmcblk?boot? ) continue ;; esac # 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 mdraid device if part_of_mdraid $device; then continue 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 printf "%s" "$label" >$dev/label 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