3.12. Boot Loaders

For PC / BIOS booting, the first sector of a hard disk partition or floppy disk contains boot code that is responsible for loading the operating system. Since 512 bytes are usually not sufficient for that, the (so-called) boot sector will only contain a first-stage loader that uses simple mechanisms to load a larger, second-stage loader. Since it is useful to know if a disk is bootable or not, disktype tries to detect these first-stage boot loaders.

These first-stage boot loaders are also found in El Torito boot images on CDs when floppy emulation is used. More recent CD loaders use non-emulated mode and thus don't have to fit into 512 bytes. They are typically 2K in size and can locate the OS kernel or the secand-stage loader by reading the actual ISO9660 file system.

disktype can identify a range of common boot loaders using clear text signatures in the boot sector. This currently includes the Linux loaders LILO, GRUB, SYSLINUX, and ISOLINUX, plus the original boot loader still built into each i386 Linux kernel. (Note that GRUB is not Linux-specific and is also used for other operating systems, Solaris x86 for instance.) Various boot loaders from FreeBSD, MS-DOS / Windows, and the BeOS family are recognized as well.

3.12.1. GRUB

For GRUB, disktype tries to determine the compatibility version code. Detection works starting with version 2.0. Older versions have no clear signature to scan for, but that doesn't matter much since they're ancient anyway.

Note that disktype only looks at the boot sector, which contains just the stage1 loader. The stage2 is usually located inside a file system. Sometimes, a filesystem-aware stage1_5 is used and put in a boot area at the start of a file system; disktype does not detect this yet.

3.12.2. FreeBSD

The native FreeBSD i386 loader has several stages that are placed in special areas of the disk. The first one, boot0, is actually a boot manager for the MBR, not a loader. It allows the user to choose the partition to boot. The second piece, boot1, is placed in the boot sector of the DOS partition (slice), i.e. before the BSD disklabel. It loads the next stage and runs it. The third piece, boot2, is more sophisticated. It loads the final kernel loader from a file in the root file system. boot2 itself just fits in the 7K of space between the disklabel and the UFS superblock, i.e. sectors 2 to 15.

disktype recognizes the three stages described above by their signatures. There are some more stages in the FreeBSD boot process, but they are outside of the scope of disktype.

3.12.3. Windows and MS-DOS

Boot loaders for Windows NT derivatives are recognized by scanning for "NTLDR". Boot loaders for non-NT Windows versions and MS-DOS are recognized by the "MSDOS   SYS" string.

3.12.4. BeOS and derivatives

disktype recognizes the boot loader from BeOS x86, and the updated version used by yellowTab in ZETA. Haiku (formerly FreeBeOS) uses a different loader which is also recognized.