help with raid and fai

ANDERSON RUSSELL D (ANDY) RXANDERS at srpnet.com
Tue Sep 13 19:52:37 CEST 2005


> -----Original Message-----
> From: owner-linux-fai at rrz.uni-koeln.de
> [mailto:owner-linux-fai at rrz.uni-koeln.de]On Behalf Of Barry L Britt
> Sent: Tuesday, September 13, 2005 8:36 AM
> To: linux-fai at uni-koeln.de
> Subject: help with raid and fai
> 
> 
> Hi,
> 
> I've been searching through the lists and through Google 
> looking for the 
> modified setup_harddisks script written by Sam Vilian. Does 
> anyone know 
> where I can find this script?
> 
> Thanks,
> Barry
> 
> 
> 
> Department of Computer Science
> Univeristy of Tennessee, Knoxville
> britt at cs.utk.edu
> Phone: (865) 974-4388
> 
> 

I really struggled getting raid mirroring to work. This is the hook and grub script I wrote/modified to do software mirroring on the O/S boot disk (2/40G) and a data disk (2/250G). Both were tested by yanking drives from a running system and reboots for robustness.

[partition.ATA_RAID1_40_250]

#!/bin/bash -x

#****************************************************
# build a raid array for filesystems
#****************************************************

# let FAI partition primary disks and then we'll modify
#
task_partition

# get list of primary disks
#
disks=$(cd $LOGDIR ; ls partition.* | sed 's/partition\./\/dev\//')

# change partitions to raid(fd)
#
partitions=$(sfdisk -d $disks|grep 'Id=8[23]'|cut -d":" -f1)
for partition in ${partitions[@]}; do
        dev=$(echo $partition | tr -d '[:digit:]')
        part=$(echo $partition | tr -cd '[:digit:]')
        sfdisk --change-id $dev $part fd
done

# copy partitions to mirror disks
#
sfdisk -d /dev/sda | sfdisk --no-reread -f /dev/sdc
sfdisk -d /dev/sdb | sfdisk --no-reread -f /dev/sdd

# create raid array for each partition
#
mdadm -C /dev/md1  -v -R -f -l1 -n2 /dev/sd[ac]1        # /
mdadm -C /dev/md5  -v -R -f -l1 -n2 /dev/sd[ac]5        # swap
mdadm -C /dev/md6  -v -R -f -l1 -n2 /dev/sd[ac]6        # /var
mdadm -C /dev/md7  -v -R -f -l1 -n2 /dev/sd[ac]7        # /tmp
mdadm -C /dev/md8  -v -R -f -l1 -n2 /dev/sd[ac]8        # /usr
mdadm -C /dev/md9  -v -R -f -l1 -n2 /dev/sd[ac]9        # /opt
mdadm -C /dev/md10 -v -R -f -l1 -n2 /dev/sd[ac]10       # /local
#
mdadm -C /dev/md11 -v -R -f -l1 -n2 /dev/sd[bd]1        # /export

# Wait for mirror sync
#
#while `grep -q resync /proc/mdstat`; do
        #echo "Waiting for devices to be ready..."
        #sleep 10
#done

# create filesystems
#
raids=$(cat /proc/mdstat|grep "^md[0-9]"|cut -d":" -f1)
for array in ${raids[@]}; do
        echo y | mkreiserfs -q /dev/${array}
done

# create swap
#
mkswap /dev/md5

# create /etc/fstab
#
cat > ${LOGDIR}/fstab << EOF
# /etc/fstab: static file system information.
#
#<file sys>  <mount point>    <type>    <options> <dump> <pass>
/dev/md1     /                reiserfs  defaults  0      0
/dev/md5     none             swap      rw        0      0
none         /proc            proc      defaults  0      0
/dev/md10    /local           reiserfs  defaults  0      0
/dev/md9     /opt             reiserfs  defaults  0      0
/dev/md7     /tmp             reiserfs  defaults  0      0
/dev/md8     /usr             reiserfs  defaults  0      0
/dev/md6     /var             reiserfs  defaults  0      0
/dev/drbd0   /export          reiserfs  noauto    0      0
EOF

# create new disk variables
#
cat > $diskvar << EOF
BOOT_DEVICE="/dev/sda"
ROOT_PARTITION="/dev/md1"
BOOT_PARTITION="/dev/md1"
SWAPLIST="/dev/md5"
EOF

# source in new disk variables
#
chmod 755 $diskvar
. $diskvar

# Since we called task_partition manually
# tell FAI to not undo our work via this hook
#
skiptask partition

[S10]

#! /bin/bash -x

# copyright Thomas Lange 2001-2004, lange at debian.org
# LILO support may be dropped in a future release

. /tmp/fai/disk_var.sh
bootdisks=$(sfdisk -d|fgrep bootable|cut -d":" -f1|tr -d '[:digit:]')
gmenu=$target/boot/grub/menu.lst

