Archive for August, 2010

Including non-free firmware within Debian netboot images

August 31, 2010

Problem –

It can be seen this approach does not work well with netboot images which need Ethernet firmware… the Ethernet firmware really needs to be in the initrd.gz before the kernel boots. One solution is to build your own custom Debian Installer images. This is possible and the Debian Installer build process is described here –

I require the firmware from the firmware-bnx2 package to install on an Dell PowerEdge R710 with Lenny:

  1. Clear, create and cd into a temporary directory:
    rm -rf /tmp/firmware-bnx2
    mkdir  /tmp/firmware-bnx2
    cd /tmp/firmware-bnx2
  2. Acquire the lenny/firmware-bnx2 package, which contains the firmware: (firmware-bnx2 download page)
    wget http://ftp.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-bnx2_0.14_all.deb
  3. Extract the files from the package into the temporary directory:
    ar -p firmware-bnx2_0.14_all.deb data.tar.gz | tar -zxf -
  4. Create the cpio archive using pax, contain stuff under lib but root it in / in the archive:
    pax -x sv4cpio -s '%lib%/lib%' -w lib | gzip -c >bnx2-fw.cpio.gz
  5. Change to the Debian Installer directory… (ie where you have your initrd.gz):
    cd $debian-installer-dir
  6. Make a backup!
    cp -p initrd.gz initrd.gz.orig
  7. Append the new archive to the original initrd:
    cat /tmp/firmware-bnx2/bnx2-fw.cpio.gz >> initrd.gz

Now boot with your new initrd.gz and original vmlinuz and you should be on the road!

Alternative way –

We uncompress the image using:

mkdir temp
cd temp/
zcat ../initrd.gz | cpio -iv

Download the firmware-bnx2 debian package:

cd ..
wget http://http.us.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-bnx2_0.14_all.deb

and extract the contents with:
dpkg-deb -x firmware-bnx2_0.14_all.deb bnx2

We need to copy the files under lib/firmware/bnx2-06-4.0.5.fw , bnx2-09-4.0.5.fw and bnx2/usr/share/initramfs-tools/hooks/firmware_bnx2 inside the extracted directory of the initrd and compress it back (from the extracted directory):

find . -print0 | cpio -0 -H newc -ov | gzip -c > ../initrd.gz

Advertisements

Useful bash tips

August 11, 2010

Addition of two int number  with awk –

echo $a $b | awk ‘{sum= $1 + $2 ; print sum }’

Multiplication and division of two floating number  with awk –

echo $a $b | awk ‘{ printf( “%.3f\n”, ( $1 * 100 ) / $2 );}’

res=`echo $a $b | awk ‘{ sum = $1 * $2 ; per = sum / 100; print per}’`

Mathematical operation with bc

res=`echo “$sum * $avg / 100” |bc`

free_t=`echo “$free / 1024  / 1024” |bc`

condition with bc –

if [ $(echo “$a < $b”| bc) -eq 1 ]

It will return either 0 or 1 depending on true or false.

Mathematical operation with bash

avg=`echo $((( $sum * 60 ) / 100 ))`

Conditional statement with awk

August 11, 2010

Sometimes bash failed to compare long integer. where awk language can easily compare integer of any range here is the way –

awk ‘BEGIN { if ( ‘$warn’ > ‘$crit’ )
{printf “Unknown.crit must be larger than warn\n”
exit 1}
if ( ‘$used’ < ‘$warn’ )
{printf “OK.Free Space: ‘$free_t’ GB, Space Left ‘$percent’%\n”
exit 2}
if ( ‘$used’ > ‘$warn’ && ‘$used’ < ‘$crit’ )
{printf “Warning. Free Space: ‘$free_t’ GB,Space Left ‘$percent’%\n”
exit 3}
if ( ‘$used’ > ‘$crit’ )
{printf “Critical. Free Space: ‘$free_t’ GB,Space Left ‘$percent’%\n”
exit 4}
}’

Comparing floating number

August 5, 2010

Suppose you wanna put a check whether your system load goes high or not??

load=`uptime |sed ‘s/.*average://’|sed ‘s/,.*//’`

val=0.01

res=`expr $load \> $val`

This expr command will return either true or false i.e. ( 1 or 0 )