Changeset 737


Ignore:
Timestamp:
Aug 3, 2006, 8:49:44 PM (13 years ago)
Author:
bruno
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.

Location:
branches/stable
Files:
2 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=$?
  • branches/stable/mondo/mondo/common/libmondo-files.c

    r684 r737  
    12671267            ("Unable to find ethN (eth0, eth1, ...) adapter via NFS mount you specified.");
    12681268    }
    1269     sprintf(outfile, "%s/start-nfs", bkpinfo->tmpdir);
    1270     sprintf(tmp, "outfile = %s", outfile);
    1271     log_it(tmp);
    1272     if (!(fout = fopen(outfile, "w"))) {
    1273         fatal_error("Cannot store NFS config");
    1274     }
    1275     fprintf(fout, "#!/bin/sh\n");
    1276     fprintf(fout, "# number of ping\n");
    1277     fprintf(fout, "ipcount=3\n");
    1278     fprintf(fout, "for i in `cat /proc/cmdline` ; do\n");
    1279     fprintf(fout, "    echo $i | grep -qi ping= && ipcount=`echo $i | cut -d= -f2`\n");
    1280     fprintf(fout, "done\n");
    1281     fprintf(fout, "ifconfig lo 127.0.0.1  # config loopback\n");
    1282     fprintf(fout, "ipdev=%s\n", nfs_dev);
    1283     fprintf(fout, "ipaddress=%s\n", nfs_client_ipaddr);
    1284     fprintf(fout, "ipnetmask=%s\n", nfs_client_netmask);
    1285     fprintf(fout, "ipbroadcast=%s\n", nfs_client_broadcast);
    1286     fprintf(fout, "ipgateway=%s\n", nfs_client_defgw);
    1287     fprintf(fout, "ipconf=\n");
    1288     fprintf(fout, "nfsmount=%s\n", bkpinfo->nfs_mount);
    1289     fprintf(fout, "for i in `cat /proc/cmdline` ; do\n");
    1290     fprintf(fout, "    echo $i | grep -qi ipconf= && ipconf=`echo $i | cut -d= -f2`\n");
    1291     fprintf(fout, "    echo $i | grep -qi nfsmount= && nfsmount=`echo $i | cut -d= -f2`\n");
    1292     fprintf(fout, "done\n");
    1293     fprintf(fout, "nfs_server_ipaddr=`echo $nfsmount | cut -d: -f1`\n");
    1294     fprintf(fout, "echo \"$ipconf\" | grep -q \"dhcp\"\n");
    1295     fprintf(fout, "if [ $? -eq 0 ]; then\n");
    1296     fprintf(fout, "    ipdev=`echo $ipconf | cut -d: -f1`\n");
    1297     fprintf(fout, "    echo \"Making DHCP request on $ipdev\"\n");
    1298     fprintf(fout, "    udhcpc -i $ipdev\n");
    1299     fprintf(fout, "else\n");
    1300     fprintf(fout, "    if [ \"$ipconf\" != \"\" ]; then\n");
    1301     fprintf(fout, "        ipdev=`echo $ipconf | cut -d: -f1`\n");
    1302     fprintf(fout, "        ipaddress=`echo $ipconf | cut -d: -f2`\n");
    1303     fprintf(fout, "        ipnetmask=`echo $ipconf | cut -d: -f3`\n");
    1304     fprintf(fout, "        ipbroadcast=`echo $ipconf | cut -d: -f4`\n");
    1305     fprintf(fout, "        ipgateway=`echo $ipconf | cut -d: -f5`\n");
    1306     fprintf(fout, "    fi\n");
    1307     fprintf(fout, "    ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast\n");
    1308     fprintf(fout, "    route add default gw $ipgateway\n");
    1309     fprintf(fout, "fi\n");
    1310     fprintf(fout, "ping -c $ipcount $nfs_server_ipaddr # ping server\n");
    1311     fprintf(fout, "mount -t nfs -o nolock $nfsmount /tmp/isodir\n");
    1312     paranoid_fclose(fout);
    1313     chmod(outfile, 0777);
    13141269    make_hole_for_dir("/var/cache/mondo-archive");
    1315 
    1316 //  paranoid_system ("mkdir -p /var/cache/mondo-archive 2> /dev/null");
    1317 
    1318     sprintf(tmp, "cp -f %s /var/cache/mondo-archive", outfile);
    1319     run_program_and_log_output(tmp, FALSE);
    13201270
    13211271    sprintf(tmp, "%s/NFS-DEV", bkpinfo->tmpdir);
Note: See TracChangeset for help on using the changeset viewer.