About Blog Projects Papers Contact

I said I'd never blog

DeforaOS, NetBSD, reverse-engineering and stuff
Installing NetBSD 5.0 on a Netbook
Blog post by khorben
on Monday, January 5 2009, 03:30

Member of

First, I wish you all a happy new year, and I thank you for reading me :)

But let's get to this topic. Supposing you want to install NetBSD 5.0 onto your newly acquired Netbook (which has no CD-ROM drive), here's how you can create a bootable USB key with the necessary installation content.

Getting started

My other system is a NetBSD amd64 workstation, whereas the Netbook is i386. Once you have downloaded NetBSD sources to /usr/src:

# cd /usr
# cvs -d:anoncvs@anoncvs3.de.NetBSD.org:/cvsroot co -r netbsd-5 src
you are free to bootstrap a compilation environment, in /home/i386 for example:

# mkdir -p /home/i386/obj /home/i386/tools
# cd /usr/src
# ./build.sh -m i386 -O /home/i386/obj -T /home/i386/tools -u tools
Congratulations, you now have a cross-compiler for i386 on your system. What is usually a tedious task took only one command with the wrapper.

Compiling a kernel

It is easier to use NetBSD's build.sh wrapper again:

# cd /usr/src
# ./build.sh -m i386 -O /home/i386/obj -T /home/i386/tools -u kernel=INSTALL_FLOPPY
You should now have a kernel in /home/i386/obj/sys/arch/i386/compile/INSTALL_FLOPPY/netbsd. Let's make a copy in a more convenient location:

$ mkdir -p /tmp/netbook
$ cp /home/i386/obj/sys/arch/i386/compile/INSTALL_FLOPPY/netbsd /tmp/netbook/
This kernel is not yet usable as an installation kernel though: it is configured to run in RAM, but does not embed any such filesystem yet.

Creating a RAM disk

Again, this is quite straightforward:

# cd /usr/src/distrib/i386/ramdisks/ramdisk-big
# /home/i386/tools/bin/nbmake-i386
If all went well, you now have a ramdisk file in /home/i386/obj/distrib/i386/ramdisks/ramdisk-big/ramdisk-big.fs. If something went wrong, such as compiling restore (like for me), simply edit the list file and comment out this line as so:

#PROG	sbin/restore	sbin/rrestore
Let's make it more convenient again:

$ cp /home/i386/obj/distrib/i386/ramdisks/ramdisk-big/ramdisk-big.fs /tmp/netbook/
Preparing the kernel

We can now embed the ramdisk inside the kernel. It only takes this:
$ cd /tmp/netbook/
$ mdsetimage -v -s netbsd ramdisk-big.fs
$ gzip -9 netbsd && mv netbsd.gz netbsd-INSTALL.gz
This kernel is now able to start the installer. By booting it, we could already download and install a system, if the sets were available. Unfortunately, we may have to compile them ourselves at the moment.

Generating the sets

This should just work:
# cd /usr/src
# ./build.sh -m i386 -O /home/i386/obj -T /home/i386/tools -u sets
It will also help for the following step to copy the sets over:
$ cp -R /home/i386/obj/releasedir/i386/binary/sets /tmp/netbook/
We will also need a kernel, for which the GENERIC configuration should be safe:
# cd /usr/src
# ./build.sh -m i386 -O /home/i386/obj -T /home/i386/tools -u kernel=GENERIC
Creating the kernel set should be as simple as this:
$ cd /tmp/netbook/
$ cp /home/i386/obj/sys/arch/i386/compile/GENERIC/netbsd .
$ gzip -9 netbsd && mv netbsd.gz netbsd
$ tar -czvf kern-GENERIC.tgz ./netbsd
Make a bootable USB key

Now comes the tricky part. First, identify how your USB key is seen by the system. A good way to do so is to run:
$ tail -f /var/log/messages
and to read what the kernel has to say. It should print something like this:
/netbsd: sd0 at scsibus0 target 0 lun 0: <, , > disk removable
/netbsd: sd0: fabricating a geometry
which means, in my case, that the key is seen as sd0. If it is already formatted as a FAT volume, you should be able to mount it like this:
# mkdir -p /mnt/usb
# mount /dev/sd0e /mnt/usb
You can make sure that it is the case through the disklabel command:
# disklabel sd0
[...]
5 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
d:   2023424         0     unused      0     0        # (Cyl.      0 -    987)
e:   2021634        62      MSDOS                     # (Cyl.      0*-    987*)
(the d partition is virtual and represents the whole disk)

Starting with the obvious, it is time to copy the installation kernel and associated sets onto the USB key:
# cp /tmp/netbook/* /mnt/usb
# mv /mnt/usb/netbsd-INSTALL.gz /mnt/usb/netbsd
Booting will also require this file on the key:
# cp /usr/mdec/boot /mnt/usb
It is time to unmount the media:
# umount /mnt/usb
And finally, the following command will make the key bootable:
# installboot -v -o timeout=5 /dev/rsd0e /usr/mdec/bootxx_msdos
Troubleshooting

If the key does not boot, it can be that:

  • there is already a bootloader in the Master Boot Record (MBR)
  • the partition needs to be active
  • the partition is incorrectly formatted
You may refer to the manual page of installboot(8) for more details. Alternatively, it is also possible to use grub to boot the key.

Come back...

Creative Commons License RSS