/[smeserver]/cdrom.image/updates/raidconvert
ViewVC logotype

Diff of /cdrom.image/updates/raidconvert

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

Revision 1.2 by growell, Sat Sep 17 02:01:29 2005 UTC Revision 1.5 by slords, Fri Dec 22 23:52:44 2006 UTC
# Line 1  Line 1 
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)
 if grep -q 'sda$' /proc/partitions; then  
     disk=sda  
 else  
     # No SCSI Drives is must be IDE  
     media=`cat /proc/ide/hda/media`  
     if [ $media == "disk" ] ; then  
         disk=hda  
     fi  
 fi  
7    
8  set $disk  if [ -n "$device" ]
9  found=`echo $#`  then
10  if [ $found -gt "0" ] ; then      sfdisk -d /dev/$device > /tmp/oldparts
11      # Dump out current partitions      sed 's/Id=8[32]/Id=fd/' /tmp/oldparts > /tmp/newparts
12      sfdisk -d /dev/$disk > /tmp/oldparts  
13        mkdir /mnt/tmp
14      # Check if we have any ext2/3 or swap partitions      for part in $(awk '/^\/dev\/.*Id=8[23]/{ print $1 }' /tmp/oldparts)
15      if grep -q 'Id=8[23]' /tmp/oldparts; then      do
16          echo -en "\n\nConverting partitions to RAID..." >/dev/tty3          md=/dev/md$(echo $part | sed 's|^.*[^0-9]||')
17          # Convert ext2/3 and swap partitions to raid autodetect  
18          sed 's/Id=8[32]/Id=fd/' /tmp/oldparts > /tmp/newparts          if grep -q "^$part .*Id=83" /tmp/oldparts
19            then
20          # Find swap partition for future checks              e2fsck -f -C0 $part
21          swap=`grep 'Id=82' /tmp/oldparts | sed "s/$disk\([0-9]\+\) :.*/md\1/"`              partsize=$(resize2fs -f $part 2>&1| sed -n 's|.* \([0-9]\+\) blocks long.*|\1|p')
22                resize2fs -fp $part $(($partsize-72))
23          # Loop throught partitions and convert to degraded raid1          fi
24          for part in `grep 'Id=8[23]' /tmp/oldparts | sed 's/ :.*//'`; do  
25              mdpart=`echo $part | sed "s/$disk\([0-9]\+\)/md\1/"`          mdadm -C $md -l 1 -n 2 -R $part missing
26                    echo "DEVICE $part" >> /tmp/mdadm.conf
27              echo -n "$part..." >/dev/tty3  
28              mdadm --create $mdpart --run --level=1 --raid-devices=2 $part missing          if grep -q "^$part .*Id=83" /tmp/oldparts
29              if [ "$mdpart" == "$swap" ]; then          then
30                  # Recreate swap partition              e2fsck -f -C0 $md
31                  mkswap $swap              resize2fs -fp $md
32              else  
33                  # Resize ext2/3 partitions (fix superblock - part 1)              mount $md /mnt/tmp
34                  resize2fs -f $mdpart              [ -r /mnt/tmp/etc/fstab ] && root=$md
35              fi              umount /mnt/tmp
36          done  
37    
38          echo "done" >/dev/tty3          elif grep -q "^$part .*Id=82" /tmp/oldparts
39            then
40          # Write out new converted partition table              mkswap $md
41          sfdisk --force /dev/$disk < /tmp/newparts          fi
42        done
43          echo -e "\nChecking filesystems on converted partitions. This may take a while." >/dev/tty3  
44        echo >> /tmp/mdadm.conf
45          mkdir /mnt/tmp      mdadm -Es -c /tmp/mdadm.conf >> /tmp/mdadm.conf
46          for part in `grep 'Id=fd' /tmp/newparts | sed "s/$disk\([0-9]\+\) :.*/md\1/"`; do  
47              if [ "$part" != "$swap" ]; then      if [ -n "$root" ]
48                  # Resize ext2/3 partitions (fix superblock - part 2)      then
49                  echo -e "\n\nChecking $part..." >/dev/tty3          mount $root /mnt/tmp
50                  e2fsck -f -C0 $part >/dev/tty3          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                  # Check for /etc/fstab on partitions and convert entries          umount /mnt/tmp
                 mount $part /mnt/tmp  
                 if [ -r /mnt/tmp/etc/fstab ]; then  
                     # XXX - FIXME - unportable hack for fstab.  
                     # Only works for 6.x I suspect  
                     cat /mnt/tmp/etc/fstab | sed "s/$disk\([0-9]\+\)/md\1/" | \  
                         sed -e "s:LABEL=/boot1:/dev/md1:" | \  
                         sed -e "s:LABEL=/:/dev/md3:" \  
                         > /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      
53      fi      fi
54        rmdir /mnt/tmp
55    
56        mdadm --stop --scan
57    
58        sfdisk --force /dev/$device < /tmp/newparts
59  fi  fi


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed