Leonid Flaks wrote:
Jeff Schroeder wrote:
> Here is an example /proc/partitions for you to look at on an HP server:
> major minor #blocks name
>
> 104 0 292935982 cciss/c0d0
> 104 1 265041 cciss/c0d0p1
> 104 2 8385930 cciss/c0d0p2
> 104 3 284278207 cciss/c0d0p3
> 104 16 1464678702 cciss/c0d1
>
> While much uglier to look at, this works in all cases I could throw at
> it including the two mentioned above:
> awk '{if ($NF !~ "name" && $NF ~ "^[a-zA-Z]") print
$NF}'
> /proc/partitions | sed -e 's:^:/dev/:g'
>
> Does this look ok to you?
You can the modify print to put /dev/ in it, so no need for sed ;-)
awk '{if ($NF !~ "name" && $NF ~ "^[a-zA-Z]") print
"/dev/"$NF}'
/proc/partitions
After looking at the partitions example above one more time I suggest
another modification to awk line above:
awk '{if ($NF ~ "^[a-zA-Z].*[0-9]$") print "/dev/"$NF}'
/proc/partitions
That would eliminate /dev/sda from the list, but keep /dev/sda1. Do
partition names on all exotic raid arrays end with digit like in this
example above? If the answer is yes, see attached patch.
Leon
diff --git a/snippets/keep_ssh_host_keys b/snippets/keep_ssh_host_keys
index 527c992..f079207 100644
--- a/snippets/keep_ssh_host_keys
+++ b/snippets/keep_ssh_host_keys
@@ -10,11 +10,7 @@ insmod /lib/ext3.o
mkdir -p /tmp/ssh
-drives=$(list-harddrives | awk '{print $1}')
-for disk in $drives; do
- DISKS="$DISKS $(fdisk -l /dev/$disk | awk '/^\/dev/{print $1}')"
-done
-
+DISKS=$(awk '{if ($NF ~ "^[a-zA-Z].*[0-9]$") print
"/dev/"$NF}' /proc/partitions)
# Try to find the keys on ordinary partitions
for disk in $DISKS; do
name=$(basename $disk)
@@ -33,6 +29,28 @@ for disk in $DISKS; do
rm -r /tmp/$name
done
+# Try software RAID
+if [ "$keys_found" = "no" ]; then
+ if mdadm -As; then
+ RDISKS="$(awk '/md/{print $1}' /proc/mdstat)"
+ for rdisk in $RDISKS; do
+ mkdir -p /tmp/$rdisk
+ mount /dev/$rdisk /tmp/$rdisk
+ [ $? -eq 0 ] || continue # Skip to the next partition if the mount fails
+ # Copy current ssh host keys out to be reused
+ if [ -d /tmp/${rdisk}/etc/ssh ]; then
+ cp -a /tmp/${rdisk}/etc/ssh/ssh_host* /tmp/ssh
+ keys_found="yes"
+ umount /tmp/$rdisk
+ break
+ fi
+ umount /tmp/$rdisk
+ rm -r /tmp/$rdisk
+ done
+ fi
+fi
+
+
# Try LVM if that didn't work
if [ "$keys_found" = "no" ]; then
lvm lvmdiskscan