phaqphaq

“a geeks daily life”

Archive for May, 2007

FreeBSD’s loader fails with wrong harddisk geometry in BIOS

Friday, May 25th, 2007

I’s been a while since I last saw issues with FreeBSD’s loader(8).

The error I came along today read like this:

can't load kernel

The most obvious reasons would be that either the kernel is missing or it’s filename was specified incorrectly.
I thought to verify this by issueing ‘ls’ in the first place, only to notice that it would show nothing.
Wait! This is supposed to show the root directory contents, isn’t it?

Maybe loader didn’t catch up with tje devices? Let’s look at them:

lsdev
disk devices:
    disk0: BIOS drive C:
         disk0s1: FFS bad disklabel

Well, this is not supposed to happen at all.

Obviously loader can see the device but is unhappy with the disklabel.

Given the fact that the disklabel is not corrupt, which can easily be verified if the system is booted by using a recovery disk or a FreeBSD bootonly CD, then there must be some other reason for this.

So I checked the disk in question for it’s logical configuration, which was manually established by means of fdisk and disklabel.
This and also the filesystem were intact and did not reveal any errors.
To make sure I even checked the primary boot blocks and re-installed them using the ‘boot0cfg -o packet ad0′ command to ensure use of LBA addressing.

Since it would still not boot from the device I checked with my BIOS where I noticed that it reported the disk’s translation mode as being “automatic”.

I suspect “automatic” in this consensus likely meant ‘CHS’ and not ‘LBA’, this is why loader(8) failed on the disk.

After changing BIOS disk translation mode to ‘LBA’ it finally worked out.

Vista on Xen: Using NE2000 in favor to RTL8139

Monday, May 21st, 2007

I finally took the time getting Vista to work in Xen.

Unfortunately there is a bug which prevents the emulated RTL8139 NIC from working properly in Vista (32-bit version concerned only, 64-bit version worked properly).
This seems a known issue after all and there exist several workarounds on the net concerning this case. So far they basically cover how alternate drivers may be patched together to go along with Vista.

The main reason for this is simple: the RTL8139 runs at 100 mbit/s and is required to get decent speeds.

However there is also the possibility to run the guest domain with NE2000 NIC emulation. Albeit this will only give you a network connection speed of 10 mbit/s full-duplex it is easier to get working right away without fiddling around with INF files and such.

Even though Microsoft dropped NE2000 driver support in Vista the NIC may still be used along with the NE2000 Drivers for Windows 2000.
To enable the use of NE2000 NIC emulation I changed my HVM configuration file accordingly:

vif = [ 'type=ioemu, bridge=xenbr0, model=ne2k_pci0 ]

Since my Vista lacked networking support I placed my driver image into an ISO image and changed the HVM to assign a virtual CD-ROM drive:

disk = [ 'file:/mnt/vm/Xen/Vista/disk1_vol1.img,hda,w',
'file:/mnt/vm/Xen/Vista/drivercd.iso,hdc:cdrom,r' ]

The ISO image was created as follows:

mkisofs -o drivercd.iso -J -r /path/to/w2k_8029.zip

The NE2000 Driver ISO is also available as download from my site.

After starting up Vista skip the ‘Add New Hardware Wizard’ in the first. Instead extract the ZIP file from the (virtual) CD-ROM drive to a temporary location.
Afterwards go to Device Manager and select the (yet) unknown pci device and choose the ‘Update Driver’ option from the Drivers tab.
From there go along with ‘Browse My Computer for Software’ and ‘List of Drivers on My Computer’ and clich the ‘Have Disk’ button.
Open the folder containing the extracted ZIP file’s contents and locate the NETRTP5.INF file. You should be given the choice of the ‘Realtek RTL8029 PCI Ethernet NIC’ which you are to accept.
After completing driver installation you should go device properties’ Extended tab and set ‘Duplex Mode’ to be ‘Full Duplex’ for best performance.

Using NE2000 NIC emulation Windows Vista will get basic network connectivity. It is easy enough to install for everybody and provides modest network speed.
If you need FastEthernet performance there is no way around patching drivers, using Vista64, waiting for an updated official driver or some guru to fix it in Xen itself (even if they didn’t screw it up in the first place…).

[Update 2007/06/30]

Here’s one thing I forget to note when I wrote the article in the first place.

Xen (at least 3.0.3 which I run) seems to have a bug which resets the NIC emulation from NE2000 to RTL8139 upon reset of the HVM.

Because of this I changed my HVM config file to destroy the HVM so I won’t end up with a non-working NIC emulation.

on_reboot = ‘destroy’
on_crash = ‘destroy’

No “sleep” command for batch files? Make it a choice!

Saturday, May 5th, 2007

I just trapped myself while hacking up a batch file.
Used to shell scripting I wanted to add a delay to the batch using “sleep”.

Dough! Bad Idea! Bad command or filename. Smash your head here to continue {(x)}!

So I winded up my memories from stoneage. Wasn’t there the choice command!?

Yeah, after some lurking around with the ‘/?’ feature I had stuck it together:

choice /c 1 /d 1 /t 1 > nul

While

  • “/c 1″ sets the choice values (1 is my value)
  • “/d 1″ sets the default choice value (which is 1 from above)
  • “/t 1″ sets the timeout to 1 second (or whatever is appropriate)
  • “> nul” means the same as “>/dev/null”: send output to nirvana (notice there being only one ‘l’ however)

Of course this may be bothersome to type if you use it often, so a “batch function” may be better, especially when you need other batch tricks to get around DOS command limitations (lazy man’s approach: create a second batch file for it).

@echo off

rem *******************
rem check args
rem *******************

:checkargs

if "%1/" == "func/" goto callfunc
goto main

:_checkargs

rem *******************
rem call functions
rem *******************

:callfunc
 shift

 rem we could do "goto %1" instead
 rem if there is a lot of functions
 if "%1/" == "sleep/" goto sleep

 goto exit

:_callfunc

rem *******************
rem function sleep
rem *******************

:sleep
 shift

 choice /c 1 /d 1 /t %1 > nul

 goto exit

:_sleep

rem *******************
rem main body
rem *******************

:main
 echo hello, going to sleep now
 call %0 func sleep 1

 echo sleep is over, good bye

 goto exit

:_main

rem *******************
rem exit handler
rem *******************

:exit
 rem if there is anything left to do, do it now.

:_exit