View Single Post
  #1   (View Single Post)  
Old 12th February 2016
danboid danboid is offline
Port Guard
Join Date: Feb 2016
Posts: 12
Default Installing NetBSD to HD/SSD on the Banana Pi

NetBSD Installation Guide for A20 / A31 based boards

Start with an ARMv7 image from evbarm-earmv7hf/binary/gzimg/armv7.img.gz from NetBSD 7.0
Download a U-Boot build for your board
Download the correct build from the linux-sunxi web site
Decompress the image via gunzip(1):

# gunzip armv7.img.gz
Write the u-boot-sunxi-with-spl.bin loader to the empty space at the start of the base image:

# dd if=u-boot-sunxi-with-spl.bin of=armv7.img bs=1k seek=8 conv=notrunc
Write the image to an SD card (e.g.: if the SD card is recognised as sd0 - please check the dmesg(8) output to be sure!), under NetBSD:

# dd if=armv7.img of=/dev/rsd0d bs=1m
Under Linux:

# dd if=armv7.img of=/dev/mmcblk0 bs=1M; sync
Prepare a boot.cmd file for U-Boot boot loader containing the needed instructions regarding how to boot the kernel (basically the bootargs that are passed to the kernel and how to load the kernel from a device to the RAM and then boot it from the memory address). You need to set the kernel value to match the correct kernel for your machine ie netbsd-BPI.ub for the Banana Pi:

setenv kernel_addr      82000000
setenv kernel           netbsd-BPI.ub
setenv bootargs         "root=ld0a console=fb"

fatload mmc 0:1 ${kernel_addr} ${kernel}
bootm ${kernel_addr}
The boot.cmd text file should be converted in a script image - boot.scr for U-Boot via mkubootimage(1):

# mkubootimage -A arm -n armv7 -T script boot.cmd boot.scr
<Here we need a link to a fork of the mkubootimage source that will build easily under Linux, OSX and maybe even Windows (with cygwin?)>

Copy the boot.scr to the MS-DOS partition of the SD card.

On first boot NetBSD will resize itself to fill your SD card and then automatically reboot. The second boot will boot into the OS but will take longer than usual due to SSH key generation. You can log in as root, there is no default password.

Transferring the root partition from SD card to a SATA drive

First, check your drive is detected:

# dmesg | grep wd0
In this example I'll create a swap partition roughly 2 GB in size and use the rest of the drive for the root partition.

# disklabel -i -I wd0
Accept the defaults for the Filesystem type and the start offset by pushing ENTER. When disklabel asks you for a partition size, look at the last figure within the square brackets and subtract about 2048 from it if you want a 2 GB swap partition. Enter this number appended with a capital M eg `1905000M`. When you are back at the partition> prompt enter:

Filesystem type [unused]: swap
Start offset: a     # Start partition b at the end of partition a
Partition size: $     # `$` means use the rest of the available space on the drive
Type `P` to print and verify your new partition map then `W` to write it to disk. Type `y` when it asks you "Label disk?" to confirm the writing of the label then type `Q` to quit disklabel. Then run:

# newfs -O2 /dev/rwd0a
# mount -o log /dev/wd0a /mnt
# pax -X -rwpe / /mnt
After the pax command has completed copying the files from the SD card to the SATA drive, it is likely to report a number of skipped files located under /mnt/var/run and /mnt/var/spool but you don't need to worry about these.

Edit /mnt/etc/fstab and substitute `ld0a` for `wd0a` and `ld0b` for `wd0b` then run:

# halt
To halt NetBSD so that you can safely remove the SD card.

The NetBSD 7.0 evbarm kernels are hard-coded to mount the root fs from the SD card (ld0a) so the final step is to replace the kernel image on the DOS boot partition of the SD card with one that has been patched to mount wd0a as the root fs, update the boot.scr file to use the patched kernel and change the `root=ld0a` boot arg to `root=wd0a`.

A pre-built, wd0-modified kernel can be downloaded from here:

Last edited by danboid; 15th February 2016 at 12:40 AM. Reason: Fully revised, working SATA install guide
Reply With Quote