grubvars() {
    # define variables for grub
    fp=$1

    dfline=$(df $fp | grep '^/dev/')
    dev=$(echo $dfline | cut -d ' ' -f1)
    mntp=$(echo $dfline | awk '{print $6}')
    #broot=$(device2grub $dev)
    gpath=${fp#$mntp}
}

# a list of modules which are loaded at boot time
for module in $moduleslist; do
    echo $module >> $target/etc/modules
done

FFLAGS=${FAI_FLAGS// /,}

cd $target/boot && kernelversion=$(ls vmlinuz-*)

# if class MBR is defined, write lilo into master boot record
ifclass MBR || BOOT_DEVICE=$ROOT_PARTITION

if ifclass LILO; then
  fcopy /etc/lilo.conf || {
    # if the installed kernel is using an initial ramdisk
    if [ -L $target/initrd.img ]; then
        initrdopt="initrd=/initrd.img"
    fi
    # write lilo.conf and install lilo to disk
    echo "Creating lilo.conf for /vmlinuz"
    cat > $target/etc/lilo.conf <<-EOF
        boot=$BOOT_DEVICE
        root=$ROOT_PARTITION
        install=/boot/boot.b
        map=/boot/map
        vga=normal
        delay=50

        image=/vmlinuz
        append="devfs=nomount $kappend"
        $initrdopt
        label=linux
        read-only

        image=/vmlinuz.old
        label=linux.old
        read-only
        optional
        $liloappend
EOF
  }
fi

if ifclass GRUB; then
    for disk in $bootdisks; do
        grub-install --no-floppy --root-directory=$target $disk
    done
    broot=$(echo "find /boot/grub/stage1" \
            | grub --no-floppy --batch \
            | egrep "\(hd[0-9],[0-9]" \
            2>/dev/null)
    fcopy /boot/grub/menu.lst || {
    fullpath=$(ls $target/boot/vmlinuz-*)
    grubvars $fullpath
    if [ -L $target/initrd.img ]; then
        iname=$(cd $target/boot; ls initrd.img*)
        t="$target/boot"
        ipath=${t#$mntp}
        initrdopt="initrd $ipath/$iname"
    fi
    cat > $gmenu <<-EOF
        # created by FAI

        timeout 10
        default 0
        fallback 1
        color cyan/blue white/blue
EOF

    if ifclass SERIAL_CONSOLE; then
    console="console=ttyS0,9600 console=tty1"
    term="(Cyclades console)"
    cat >> $gmenu <<-EOF

        serial --unit=0 --speed=9600
        terminal --timeout=0 serial console
EOF
    fi

    for root in $broot; do
    cat >> $gmenu <<-EOF

        title Debian GNU/Linux, $kernelversion $root $term
        root $root
        kernel $gpath root=$ROOT_PARTITION $kappend $console
        $initrdopt
EOF
    done

    for root in $broot; do
    cat >> $gmenu <<-EOF

        title Debian GNU/Linux, $kernelversion $root Single user $term
        root $root
        kernel $gpath root=$ROOT_PARTITION $kappend ro single $console
        $initrdopt
EOF
    done

    if ifclass BOOTWINDOWS; then
    cat >> $gmenu <<-EOF

        # created by FAI

        # For booting Windows NT or Windows95
        title Windows
        rootnoverify (hd0,0)
        makeactive
        chainloader  +1
EOF
    fi

    # add entry for memtest
    if [ -f $target/boot/memtest86+.bin ] ; then
    t="$target/boot"
    gpath=${t#$mntp}
    for root in $broot; do
    cat >> $gmenu <<-EOF

        title  memtest $root $term
        root   $root
        kernel $gpath/memtest86+.bin $console
EOF
    done

    fi
    }
    echo "Grub installed for $kernelversion on $broot"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ifclass FAI_BOOTPART && {

    rev=`uname -r`
    mkdir -p $target/fai-boot
    cp -a /boot/vmlinuz-$rev $target/fai-boot

    ifclass LILO && {
    # write lilo.conf and install lilo to disk
        echo "Add /fai-boot partition to lilo.conf"

        cat >> $target/etc/lilo.conf <<-EOF
        image=/fai-boot/boot/$kernelversion
        $initrdopt
        append="devfs=nomount"
        label=FAI
EOF
        mkdir $target/fai-boot/etc
        cp $target/etc/lilo.conf $target/fai-boot/etc
    }

    ifclass GRUB && {

        echo "Add /fai-boot partition to menu.lst for grub"
        cd $target && kernelname="/fai-boot/vmlinuz-$rev"
        fullpath="$target/fai-boot/vmlinuz-$rev"
        grubvars $fullpath
        for root in $broot; do
        cat >> $gmenu <<-EOF

        title start FAI with FAI_ACTION=sysinfo $root $term
        password fai
        root $root
        kernel $kernelname root=/dev/nfs ip=dhcp FAI_FLAGS=$FFLAGS FAI_LOCATION=$FAI_LOCATION FAI_ACTION=sysinfo $console

        title FAI re-Installation $root $term
        password fai
        root $root
        kernel $kernelname root=/dev/nfs ip=dhcp FAI_FLAGS=$FFLAGS FAI_LOCATION=$FAI_LOCATION FAI_ACTION=install $console
EOF
        done

        echo "Grub for $kernelversion installed on $broot"
    }
}

# now call lilo
# you can also use this
# $ROOTCMD lilo -v
if ifclass LILO; then
    $target/sbin/lilo -r $target
fi




More information about the linux-fai mailing list