GPT aware boot loader &mdash how to install and use

Bootloader structure overview

First of all please note that despite of GPT in it's name the loader is not related to EFI/UEFI. The main goal of the loader is to provide ability to bootstrap the NetBSD from GPT partitioned disk on a PC BIOS computer.

By nature the GPT loader is very similar to usual NetBSD MBR loader. It comprised of the following three parts:

How to build the loader

In order to build and install the loader you should have the following: The following steps are describing what and how you'd need to build:
  1. Download all the sources above.
  2. Prepare src tree to patching by making directories missing. See list of the directories inside the patchfile:
    $ awk '/^WARNING:/ {print $(NF)}' gptboot.patch
  3. Apply the patch.
  4. Build GPT loaders and tools at the following directories: All of above builds just fine on NetBSD 5.0 (including amd64) without cross compilation. The installboot may require passing -DSMALLPROG to make(1) to exclude extra stuff and simplify the build process. Also, new sys/sys/bootblock.h has to be used in place of /usr/include/sys/bootblock.h.

Loader installation

First of all prepare your disk. The disk should be GPT partitioned and have at least two partitions: one for NetBSD, and one for boot loader:
# gpt create sd0
# gpt add -s 65536 -t efi sd0
# gpt add -t ffs sd0
# gpt show
then issue a set of dkctl addwedge commands or reattach the disk to configure dk wedges automatically
NB: wedges are not supported on vnd(4) devices.

Next, format partitions accordingly:

# newfs_msdos -F 16 /dev/dk0
# newfs /dev/dk1
Please note that newfs_msdos seems have a bug and can incorrectly determine filesystem size (check number of file sectors reported by newfs_msdos — it must be less or equal to partition size). It it appears, please reformat filesystem explicitly specifying correct fs size via newfs_msdos -s option.

Install loaders:

# .../gpt biosboot -c $NETBSDSRC_DIR/sys/arch/i386/stand/mbr/mbr_gpt/mbr_gpt sd0
# .../installboot /dev/rdk0 $NETBSDSRC_DIR/sys/arch/i386/stand/fatboot/fat16/bootxx_fat16
# mount -t msdos /dev/dk0 /mnt
# cp $NETBSDSRC_DIR/sys/arch/i386/stand/boot/biosboot/boot /mnt
# echo "menu=Boot NetBSD:boot hd0b:netbsd" > /mnt/boot.cfg
# umount /mnt
The gpt(8) will automatically find EFI System Partition on sd1 and instruct mbr_gpt where to load PBR from. But rest loaders should be installed on dk wedges. If you're confused about the names, you may use gpt(8) on a wedge, but in this case mbr_gpt will load PBR from the specified wedge:
# .../gpt biosboot -c $NETBSDSRC_DIR/sys/arch/i386/stand/mbr/mbr_gpt/mbr_gpt dk0

Install kernel and base system files:

# mount /dev/dk1 /mnt
# cp /netbsd /mnt
then create usual NetBSD hierarchy: /dev, /etc, /sbin, etc...
and specify root partition as it will be enumerated by DKWEDGE_AUTODISCOVER:
# echo "/dev/dk1 / ffs rw 1 1" > /etc/fstab
# umount /mnt

Please note disk names on previous steps. It might be somewhat confusing, so there is some explanation:

Reboot. Have fun.

Problems

The loader still work in progress so please check todo, bugs, and caveats page for possible misbehavior. Anyway, please feel free to contact me in case of problems, and also with ideas or comments.


« Return to main page
Mike M. Volokhov (mike.volokhov (at) gmail.com)
$Id: howto.html 38 2009-10-16 08:38:31Z mishka $