You are not logged in.

#1 2014-02-13 14:58:15

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,778

AoE mkinitcpio hook

I wrote a hook for diskless boot from an AoE device. It works fine, but I'd like to get some input. Any general criticism is welcome, but there are two things in particular I want to get input about:

1) I ripped off the network config from the net hook of mkinitcpio-nfs-utils. I did this rather than use the net hook itself because a) even though it's trivial, I don't want to pull the nfs stuff into the initrd and b) I use two of the variables from /tmp/net-*.conf, the sourcing of which is part of the ip configuration.

2) The bigger issue is the fact that aoe 'discovery' is rather simplistic; it boils down to echo >/dev/etherd/discover . So I use two for loops, one to confirm the server is reachable and one to do the discovery and test for the existence of $root.

Anyway, here's the hook:

#!/usr/bin/ash
run_hook() {
    local i net_mac bootif_mac bootif_dev
    # These variables will be parsed from /tmp/net-*.conf generated by ipconfig
    local DEVICE
    local IPV4ADDR IPV4BROADCAST IPV4NETMASK IPV4GATEWAY IPV4DNS0 IPV4DNS1
    local HOSTNAME DNSDOMAIN NISDOMAIN ROOTSERVER ROOTPATH
    local filename
    # /tmp/net-*.conf

    if [ -n "${ip}" ]; then
        if [ -n "${BOOTIF}" ]; then
            bootif_mac=${BOOTIF#01-}
            bootif_mac=${bootif_mac//-/:}
            for i in /sys/class/net/*/address; do
                read net_mac < ${i}
                if [ "${bootif_mac}" == "${net_mac}" ]; then
                    bootif_dev=${i#/sys/class/net/}
                    bootif_dev=${bootif_dev%/address}
                    break
                fi
            done
            ip="${ip}::${bootif_dev}"
        fi

        # setup network and save some values
        ipconfig "ip=${ip}"

        for conf in /tmp/net-*.conf; do
            [ -f "$conf" ] && . "$conf"
        done
    fi

    echo -n "Waiting for network"
    for i in 0 1 2 3 4; do
        if ping -w1 -c1 $ROOTSERVER >/dev/null 2>&1; then
            echo
            run_discover $DEVICE
            break
        else
            echo -n '.'
        fi
    done
    echo
}

run_discover() {
    local i

    modprobe aoe aoe_iflist="$1"

    echo -n "Discovering device on $1"
    for i in 0 1 2 3 4; do
       aoe-discover
       if [ -e $root ]; then
           return
       else
           sleep 1
           echo -n '.'
       fi
    done
}

But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#2 2014-02-15 20:18:08

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,097
Website

Re: AoE mkinitcpio hook

I'm not familiar with AoE, but it seems to me that calling modprobe repeatedly on the same module isn't going to give you the desired effect, even if the options are different each time.

Offline

#3 2014-02-15 20:26:19

Rexilion
Member
Registered: 2013-12-23
Posts: 784

Re: AoE mkinitcpio hook

Yeah, you should look at /sys/module/aoe/parameters/ . I hope those files are runtime writable though.


fs/super.c : "Self-destruct in 5 seconds.  Have a nice day...\n",

Offline

#4 2014-02-15 21:33:06

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,778

Re: AoE mkinitcpio hook

The logic should only allow 'run_discover $DEVICE' to run once, so I don't see how modprobe would be called more than once.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#5 2014-02-15 22:00:03

progandy
Member
Registered: 2012-05-17
Posts: 2,152

Re: AoE mkinitcpio hook

alphaniner wrote:

The logic should only allow 'run_discover $DEVICE' to run once, so I don't see how modprobe would be called more than once.

It doesn't get called more than once, but I think it would be more obvious if you moved the call to run_discover after the ping-loop.

Offline

#6 2014-05-19 19:16:36

ackalker
Member
Registered: 2012-11-27
Posts: 201

Re: AoE mkinitcpio hook

@alphaniner
Don't mean to be necrobumping this thread (3 months shouldn't be a problem), but did you know there's an `aoeping` utility in aoetools that should fit your need. Yes, it's 13KiB, but it has some other useful options, too.

With `aoeping` you can make your hook more generic: since AoE is an Ethernet-level protocol, you don't need IP addresses configured on either the target or the client (but obviously, it doesn't hurt :-) ). In fact, you don't even need the `ipconfig` binary, just bring up the network interfaces you wish to use for AoE by doing `ifconfig <netif> up` (`ifconfig` should be enabled as a Busybox applet), then use `aoeping` with a suitable timeout instead of a 'regular' ping loop to check if the disks are up.
When all is done and the root fs is mounted, regular netctl / systemd-networkd.service / whatever can take care of DHCP and stuff, just make sure that it doesn't bring down the interface inbetween phases (important!)

Last edited by ackalker (2014-05-19 19:25:54)

Offline

#7 2014-05-19 20:00:09

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,778

Re: AoE mkinitcpio hook

Don't mean to be necrobumping this thread

Well, it's certainly ok with me... wink

Anyway, I put this on the backburner due to 'serious business' at work and lack of equipment at home, then kind of forgot about it. Since then I'm using AoE at home and work, but just from a running system. I do plan on revisiting AoE boot though,, so thanks for the tip!


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#8 2014-05-20 01:05:38

ackalker
Member
Registered: 2012-11-27
Posts: 201

Re: AoE mkinitcpio hook

You're welcome :-)

I've gone ahead and uploaded my take on it to the AUR: https://aur.archlinux.org/packages/mkinitcpio-aoe/

For help, use the usual:

$ mkinitcpio -H aoe

Please let me know what you think of it :-)

Offline

#9 2014-05-20 01:48:42

ackalker
Member
Registered: 2012-11-27
Posts: 201

Re: AoE mkinitcpio hook

Well, testing in a VM worked perfectly, but real hardware always comes around to bite you :-(
I've added a pair of sleep commands (yuck, sleep is for lazy people!), hope these will help...

Offline

#10 2014-05-20 16:21:42

ackalker
Member
Registered: 2012-11-27
Posts: 201

Re: AoE mkinitcpio hook

Uploaded a new version: https://aur.archlinux.org/packages/mkinitcpio-aoe/
Tested on a VM and on my HTPC, working well.

Any comments are very welcome :-)

Offline

Board footer

Powered by FluxBB