Find the answer to your Linux question:
Results 1 to 2 of 2
Aw, I really can't figure this one out. I have a machine (let's call it server) that is partitioning, formatting and installing images on clients. The clients disks are all ...
  1. #1
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047

    Automatic formatting always fails the first time

    Aw, I really can't figure this one out.

    I have a machine (let's call it server) that is partitioning, formatting and installing images on clients.

    The clients disks are all zeroed, is that how you call it? dd if=/dev/zero of=/dev/hda options blablabla


    Anyway, the procedure is as follows. The clients are hooked up to the server through a switch. The clients are powered on, and are ordered to 'netboot'. Now in short, they request DHCP, find a PXE config, load a kernel, load a ramdisk, and in the ramdisk there is the painful payload that causes my question:

    In the script:
    I use sfdisk to partition the disk
    I then use mkreiserfs /dev/hda1
    I use mkswapfs /dev/hda2
    then mkreiserfs /dev/hda3 <= here it errors


    It always errors on that point. I tried to change the order of things around without effect. It always errors on `mkreiserfs /dev/hda3` on, and this is what's weird, on the first time. When I reboot and run the same procedure again, it doesn't error and it does exactly what I want.
    Also, when I do the same with a machine that isn't zeroed, it also doesn't error and it also does what I want. I can take any machine I want and do this procedure on, and it always works. But as soon as I take one with a zeroed disk, it errors but only on the first run and not on the second run. And always on /dev/hda3 and never on anything else.



    So far I've tried to change the order of the mk*fs commands. I've set it up so that if the first run of `mkreiserfs /dev/hda3` fails, that it tries again. To no avail. Right now the whole script reruns when `mkreiserfs /dev/hda3` errors, also to no avail. It always errors. And a reboot later it's working perfectly.

    That is also a bit of the problem. To replicate the behavior, or to try to solve it, I need to zero the disk of the test machine again, which takes almost an hour.

    Any and all thoughts on this are highly appreciated, as I have no idea what is going on.

    Below is the entire script, as is:
    (It's a bit dirty, but 100&#37; functional)
    Code:
    #!/bin/bash
    #
    #
    #
    #    WARNING
    #    Highly HAZARDOUS code
    #    Do NOT run unless you know you want to
    #    And ask you parents for permission, just to be on the safe side :-p
    #
    #
    #
    exit     # Safety mesure, not acttually part of the script.
    
    
    # Netwerk
    rpc.portmap
    mount -t nfs 192.168.0.1:/nfsroot /mnt
    
    # Definities
    IPADRES=`ifconfig|grep 192|awk '{print $2}'`
    MACHINE="${IPADRES##*.}"
    LOGFILE='/mnt/clientlog'
    PARTFAIL="0"
    FORMFAIL="0"
    MBRFAIL="0"
    IMGFAIL="0"
    
    Startlog () {
    echo "$MACHINE checks in" >> $LOGFILE
    }
    
    Write2Log () {
    echo "$MACHINE $MESSAGE $VAR" >> $LOGFILE
    }
    
    
    Partitioneren () {
    MESSAGE="sfdisk"
    sfdisk /dev/hda << EOF
    ,1100,L,*
    ,80,S
    ,,L
    ;
    EOF
    
    
    if [ "$?" -eq "0" ] ; then
        VAR="succes"
    else
        VAR="FAAL"
        PARTFAIL=`expr $PARTFAIL + 1`
    fi
    
    Write2Log
    }
    
    Formatteren () {
    MESSAGE="mkreiserfs1"
    mkreiserfs -q /dev/hda1 
    if [ "$?" -eq "0" ] ; then
        VAR="succes"
    else
        VAR="FAAL"
        FORMFAIL=`expr $FORMFAIL + 1`
    fi
    Write2Log
    
    MESSAGE="mkreiserfs3"
    mkreiserfs -q /dev/hda3 
    if [ "$?" -eq "0" ] ; then
        VAR="succes"
    else
        VAR="FAAL"
        FORMFAIL=`expr $FORMFAIL + 1`
    fi
    Write2Log
    
    
    MESSAGE="swapfs"
    mkswap -f /dev/hda2 
    if [ "$?" -eq "0" ] ; then
        VAR="succes"
    
    else
        VAR="FAAL"
        FORMFAIL=`expr $FORMFAIL + 1`
    fi
    Write2Log
    }
    
    
    mbrTransfer () {
    MESSAGE="MBR"
    dd if=/mnt/mbr.img of=/dev/hda bs=446 count=1 
    if [ "$?" -eq "0" ] ; then
        VAR="succes"
    else
        VAR="FAAL"
        MBRFAIL=`expr $MBRFAIL + 1`
    fi
    Write2Log
    }
    
    
    ImageTransfer () {
    MESSAGE="image"
    VAR="patience"
    Write2Log
    gzip -dc /mnt/final.img.gz|dd of=/dev/hda1 
    if [ "$?" -eq "0" ] ; then
        VAR="voltooid"
    else
        VAR="FAAL"
        IMGFAIL=`expr $IMGFAIL + 1`
    fi
    Write2Log
    }
    
    
    RoundUp () {
    MESSAGE=" "
    VAR="klaar"
    Write2Log
    poweroff
    }
    
    
    #
    #    Work
    #    WORK
    #    WORK
    #
    
    Startlog
    Partitioneren        # sfdisk! Go go go
    if [ "$PARTFAIL" -gt "0" ] ; then
        PARTFAIL="0"
        Partitioneren    # A second chance to do right
        if [ "$PARTFAIL" -gt "0" ] ; then
            VAR="AFBREKEN"
            Write2Log
            poweroff
        fi
    fi
    
    Formatteren        # mkreiserfs
    if [ "$FORMFAIL" -gt "0" ] ; then
        FORMFAIL="0"
        Partitioneren                              # Weird bug to get around
        Formatteren                              # alas this hack doesn't work either
        if [ "$FORMFAIL" -gt "0" ] ; then
            VAR="RAARRRRRRR"                  # This is where we don't want to be -
            Write2Log                             # but always end up when the disk -
            echo 'Again its wrong!'                    # is zeroed
            #poweroff 
        fi
    fi
    
    mbrTransfer        # Master Boot Record
    if [ "$MBRFAIL" -gt "0" ] ; then
        MBRFAIL="0"
        mbroverdracht
        if [ "$MBRFAIL" -gt "0" ] ; then
            VAR="AFBREKEN"
            Write2Log
            poweroff
        fi
    fi
    
    ImageTransfer        # Now everything went ok, get to work you!
    RoundUp
    Last edited by Freston; 10-16-2008 at 04:45 PM. Reason: translated some more
    Can't tell an OS by it's GUI

  2. #2
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Oops!

    I forgot to mention the most important part, and the reason why I put it in this section

    When I enter all the steps on a zeroed machine manually it does not error. I just tried that again.


    It is really beyond me why this piece of code always works:
    Code:
    mkreiserfs -q /dev/hda1 
    if [ "$?" -eq "0" ] ; then
        VAR="succes"
    else
        VAR="FAAL"
        FORMFAIL=`expr $FORMFAIL + 1`
    fi
    And this piece only works after the second boot, if the disk is zeroed:
    Code:
    mkreiserfs -q /dev/hda3 
    if [ "$?" -eq "0" ] ; then
        VAR="succes"
    else
        VAR="FAAL"
        FORMFAIL=`expr $FORMFAIL + 1`
    fi
    But it works flawlessly if the disk isn't zeroed or when I enter it manually, regardless of anything else




    I'm zeroing the disk again right now. See if I can get it to give me some error message. Any thoughts on how and what kind of action I should take to get a useful error message? The debugging flag on mkreiserfs comes to mind. Any other thoughts are appreciated.



    EDIT: Solved
    It turned out that some minor tests I had been running while doing all this manually had greater and more beneficial effect than I had anticipated. Special thanks goes out to `fdisk -l`, which seems to have to be run after sfdisk probably to reread the partition table.
    Can't tell an OS by it's GUI

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...