Ignore:
Timestamp:
Aug 3, 2006, 8:49:44 PM (13 years ago)
Author:
Bruno Cornec
Message:

Big NFS+PXE migration: start-nfs is not created by mondoarchive, but on the fly by init during restore. This allows more flexibility to restore through NFS a backup created on disks e.g. and simplify code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mindi/rootfs/sbin/init

    r736 r737  
    307307# pipe vgscan's output, strip it, run 'vgchange' on its output, etc.etc.
    308308    LogIt "LVM's have been started."
    309 }
    310 
    311 
    312 
    313 StartNfs() {
    314     # using mount -o nolock avoids portmap requirement
    315     #if which portmap > /dev/null 2> /dev/null ; then
    316         #LogIt "Running portmap"
    317     #portmap
    318         #[ "$?" -eq "0" ] && LogIt "Portmap started OK" || LogIt "Portmap error"
    319         if [ -e "/sbin/start-nfs" ] ; then
    320             chmod 755 /sbin/start-nfs
    321         LogIt "Starting NFS..."
    322             /sbin/start-nfs
    323         fi
    324     #fi
    325309}
    326310
     
    481465fi
    482466
    483 #if [ -e "/tmp/2880.siz" ] ; then
    484 #    HandleCDROMorFloppies
    485 #el
     467#
     468# Create NFS configuration
     469#
     470cat > /sbin/start-nfs << EOF
     471#!/bin/sh
     472#
     473# number of ping
     474#
     475ipcount=3
     476
     477# Get info from config file
     478ipdev=`grep nfs-dev /tmp/mondo-restore.cfg | cut -d' ' -f2-`
     479ipaddress=`grep nfs-client-ipaddr /tmp/mondo-restore.cfg | cut -d' ' -f2-`
     480ipnetmask=`grep nfs-client-netmask /tmp/mondo-restore.cfg | cut -d' ' -f2-`
     481ipbroadcast=`grep nfs-client-broadcast /tmp/mondo-restore.cfg | cut -d' ' -f2-`
     482ipgateway=`grep nfs-client-defgw /tmp/mondo-restore.cfg | cut -d' ' -f2-`
     483ipconf=""
     484nfsmount=`grep nfs-server-mount /tmp/mondo-restore.cfg | cut -d' ' -f2-`
     485imgname=`grep iso-prefix /tmp/mondo-restore.cfg | cut -d' ' -f2-`
     486if [ "$imgname" = "" ]; then
     487    imgname="mondorescue"
     488fi
     489dirimg=`grep nfs-server-path /tmp/mondo-restore.cfg | cut -d' ' -f2-`
     490if [ "$dirimg" = "" ]; then
     491    dirimg="/"
     492fi
     493
     494# info from cmdline are predominent
     495for i in `cat /proc/cmdline` ; do
     496    echo $i | grep -qi ping= && ipcount=`echo $i | cut -d= -f2`
     497    echo $i | grep -qi ipconf= && ipconf=`echo $i | cut -d= -f2`
     498    echo $i | grep -qi nfsmount= && nfsmount=`echo $i | cut -d= -f2`
     499    echo $i | grep -qi prefix= && imgname=`echo $i | cut -d= -f2`
     500done
     501
     502if [ $ipdev = "" ] && [ $ipconf = "" ]; then
     503    # No network configuration neither stored during archive
     504    # nor on cmdline so no network wanted => exiting
     505    exit 0
     506else
     507    LogIt "Starting Network..."
     508fi
     509
     510# Activate loobback
     511ifconfig lo 127.0.0.1
     512
     513echo "$ipconf" | grep -q "dhcp"
     514if [ $? -eq 0 ]; then
     515    ipdev=`echo $ipconf | cut -d: -f1`
     516    echo "Making DHCP request on $ipdev"
     517    udhcpc -i $ipdev
     518else
     519    if [ "$ipconf" != "" ]; then
     520        ipdev=`echo $ipconf | cut -d: -f1`
     521        ipaddress=`echo $ipconf | cut -d: -f2`
     522        ipnetmask=`echo $ipconf | cut -d: -f3`
     523        ipbroadcast=`echo $ipconf | cut -d: -f4`
     524        ipgateway=`echo $ipconf | cut -d: -f5`
     525    fi
     526    echo "Configuring $ipdev statically ($ipaddress/$ipnetmask)"
     527    ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast
     528    route add default gw $ipgateway
     529fi
     530
     531# ping server helps waking interface up
     532LogIt "Pinging NFS server..."
     533nfs_server_ipaddr=`echo $nfsmount | cut -d: -f1`
     534ping -c $ipcount $nfs_server_ipaddr
     535
     536# Finally mounts the NFS share
     537LogIt "Mounting NFS share ($nfsmount) on /tmp/isodir..."
     538mount -t nfs -o nolock $nfsmount /tmp/isodir
     539
     540LogIt "Mounting NFS image $imgname-1.iso in $dirimg on /mnt/cdrom in loopback"
     541losetup /dev/loop7 /tmp/isodir/$dirimg/$imgname-1.iso
     542mount -o ro -t iso9660 /dev/loop7 /mnt/cdrom
     543EOF
     544chmod 755 /sbin/start-nfs
     545
    486546if [ "`grep -i 'tape ' /tmp/mondo-restore.cfg`" ] || [ "`grep -i udev /tmp/mondo-restore.cfg`" ] ; then
    487         HandleTape
     547    HandleTape
    488548    ExtractDataDisksAndLoadModules
    489 elif [ -e "/sbin/start-nfs" ] && [ "`grep -i pxe /proc/cmdline`" ]; then
    490     StartNfs
    491     imgname=`grep iso-prefix /tmp/mondo-restore.cfg | cut -d' ' -f2-`
    492     if [ "$imgname" = "" ]; then
    493         imgname="mondorescue"
    494     fi
    495     if [ "`grep -i prefix /proc/cmdline`" ] ; then
    496         for i in `cat /proc/cmdline` ; do
    497             if [ "`echo $i | grep -i prefix`" ] ; then
    498                 imgname=`echo $i | cut -d'=' -f2`
    499             fi
    500         done
    501     fi
    502     dirimg=`grep nfs-server-path /tmp/mondo-restore.cfg | cut -d' ' -f2-`
    503     if [ "$dirimg" = "" ]; then
    504         dirimg="/"
    505     fi
    506     LogIt "Mounting NFS image $imgname-1.iso in $dirimg on /mnt/cdrom in loopback"
    507     losetup /dev/loop7 /tmp/isodir/$dirimg/$imgname-1.iso
    508     mount -o ro -t iso9660 /dev/loop7 /mnt/cdrom
     549elif [ "`grep -i pxe /proc/cmdline`" ]; then
     550    /sbin/start-nfs
     551
    509552    # Simulate a local CD
    510553    echo "/mnt/cdrom" > /tmp/CDROM-LIVES-HERE
    511         CD_MOUNTED_OK=yes
     554    CD_MOUNTED_OK=yes
    512555    ExtractDataDisksAndLoadModules
    513556else
    514557    HandleCDROMorFloppies
    515558    ExtractDataDisksAndLoadModules
    516     if [ -e "/sbin/start-nfs" ]; then
    517         StartNfs
    518     fi
     559    /sbin/start-nfs
    519560fi
    520561res=$?
Note: See TracChangeset for help on using the changeset viewer.