phaqphaq

“a geeks daily life”

Archive for October, 2006

Prototype Mismatch in APR::XSLoader::BOOTSTRAP

Tuesday, October 31st, 2006

Well, today I just did not believe my eyes.

I was just bringing up a new webmail host when I noticed Apache throwing an 500 internal server error at me.

Looking at the error log I saw this line:

[Wed Jan 01 00:16:35 2003] [error] [client 127.0.0.1] Prototype mismatch: sub APR::XSLoader::BOOTSTRAP: none vs () at /usr/local/lib/perl5/site_perl/5.8.8/mach/APR/XSLoader.pm line 24. BEGIN failed–compilation aborted at /usr/local/lib/perl5/site_perl/5.8.8/mach/APR/XSLoader.pm line 26. Compilation failed in require at /usr/local/lib/perl5/site_perl/5.8.8/mach/Apache2/Reload.pm line 161.

At first I though to be going mad because that server had just worked only few hours ago. Why would it fail like that after relocating it?

At second thought I noticed the time stamp which said “Wed Jan 01 00:16:35 2003″.

Well, the server had likely lost it’s CMOS settings during relocation. So after correcting the time through ntpdate the error had disappeared and Apache/mod_perl worked like a charm again. :-)

Convert Single Disk to GEOM Mirror

Saturday, October 28th, 2006

This article should have been published already last month, unfortunately the draft was left forgotten for a while in my mailbox.

As some may remember I published two articles on how to setup GEOM disk mirroring on alpha and sparc earlier this year. These articles were originally based upon Ralf Engelschalls disk mirroring howto.

I had installed GEOM disk mirrors on various occasions since then, though I always felt that converting to a GEOM mirror like that involved too much work.

So I went on to find a better and faster way to achieve the task and I found one.

But be warned first: it is faster after all, even less error prone IMHO, but still dangerous if you are not very careful. Foremost you must consider that this procedure involves single user mode so local access (serial terminal for doing this remotely) is a must!

The instructions assume that you have two hard disks identical in size which are /dev/ad0 and /dev/ad1. Apply the instructions to fit your own system.

#1 Reboot into Single User Mode

#2 fsck and mount / fs read/write

First run an fsck on your root filesystem:

#fsck -p /

Then mount it with read/write access:

#mount -w /

#3 Edit /etc/fstab

First change your /etc/fstab. Replace all your single disk slices by the geom provider. The example shows a disk with a single root and swap slices.

# Device	Mountpoint	FStype	Options	Dump	Pass#
/dev/ad0s1b	none		swap	sw	0	0
/dev/ad0s1a	/		   ufs	    rw	     1       1

Change it to look similar to this:

# Device	Mountpoint	FStype	Options	Dump	Pass#
/dev/mirror/gm0s1b	none		swap	sw	0	0
/dev/mirror/gm0s1a	/		   ufs      rw	     1	     1

#4 Enable GEOM MIRROR kernel module

Edit your /boot/loader.conf and add the following line:

geom_mirror_load="YES"

#5 Enable Crash Dumps (optional, but recommended)

If you want to enable crash dumps to your GEOM provider you should add this line to your /etc/rc.early:

gmirror configure -b prefer gm0

And this should go to your /etc/rc.local:

gmirror configure -b split gm0

Have a look at gmirror(8) to understand what this means exactly.

#6 mount / fs read-only

Sync and mount your root file system read-only. This is very important to complete successfully. This is also why you must do this in single user mode.

#sync && sync
#mount -r /

#7 Initialize GEOM provider

First you must raise the GEOM debug flags:

#sysctl kern.geom.debugflags=16

This will allow to initialize a GEOM provider even if it is locked by the kernel.

#gmirror label -v -b split gm0 ad0

#8 Reset

Now it’s best to press the reset button (yes, you heard right!). This is absolutely safe as long as your root fs is in read-only mode.

Do not try to invoke reboot / shutdown as this will lead to a kernel panic. By labelling the GEOM provider you have taken away the underlaying device from the kernel.

Doing so will cause the machine to reboot after the panic, the reset button may be the better choice however.

#9 Boot

Your system should now boot from the GEOM consumer gm0 with your /dev/ad0 as the first provider.

It does not actually matter if you boot into multi-user or single-user mode. In either case you must add the second hard drisk to the GEOM mirror.

