Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Trouble booting from thumb drive...



    Date:        Mon, 5 Dec 2011 23:34:05 +0200
    From:        Andreas Gustafsson <gson%gson.org@localhost>
    Message-ID:  <20189.14541.373196.999072%guava.gson.org@localhost>

  | There's a script for doing this in pkgsrc: sysutils/mkmemstick. 

Beware the script contains
        vnddev="vnd0"

That is, it simply assumes vnd0 is available (it doesn't even test the
result of the vnconfig to determine if that's true or not).

Here's a little function/script that determines the name of the next
available vnd (or to be more precise, one vnd above the biggest numbered
one currently in use).    Scripts should really use something like this
rather than just assuming that no-one else uses vnds (or cgds, or similar).

kre

#! /bin/sh

# Usage: next_avail cloner-type-disk
#       eg; next_avail vnd
#                       (or cgd or raid ...)

# could be made smarter by detecting holes in sequence space...

next_avail ()
{
        local dev="$1"
        local N=$(( ${#dev} + 1 ))

        local unit=$(
                sysctl -n hw.disknames          |
                        tr ' ' '\012'           |
                        grep '^'"${dev}"'[0-9]' |
                        sort -n -k 1.$N         |
                        tail -1                         )

        test -z "${unit}" && {
                echo "${dev}0"
                return
        }

        N=${unit#${dev}}
        echo "${dev}$(( $N + 1 ))"
}

for A
do
        next_avail "${A}"
done




Home | Main Index | Thread Index | Old Index