Sunday, May 15, 2011

Making NetBSD dual boot with Linux

The day I decided that I am going to submit a  proposal for NetBSD for GSoC 2011, I installed it on one of my primary hard disk partitions to give it a try and have more solid understanding of the platform before I start to write my proposal. Installing NetBSD is a very easy thing to do, and the NetBSD guide [1] does a great job explaining the whole installation process in a very detailed manner.

However, It's not easy to just switch to a new OS all of a sudden, so I wanted to setup a dual boot system alongside with my existing Linux. Although the NetBSD guide does mention about setting up dual boot systems but it didn't discuss about the possible caveats that may crop up in the process, and as it turns out, setting up a dual boot of NetBSD + Linux can be a tough nut to crack for the newbies.

So, here I am writing this blog post after having fixed the problem. I hope this post will be useful for me in the future and to others who may also come across this not so rare problem. 

The following guide assumes that you already have Linux installed on one of your partitions and you are installing NetBSD.

In the NetBSD partition manager screen where you need to select the partition to install NetBSD, let the 'd' and 'a' flags remain with the Linux partition and set the 'I' flag only for the NetBSD partition. 

Do not install the NetBSD boot loader when sysinst (the NetBSD install program) prompts you to while installing NetBSD.
Don't install the NetBSD bootcode in MBR

After the installation of NetBSD finishes and you reboot, you will be directly booted into Linux (no surprises here), because we did not install the NetBSD boot loader in the MBR and GRUB didn't know about the existence of NetBSD so it directly booted Linux. Our next step will be to tell GRUB about NetBSD so that from the next time onwards it will give us a choice between NetBSD and Linux.

Note: These instructions are for GRUB2

  • Create a file 06_netbsd in /etc/grub.d/ and write the following script in it to chain load the NetBSD boot loader:

#!/bin/sh -e
echo "Adding NetBSD 5.1 on sda1 to GRUB 2 menu"
cat << EOF
menuentry "NetBSD 5.1 on sda1" {
insmod bsd
set root=(hd0,1)
chainloader (hd0,1)+1
This script assumes that you have installed NetBSD in the Ist partition of your first hard disk. GRUB2 counts hard disks from 0 but partitions from 1, thus we have (hd0,1). If for example you had NetBSD in the 3rd partition, you would use (hd0,3).
  • Make this script executable by the following command:
$sudo chmod a+x 06_netbsd
  • After this, we need to tweak another file. Run the following commands:

 $sudo gedit /etc/default/grub 

  • In this file you need to comment out the line saying: 


To comment it out, simply put a # in front of this line in the file and save it.

  • Now we need to run the 'update-grub' command and we are done. After running 'update-grub' , GRUB2 will add menu entry for NetBSD in it's configuration file (boot.cfg) and the next time you boot, you will be presented with the options to boot either into NetBSD or Linux.

For those using GRUB (not GRUB2), I believe they can simply add the menu entry in the menu.lst file and it should be ok (I am not sure, as I did not try). Also GRUB used to count partition numbers from 0, so if you had installed NetBSD in the Ist partition you would use (hd0,0)

In the end I would like to say that, these are my personal notes and might be opinionated at some points. I am pretty sure there must be other ways of doing it even from NetBSD. This method worked for me the best.


  1. though i know absolutely nothing about NetBSD and a very little about Linux but the way u wrote it.. that makes it look very easy.. :-)

  2. @Sach thanks buddy :). Its an easy thing to do as well.

  3. This comment has been removed by the author.

  4. I just google'd the same problem about dual-booting and come across your blog, thanks for taking time to write and explain this


  5. Thanks for the feedback. I am glad that it is helpful :)

  6. Still a useful tip for those using the rather obtuse NetBSD installer.

  7. for Tips And Tricks Visit Here

  8. Grub4dos (puzzling name; it's cross-platform!) can chainload the NetBSD 2nd-stage bootloaders (bootxx_ffs2, bootxx_ext2fs et al), It's therefore possible to go from a grub4dos menu to a NetBSD boot,cfg menu. The only catch is that the NetBSD third-stage bootloader has to be called "boot" (short of recompiling the 2nd stage bootloader...) which means that grub4dos has to be in a directory that isn't named "boot".

    Here's a grub4dos menu.lst entry to accomplish the above on a grub4dos bootable cdrom:

    title chainload NetBSD cd9660 bootblock
    chainloader /bootxx_cd9660

    Getting grub4dos to read it's own menu.lst on a cdrom is another story, but it can be done. Probably easy on writable media!

  9. Helpful, even though it did not work for me, it got me going. I have Fedora 21 and although you would think it uses
    grub2, e.g., it has a directory saying grub2, it is quite different from your explanation. The command grub-update does not even exist.

    How I solved the problem: when Fedora boots, I interrupt by pressing the space bar. I enter
    in order to to get to the grub prompt for commands. My bootable or active NetBSD partition is on what the grub
    from Fedora thinks of as (hd0,msdos2) partition. So I first load this kernel with the command

    knetbsd (hd0,msdos2)/netbsd

    Then I boot from this with the boot command:

    boot (hd0,msdos2)/netbsd

    And my installation of NetBSD works as well as it ever did before
    I installed Fedora. That is, it never really worked: neither did FreeBSD:
    startx has its connection refused, so it's just like the good old days in 1977....