#gmirror insert gm0 ad1

This will cause your /dev/ad1 to be synced against /dev/ad0. Your dmesg should print something like this when starting:

Aug 19 11:26:37 localhost kernel: GEOM_MIRROR: Device gm0: rebuilding provider ad1

And something like this when finished:

Aug 19 12:34:17 localhost kernel: GEOM_MIRROR: Device gm0: rebuilding provider ad1 finished.

Congratulations: your GEOM mirror is now up and running!

These instructions were originally put together when trying to upgrade my PC-BSD to a GEOM mirror. They have been verified at least a dozen times since then in the lab.

Interoperability Problems: Samba, Windows, Rsync and Unicode

Saturday, October 28th, 2006

A late night experience, thank good I got it fixed right away…

Imagine this setup:

  • A Samba file server (primary) and a Windows file server (secondary).
  • A DFS root which points to the Samba server (as primary) and the Windows server (as secondary, which maintains a replica of the primary).
  • An rsync client (cwrsync) is installed on the Windows server to maintain the DFS replica

Imagine the fact:

  • Files/directories which contain special chars (eg. umlauts) in their name copied onto the Samba server end up there correctly (eg. hütte.doc)

Imagine the problem:

  • Files/directories which contain special chars in their named copied through rsync onto the Windows server end up there mangled (eg. hütte.doc)

The reason for this behavious is simple: cwrsync is actually nothing else than traditional rsync compiled as win32-binary using cygwin. Now rsync has one major drawback: it’s not (yet) unicode aware, which means that special characters in file names are not properly converted.

Now there are two ways to fix this. Either replace the bundled cygwin library (cygwin1.dll) with another one which is unicode-aware. You find one at the UTF-8 cygwin project website.
Another possibility would be the use of an alternative tool (anything else than rsync) which is unicode-aware or the .NET based rsync port.

I choose to go the UTF-8 cygwin way, which did the trick for me.

I just downloaded the 1.5.21-1 version (I checked the bundled cygwin1.dll version through properties dialog in explorer first to make sure they match), moved the original cygwin1.dll away and replaced it by the download version instead.

By the next time I ran cwrsync my filenames would just look as supposed. Wheew, what a night…!

Another Positive Experience With Windows Server 2003

Saturday, October 28th, 2006

While I’m usually living on the Unix side of live, I sometimes happen to find myself again in the Windows world.

Some may say this is blasphemy, a decent unix admin would never bother in doing Windows, deny the open source idea, be such a scumbag, blablablabla…

But let me tell you one thing: Windows is not that bad after all. Honestly.

Why can I say: Because I’m writing code on Windows, I’m working with Windows (my personal workstation runs PC-BSD however…), I see and I feel when it makes progress. (Still, I’m a unix admin after all…)

My most recent experience was tonight. I went to setup an AD domain controller on my recently acquired Windows Server 2003 (180-day trial license).

I remember how long this took on my testing system (an ancient Celeron 733 with 1gig of RAM) with Windows 2000 just two weeks ago: almost 30 minutes only to initialize a new AD structure.

The very same process on the same machine with Windows Server 2003: not even five minutes! I could not believe this at first so I repeated this after doing a reinstall – with the same result.

Now this is definitely what I call progress, especially considering this kind of old hardware being used!

And for those who may have wondered: the whole purpose to setup the AD domain controller is to see wether an AD-driven LDAP may be merged with OpenLDAP to provide authentication services in a mixed environment. More about this shall be coming soon…

Find And Replace Strings

Friday, October 13th, 2006

Imagine you have a directory with thousands of text files, each of which containing some keywords to be replaced.

While there’s a lot of tools out there allowing you to find and replace strings in text files, there’s always a goog reason to use the tools that you already have.

This snippet uses find in combination with perl to achieve the task:

#find /my/path -type f -exec perl -i -p -e ’s/search/replace/g;’ {} \;

This command line instructs to find all files within /my/path, passing them to perl, which is instructed to find and replace given strings instantly.

Rememver however that this is not binary sage so you should run this only on directories containt text files.

The get additional verbosity add the ‘-print’ flag to find’s command line to see which files is being worked on.

If you pass an optional extension to ‘-i’ (eg. ‘-i.bak’) perl is instructed to create a backup by the same filename plus extension.

As always: man find and man perl are your friends.

Enjoy!