Page MenuHomePhabricator
Paste P8961

md-tools.sh
ActivePublic

Authored by CDanis on Aug 22 2019, 5:24 PM.
#!/bin/bash
# to "minify":
# echo echo $(gzip -c md_tools.sh | base64 -w0) '| base64 -d | zcat | sudo bash'
set -eu
# given a filesystem path, returns its associated block device
fs_to_dev() {
df "$1" | tail -n1 | cut -f1 -d' '
}
# given a mdN device name, return all the associated sdXn block device names
md_to_disks() {
ls -1 /sys/block/"$1"/slaves
}
# e.g. sda1 --> sda
partition_to_disk() {
echo "$1" | sed 's/[0-9]*$//'
}
FULLBOOTDEV="$(fs_to_dev /boot)"
BOOTDEV="$(basename $FULLBOOTDEV)"
if [[ "$FULLBOOTDEV" == "/dev/mapper"* ]]; then
# /boot uses LVM; find the name of the device mapper's device
DMNAME="$(basename $(readlink -f $FULLBOOTDEV))"
# and then map that to its underlying md device
BOOTDEV="$(md_to_disks $DMNAME)"
if [[ $BOOTDEV == *" "* ]]; then
echo "ERROR: /boot is backed by $DMNAME with multiple slaves $BOOTDEV"
exit 2
fi
fi
if [[ "$BOOTDEV" != "md"* ]]; then
echo "exclude: /boot is not backed by a md device"
exit 0
fi
for DEV in $(md_to_disks $BOOTDEV); do
DISK=$(partition_to_disk $DEV)
if head -c512 /dev/$DISK | grep -q GRUB; then
#echo -e "$DISK\tyes-GRUB"
true
else
#echo -e "$DISK\tno"
echo "bad"
exit 0
fi
done
echo "good-grub"

Event Timeline

CDanis created this paste.Aug 22 2019, 5:24 PM