Kernel Configuration script [was Re: "Next Generation" kernel configuration?]

From: William Kirkland (bill_at_wek4.com)
Date: 07/29/04

  • Next message: Brooks Davis: "Re: Kernel Configuration script [was Re: Next"
    To: freebsd-hackers@freebsd.org
    Date: Thu, 29 Jul 2004 08:28:05 -0700 (PDT)
    
    

    On Tue, Jul 20, 2004 at 07:39:31PM -0500, Conrad J. Sabatier wrote:
    > Just musing on an idea here:
    >
    > I've been thinking for a while now about trying to write a tool to make
    > kernel configuration easier, sort of a "make config" (as in ports) for
    > the kernel, similar to what's available on some of the Linux distros.

    Ok, I have attached some scripts I wrote, to make my life simpler.
    Though I do have some concerns that one should write their own, or use
    the existing structure and tools. I am willing to show what I use and
    share ideas.

    If you choose to use this, please give credit where it is due. As I
    have never previously published this, nor anything else. I find the GNU
    GPL (http://www.gnu.org/copyleft/gpl.html) acceptable. Use at your own
    risk.

    My scripts parces the boot information from /var/log/messages, then
    builds a kernel configuration file from that and a configuration file.
    I have, just now, written a brief overview of what is done and am
    willing to provide more information if you ask. I suppose I could even
    clean it up a bit and write proper documentation.

    The profile is a bit overly complex, though I use it for a number of
    other scripts as well. Sufice it to say, it searches (based upon the
    PATH environmental variable, replacing "/bin:" and "/sbin:" with
    "/etc:" for an appropriate configuration file (one that has the script
    name, minus an optional .sh and appending a .cfg, as a sufix). Once
    the file is found, appropriate variables are set.

    The performance can be enhanced by setting the "grep" variable, so
    that only the relevent boot entries are parced, or copying the message
    file somewhere else, then setting the "boot" variable to point to that
    file.

    Options and and device entries are included if a reference is found
    for them in the /var/log/messages file. The exclude and include
    configuration variables, modify this behavior, in that the script does
    not find references for everything in the boot record, and also finds
    references to things I do not use.

    You should probably uncomment line 34, and verify the results, prior to
    using. For that matter, there are a number of other things you should
    understand prior to use (review it before you use it!).

    #! /bin/sh
    #- -r-xr-xr-x 1 root wheel 1285 May 9 20:20 /wek/bin/kernel.sh
    . /wek/bin/_profile

    if [ ! -f "${_kernel_dst}" ]; then
    grep -E "${_kernel_grep:-.*}" ${_kernel_boot:-/var/log/messages} >${tmp}
    awk -v K=${_kernel} -v B=${tmp} -v P=${_kernel_prefix} \
            -v I="${_kernel_include}" -v X="${_kernel_exclude}" '
    BEGIN { while( getline <B ) {
                    if ( $0 ~ P && $5 == "kernel:" && $6 ~ "[0-9]:$" ) {
                            sub( "[0-9]:$", "", $6 ); D[$6]++
            } }
            z=split( I, Z ); for( i=1; i<=z; i++ ) { d=Z[i]; D[d]++ }
            z=split( X, Z ); for( i=1; i<=z; i++ ) { d=Z[i]; D[d]=0 }
    }
    /^[ # ]*ident[ ]/ { printf( "ident %s\n", K ); next }
    /^[ # ]*device[ ]/ {
            sub( "^[ # ]*", "" )
            sub( "[ ]*$", "" )
            if ( D[$2] == 0 ) { printf( "#- %s\n", $0 )
            } else { printf( "%s #=%d\n", $0, D[$2] ) }
            next }
    /^[ # ]*(options|cpu)[ ]/ {
            if ( D[$2] != "" ) {
            sub( "^[ # ]*", "" )
            sub( "[ ]*$", "" )
            if ( D[$2] == 0 ) { printf( "#- %s\n", $0 )
            } else { printf( "%s #=%d\n", $0, D[$2] ) }
            next } }
    /./ { print }' <${_kernel_src:-/dev/null} >${_kernel_dst}
            if [ -f "${_kernel_add}" ]; then
                    cat ${_kernel_add} >>${_kernel_dst}
            fi
    rm -f ${tmp} 2>/dev/null
    #- exit
    fi

    ( uname -a; date; set -o xtrace
            printenv | grep "^_${P}" | sort
            cd /usr/src && make -i depend \
                    && make buildkernel KERNCONF=${_kernel} \
                    && make installkernel KERNCONF=${_kernel}
    ) 2>&1 | tee ${_kernel_log}

    #- -r--r--r-- 1 operator wheel 126 Apr 23 15:50 /wek/etc/kernel.add
    #- options FAST_IPSEC # new IPsec
    options IPSEC
    options IPSEC_ESP
    options IPFIREWALL
    options IPDIVERT
    options DUMMYNET

    #- -r--r--r-- 1 operator wheel 372 May 9 13:59 /wek/etc/kernel.cfg
    wek-*
            boot=/tmp/boot
            boot=/var/log/messages
            src=/usr/src/sys/$( uname -m )/conf/GENERIC
            dst=/usr/src/sys/$( uname -m )/conf/${_kernel}
            include="atadisk atapicd atapifd atapist random loop ether pty md bpf miibus gif sis"
            exclude="INET6 MD_ROOT NFS_ROOT I486_CPU I586_CPU SMP plip"
            add=${home}/etc/${P}.add
            log=${home}/log/${_kernel}

    #! /bin/sh
    #- -rw-r--r-- 1 root wheel 742 May 11 14:39 /wek/bin/_profile

    P=$( basename ${0%.*} )
    export home=/wek
    export tmp=/tmp/$$
    export log=/tmp/${P}-$( date "+%y%m%d" )

    for T in $( echo ${PATH}:${home}/etc \
    | sed 's|/[s]*bin:|/etc |g' | tr ":" " " ); do
            if [ -z "${cfg}" -a -r ${T}/${P}.cfg ]; then
                    cfg=${T}/${P}.cfg
            fi
    done
    awk -F = -v P=${P} -v M="${1:-$( date '+wek-%y%m%d' )}" '
    /^[^ ]/ { ok=0; if ( M ~ $1 ) { print "export _" P "=" M; ok=1; next } }
    /^[ ]+[A-Z0-9a-z_]*[ ]*=/ { if ( ok ) {
            gsub( "^[ ]*", "export _" P "_" ); print
    } }' ${cfg:-/dev/null} >${tmp}
    . ${tmp} && rm ${tmp}
    export PATH=${home}/bin:${PATH}
    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: Brooks Davis: "Re: Kernel Configuration script [was Re: Next"

    Relevant Pages

    • Re: No keyboard at boot in Debian
      ... If you are using a custom kernel, the boot scripts probably don't match ... As long as you can boot a rescue system, ...
      (comp.os.linux.misc)
    • Re: 2.6.21.1 on Fedora Core 6 breaks LVM/vgscan
      ... results in a panic at boot because the root filesystem can't be found. ... I have just compiled 2.6.22-rc2 with the configuration file given in my ... previous post and the resulting kernel successfully boots on the machine ...
      (Linux-Kernel)
    • Kernel Configuration script [was Re: Next
      ... > the kernel, similar to what's available on some of the Linux distros. ... Ok, I have attached some scripts I wrote, to make my life simpler. ... My scripts parces the boot information from /var/log/messages, ... builds a kernel configuration file from that and a configuration file. ...
      (freebsd-hackers)
    • Re: Making Emergency bootable CD on Debian 3.1 2.4.27 kernel
      ... using OLD kernel in case there is problem in booting using new compiled ... I am using GRUB as boot loader. ... and edit the configuration file on the boot floppy. ...
      (Debian-User)
    • Re: boot cgroup questions
      ... without mounting a cgroupfs? ... filesystem inside the kernel. ... Would this be done based on some boot commandline option? ... It probably won't even affect your existing scripts since ...
      (Linux-Kernel)