Thursday, June 25, 2009

Debian Installation on Servers With Broadcom 5708/5709 NICs using the bnx2 driver

Installing Debian on a system with Broadcom network interfaces can be quite annoying because the firmware is no longer included. If you load the firmware onto a usb disk as suggested, you run into other problems when using scsi drives resulting in a system which requires hacking menu.lst after install to boot. This approach doesn't work if you're using iLO/DRAC/iDRAC to install as they only allow one remote media connection at a time.

An easy workaround is to modify your install iso to contain the drivers. Here's how:
  1. Download a newish Debian install iso.
  2. Mount the install iso:
    1. mkdir cdrom
    2. mount -o loop debian-testing-amd64-CD-1.iso cdrom
  3. Copy the files:
    1. mkdir isocopy
    2. cp -av cdrom isocopy
  4. Download the appropriate firmware package for your installation, such as http://packages.debian.org/squeeze/all/firmware-bnx2/download
  5. Extract the drivers and copy into your new iso:
    1. dpkg-deb -x firmware-bnx2_0.16_all.deb firmware
    2. cp firmware/lib/firmware/* isocopy/cdrom
  6. Build a new iso:
    1. cd isocopy/cdrom
    2. mkisofs -o ../modified-debian.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V disks .
  7. Done, let's look at our new iso:
    1. cd ..
    2. ls modified-debian.iso

You can now burn this iso to a CD or use it as virtual media.

There's one final step, which is getting the OS to see the firmware drivers.

Once booted to the new ISO, you need to immediately switch to another console and copy the files over before the installer looks for them:
  1. mkdir lib/firmware
  2. cp /cdrom/*.fw lib/firmware
After that's done, the Debian installer should be able to autoload the bnx2 driver without any problems.

Monday, June 15, 2009

php utf-8 chr() and ord() equivalents

As far as I can tell, PHP provides no built in methods of working with multi byte characters.

Here is a simple function for turning an integer value into a character:

function unichr($intval) {
return mb_convert_encoding(pack('n', $intval), 'UTF-8', 'UTF-16BE');
}

A uniord() function can be found in the comments of the PHP manual:
http://us.php.net/manual/en/function.ord.php

Monday, May 25, 2009

"This PDF document contains an Adobe XML form. Such files cannot be optimized."

To fix this problem:
  1. Save the document in LiveCycle with PDF compatibility
  2. Use the drop_xfa command with pdftk
This removes all of the LiveCycle data and makes the file compatible with Acrobat and other tools.

Tuesday, March 31, 2009

Some useful MegaCli commands/quick debian howto

MegaCli and MegaCli64 are the LSI utility used for Dell Perc 5 and other adapters isn't well documented. Here's some commands:

MegaCli -AdpEventLog -GetEvents -f logfile -aALL
What it does: Dump all events from the adapters event log to a file named logfile

MegaCli -PDList -aAll | less
What it does: Dump information about all Phsyical Disks (hence the PD), paged with less

MegaCli -LDInfo -LAll -aAll | less
What it does: Dump information about all Logical Disks on all adapters, paged with less

MegaCli -LdPdInfo -aAll | less
What it does: Dump information of all logical and physical disks on all known adapters

Currently these can be obtained from LSI at http://www.lsi.com/DistributionSystem/AssetDocument/support/downloads/megaraid/miscellaneous/linux/1.01.39_Linux_Cli.zip

You don't need to actually install the packages, both the MegaCli and MegaCli64 (64 bit build) are statically linked within. In order to access them in a non RPM environment, you can extract the files with the following command:
rpm2cpio MegaCli-1.01.39-0.i386.rpm | cpio -idmv
This will extra the MegaCli and MegaCli64 executables.
Alternately, you can try to convert the rpm to a .deb via alien.

Sunday, March 29, 2009

Video of morse code blinking

I modified a bike blinker to blink in morse code. Video of it in action is
here

Source is here.

Tuesday, March 10, 2009

One cause of "Fatal error: Exception thrown without a stack frame in Unknown on line 0"

"Fatal error: Exception thrown without a stack frame in Unknown on line 0" can be quite hard to debug.

php -r '
register_shutdown_function("a");
function a() {
$b = new DateTime("02/40/2009");
} '

Results in:
Fatal error: Exception thrown without a stack frame in Unknown on line 0

The problem is that PHP does not allow exceptions to be thrown in a shutdown function or anything called by a shutdown function. Initializing a DateTime object with an invalid date throws an exception, leading issues similar to above.

Friday, February 27, 2009

Fun with PHP implicit scoping on static calls

class a {
public $a = "yay!";

func call_b()
{
b::b();
}
}

class b {
function b()
{
echo $this->a;
}
}

$a= new a();
$a->call_b();


Prints:
yay!

This is because if you statically call a method that is not declared as static in PHP, it inherits the class scope of the caller. Note that if you had declared function b as a static method, you'd get a different behavior.