1 |
#!/bin/sh |
#!/bin/sh |
|
set -x |
|
|
|
|
|
# exec 2>&1 >/tmp/raidconvert.out |
|
2 |
|
|
3 |
|
set -x |
4 |
exec 2>&1 |
exec 2>&1 |
5 |
|
|
6 |
# let's assume it's a SCSI system |
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 |
if grep -q 'sda$' /proc/partitions; then |
|
8 |
disk=sda |
if [ -n "$device" ] |
9 |
else |
then |
10 |
# No SCSI Drives is must be IDE |
sfdisk -d /dev/$device > /tmp/oldparts |
11 |
media=`cat /proc/ide/hda/media` |
sed 's/Id=8[32]/Id=fd/' /tmp/oldparts > /tmp/newparts |
12 |
if [ $media == "disk" ] ; then |
|
13 |
disk=hda |
mkdir -p /mnt/tmp |
14 |
fi |
for part in $(awk '/^\/dev\/.*Id=8[23]/{ print $1 }' /tmp/oldparts) |
15 |
fi |
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 |
|
|
27 |
|
if grep -q "^$part .*Id=83" /tmp/oldparts |
28 |
|
then |
29 |
|
e2fsck -f -C0 $md |
30 |
|
resize2fs -fp $md |
31 |
|
|
32 |
|
mount $md /mnt/tmp |
33 |
|
[ -r /mnt/tmp/etc/fstab ] && sed -i "s|/dev/$device\([0-9]\+\)|/dev/md\1|" /mnt/tmp/etc/fstab |
34 |
|
umount /mnt/tmp |
35 |
|
|
36 |
|
|
37 |
|
elif grep -q "^$part .*Id=82" /tmp/oldparts |
38 |
|
then |
39 |
|
mkswap $md |
40 |
|
fi |
41 |
|
done |
42 |
|
rmdir /mnt/tmp |
43 |
|
|
44 |
set $disk |
mdadm --stop --scan |
45 |
found=`echo $#` |
sfdisk --force /dev/$device < /tmp/newparts |
|
if [ $found -gt "0" ] ; then |
|
|
# Dump out current partitions |
|
|
sfdisk -d /dev/$disk > /tmp/oldparts |
|
|
|
|
|
# Check if we have any ext2/3 or swap partitions |
|
|
if grep -q 'Id=8[23]' /tmp/oldparts; then |
|
|
echo -en "\n\nConverting partitions to RAID..." >/dev/tty3 |
|
|
# Convert ext2/3 and swap partitions to raid autodetect |
|
|
sed 's/Id=8[32]/Id=fd/' /tmp/oldparts > /tmp/newparts |
|
|
|
|
|
# Find swap partition for future checks |
|
|
swap=`grep 'Id=82' /tmp/oldparts | sed "s/$disk\([0-9]\+\) :.*/md\1/"` |
|
|
|
|
|
# Loop throught partitions and convert to degraded raid1 |
|
|
for part in `grep 'Id=8[23]' /tmp/oldparts | sed 's/ :.*//'`; do |
|
|
mdpart=`echo $part | sed "s/$disk\([0-9]\+\)/md\1/"` |
|
|
|
|
|
echo -n "$part..." >/dev/tty3 |
|
|
mdadm --create $mdpart --run --level=1 --raid-devices=2 $part missing |
|
|
if [ "$mdpart" == "$swap" ]; then |
|
|
# Recreate swap partition |
|
|
mkswap $swap |
|
|
else |
|
|
# Resize ext2/3 partitions (fix superblock - part 1) |
|
|
resize2fs -f $mdpart |
|
|
fi |
|
|
done |
|
|
|
|
|
echo "done" >/dev/tty3 |
|
|
|
|
|
# Write out new converted partition table |
|
|
sfdisk --force /dev/$disk < /tmp/newparts |
|
|
|
|
|
echo -e "\nChecking filesystems on converted partitions. This may take a while." >/dev/tty3 |
|
|
|
|
|
mkdir /mnt/tmp |
|
|
for part in `grep 'Id=fd' /tmp/newparts | sed "s/$disk\([0-9]\+\) :.*/md\1/"`; do |
|
|
if [ "$part" != "$swap" ]; then |
|
|
# Resize ext2/3 partitions (fix superblock - part 2) |
|
|
echo -e "\n\nChecking $part..." >/dev/tty3 |
|
|
e2fsck -f -C0 $part >/dev/tty3 |
|
|
|
|
|
# Check for /etc/fstab on partitions and convert entries |
|
|
mount $part /mnt/tmp |
|
|
if [ -r /mnt/tmp/etc/fstab ]; then |
|
|
cat /mnt/tmp/etc/fstab | sed "s/$disk\([0-9]\+\)/md\1/" \ |
|
|
> /mnt/tmp/etc/fstab.tmp |
|
|
mv /mnt/tmp/etc/fstab.tmp /mnt/tmp/etc/fstab |
|
|
fi |
|
|
umount /mnt/tmp |
|
|
fi |
|
|
done |
|
|
rmdir /mnt/tmp |
|
|
mdadm --stop --scan |
|
|
fi |
|
46 |
fi |
fi |