DidactiCOde
  • Home
  • Works
  • Blog
  • Social
  • About

Guide: OS Multiboot - Saving NetBSD Bootloader

2/26/2017

Comments

 
Picture
Saving OS boot loaders to a file makes it easier to maintain a single master/primary boot loader at the start of the disk. It is also easier to restore the boot configuration by using files since they can be backed up in one place.

I like that NetBSD has retained a simple bootloader. Unlike Linux's Grub2 which has ballooned with an excess of features that rival interpreted programming languages, NetBSD just needs the tiny boot sector of old to enter its interactive boot manager. From here you can pick kernels, root partitions and quickly enter a unix environment where the full system is accessible!
Note: NetBSD 7's fdisk doesn't seem to read and write to a file as specified in the manual. This is very uncharacteristic because BSD documentation is clear by established practice. I used NetBSD 6.

Boot normally and start a root shell. If booting from install media, type "CTRL + Z" to suspend the installer and return to the parent root shell.

We will be working on "wd0" i.e. the first physical disk. "fdisk" is used to edit the physical disk parition table and boot configuration for MBR disks. The "gpt" command is used for editing GUID partition tables (GPT). This guide is for MBR disks. I might add a GPT section if I ever partition a disk as such.

Mount a writeable filesystem (that Windows can access) and navigate to the directory where the partition table will be stored.

Display the partition table and boot selector:
# fdisk wd0

Edit boot selector and write entire table to a file:
# fdisk -w boot_netbsd -u wd0

Explanation:
-w boot_netbsd: Instructs fdisk to write partition table to file "boot_netbsd" instead of the physical disk
-u: interactively edit/update the partition table

fdisk will ask if you want to change what the BIOS thinks (answer no), whether you want to update the bootcode (answer yes) and which partition you want to edit. I advise against using NetBSD's fdisk to change the partition structure since it uses absolute sector values whereas other Operating Systems prefer to align partitions to 4K boundaries. We just want to be able to boot NetBSD from a file so enter the partition number assigned to NetBSD, press enter to leave the "start" and "size" as is but enter "NetBSD" when prompted to enter "bootmenu." To delete a bootmenu entry, type a single space when prompted for its bootmenu name. You can ignore the other partitions to avoid phantom entries. Answer "yes" to write the partition table.

The file "boot_netbsd" will now be in the current directory. We need to set the timeout and default boot target:
# fdisk -r boot_netbsd -B

"-r boot_netbsd" reads the file we just wrote and "-B" instructs fdisk to interactively edit the boot menu options. Select the number of the NetBSD partition to be the default and set the timeout to "0" so that we can enter the actual NetBSD boot options without delay.

The file can now be used by Windows Loader to boot NetBSD as described in the Windows Loader guide.

Comments
comments powered by Disqus

    Categories

    All
    BlackBerry
    Computing
    Technology

    Archives

    February 2017
    May 2016

    CA Canadian Domain Name Registration and Web Site Hosting
Site powered by Weebly. Managed by Web Hosting Canada
  • Home
  • Works
  • Blog
  • Social
  • About