1 |
#!/bin/sh |
2 |
|
3 |
set -x |
4 |
exec 2>&1 |
5 |
|
6 |
device=$(sed -n 's|.*[0-9]\s\+\([^ ]\+[^0-9]\)$|\1|p;s#.*[0-9]\s\+\(\(rd\|ida\|cciss\|i2o\)/.*[^0-9p][0-9]\+\)$#\1#p' /proc/partitions | head -1) |
7 |
|
8 |
if [ -n "$device" ] |
9 |
then |
10 |
sfdisk -d /dev/$device > /tmp/oldparts |
11 |
sed 's/Id=8[32]/Id=fd/' /tmp/oldparts > /tmp/newparts |
12 |
|
13 |
mkdir /mnt/tmp |
14 |
for part in $(awk '/^\/dev\/.*Id=8[23]/{ print $1 }' /tmp/oldparts) |
15 |
do |
16 |
md=/dev/md$(echo $part | sed 's|^.*[^0-9]||') |
17 |
|
18 |
if grep -q "^$part .*Id=83" /tmp/oldparts |
19 |
then |
20 |
e2fsck -f -C0 $part |
21 |
partsize=$(resize2fs -f $part 2>&1| sed -n 's|.* \([0-9]\+\) blocks long.*|\1|p') |
22 |
resize2fs -fp $part $(($partsize-72)) |
23 |
fi |
24 |
|
25 |
mdadm -C $md -l 1 -n 2 -R $part missing |
26 |
echo "DEVICE $part" >> /tmp/mdadm.conf |
27 |
|
28 |
if grep -q "^$part .*Id=83" /tmp/oldparts |
29 |
then |
30 |
e2fsck -f -C0 $md |
31 |
resize2fs -fp $md |
32 |
|
33 |
mount $md /mnt/tmp |
34 |
[ -r /mnt/tmp/etc/fstab ] && root=$md |
35 |
umount /mnt/tmp |
36 |
|
37 |
|
38 |
elif grep -q "^$part .*Id=82" /tmp/oldparts |
39 |
then |
40 |
mkswap $md |
41 |
fi |
42 |
done |
43 |
|
44 |
echo >> /tmp/mdadm.conf |
45 |
mdadm -Es -c /tmp/mdadm.conf >> /tmp/mdadm.conf |
46 |
|
47 |
if [ -n "$root" ] |
48 |
then |
49 |
mount $root /mnt/tmp |
50 |
sed -i "s|/dev/$device\([0-9]\+\)|/dev/md\1|" /mnt/tmp/etc/fstab |
51 |
cp /tmp/mdadm.conf /mnt/tmp/etc/mdadm.conf |
52 |
umount /mnt/tmp |
53 |
fi |
54 |
rmdir /mnt/tmp |
55 |
|
56 |
mdadm --stop --scan |
57 |
|
58 |
sfdisk --force /dev/$device < /tmp/newparts |
59 |
fi |