This Space for Rent

Software patch of the week

At work, I've been playing around with ways of loading our Linux distribution onto the various servers that we use. The first round of this, which happened about a year ago, was to switch from a ugly (and potentially dangerous) isolinux loader menu to one written on freedos, because I could wedge that onto a floppy image and not have to worry about cdrom drives that would freak out when confronted with an isolinux-style cd. At the time, we were pretty sure that our machines would use IDE cdroms to boot off for the forseeable future, so the somewhat elaborate contortions that I had to go through to make this booter work didn't seem to be that much of a problem.

A year later, after a few rounds of

  1. freedos relocating extended bios data into places where Linux can't find it anymore,
  2. The kernel getting big enough so that loadlin was unable to load it (but not actually saying that it was too big to load. No, what loadlin did was far nastier; it would cheerfully truncate the load image in such a way that the system would lock up and die part of the way through the boot process. This took a while to figure out because I was naively assuming that free software doesn't suck™)
  3. Switching to linload, and having to rearrange many things to get around the horrible limitations it has, like not being able to coherently load parameters from batchfiles, but instead having to cram all of the options that the installer wants into a 125 character DOS command line.
the final straw came when we started using machines that didn't have IDE cdroms anymore. I could have gone right back to the original isolinux menu, but it was ugly, and it offered many opportunities for user error in that all of boot options, for serial and vga console, were all plunked down on the same menu, and if you were loading from a modem and accidentally told it to do one of the vga console commands, you'd end up having to roll a field service truck to reboot the stupid computer so you could make the same mistake again.

But one of the tweaks I did for the freedos loader was that it only gave the three options we wanted, and behind the scenes kept track of where the input was coming from and built linux command lines suited to the device you were typing to it at. I liked that tweak, and didn't want to get rid of it, but isolinux doesn't actually seem to have any way to duplicate this feature. Or, actually, didn't have any way to duplicate this feature. I sat down for a few days last week and beat up on the 8086 assembly language parts of isolinux so that I could do source-sensitive LABEL's in isolinux.cfg.

How did I do it? By an evil hack, forgiven by repeating the chant "it's a bootstrap loader; it's supposed to be unreadable" 30 times. I added a prefix byte to the command line buffer, and set that prefix to '+' or '-' depending on whether the input is coming from the vga or serial console. Then I modified the code that searches for kernels to first search for the command by itself, and then if that didn't work, to re-search with the command plus the given prefix. Which means that a label like LABEL +1 matches 1 entered from the vga console, and LABEL -serial matches serial entered from the serial console. If you're not someone who writes 8086 assembly language for a living (and even if you are and still retain some self-respect), you probably shouldn't look at the code or patches, but if you've succumbed to the dark side, here it is, in full glory (note that I don't use named constants for + and -, so when the ascii definition of them changes this loader patch will immediately fail.)

And in case you're wondering, Syslinux is GPLed, so this patch is communist software from head to toe.