DaemonForums  

Go Back   DaemonForums > NetBSD > NetBSD Installation and Upgrading

NetBSD Installation and Upgrading Have trouble getting NetBSD on your toaster?

Reply
 
Thread Tools Display Modes
  #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 http://dl.linux-sunxi.org/nightly/u-...inline-latest/.
Decompress the image via gunzip(1):

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

Code:
# 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:

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

Code:
# 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:

Code:
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):

Code:
# 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:

Code:
# 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.

Code:
# disklabel -i -I wd0
partition>a
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:

Code:
partition>b
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:

Code:
# 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:

Code:
# 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:

https://www.netbsd.org/~tnn/bpi-wd0a/netbsd.ub

Last edited by danboid; 15th February 2016 at 12:40 AM. Reason: Fully revised, working SATA install guide
Reply With Quote
  #2   (View Single Post)  
Old 13th February 2016
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 1,027
Default

[Historical note for future readers: Much of the discussion that follows relates to a preliminary version of the Original Post, which asked about problems booting from a SATA drive.]


Hello danboid, and welcome to daemonforums!

I've never worked with banana Pi's and such, but from your description I'm wondering if a couple of preliminary steps have been taken care of. To explain this, first a quick re-cap of the boot process:

1) BIOS reads MBR boot code, and executes it, and it has to decide to boot off the NetBSD partition.

2) BIOS boot code passes control to the primary boot loader in the NetBSD partition.

3) Primary boot loader finds the secondary boot loader, /boot, which then loads the kernel and away you go.

It seems to me your rsync operation should have copied over the secondary boot loader, so that should be there.

BUT: did you install the primary boot loader? If not this can be done using the installboot program. Check the man page for details, but you can run this from the system booted off your SD card, and tell it to put the primary bootloader on the SCSI disk partition. A typical run might look like this

# installboot -v /dev/rwd0a /usr/mdec/bootxx_ffsv2

but do not copy this blindly, you want to make sure you put the loader at the right target location (which in the example is /dev/rwd0a -- again, please consult the man page carefully).

As for the first step, is there anything in your MBR (I assume you use MBR) that will try to boot the NetBSD partition?

Last edited by IdOp; 15th February 2016 at 05:36 PM.
Reply With Quote
  #3   (View Single Post)  
Old 13th February 2016
danboid danboid is offline
Port Guard
 
Join Date: Feb 2016
Posts: 12
Default

Hi IdOp

The BPi doesn't have a BIOS and installboot is unlikely to be of any use to me because the BPi, like many SBC ARM devices, uses the u-boot bootloader.

u-boot is installed to the MBR of my SD card and it successfully boots the rootfs from the SD card but not the HD.

Thanks for your suggestions
Reply With Quote
  #4   (View Single Post)  
Old 13th February 2016
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 1,027
Default

Thanks for the further information. As you can see I wasn't kidding about lack of familiarity with BPi.

It seems to me then there are two issues. The first is getting u-boot to attempt to boot off the HD. This I know nothing about. Second, though, if you can resolve the first issue, is that I think you'll still need to have the primary bootloader installed on the hard disk. It is placed at the start of the NetBSD partition. Without it present, I doubt you can boot NetBSD.

Hopefully you'll get some replies from others more familiar with this particular setup.

Last edited by IdOp; 13th February 2016 at 07:27 PM.
Reply With Quote
  #5   (View Single Post)  
Old 13th February 2016
danboid danboid is offline
Port Guard
 
Join Date: Feb 2016
Posts: 12
Default

Hi IdOp!

Ah right! Seems I misunderstood your first reply then. I'm only familar with Linux where we only have one bootloader (GRUB or lilo on x86, u-boot on ARM) so I presumed that installboot would be analagous to GRUB in that it would be the bootloader I'd be using to boot NetBSD on x86/x64.

However, after your latest response I now get the impression that if I was dual-booting NetBSD with Linux on x86 I would need to have both GRUB and the installboot primary bootloader installed, installboot living exclusively on the NetBSD partition whilst GRUB (or u-boot in this case) would be on the MBR.

As I said in my first post, I avoided using disklabel / fdisk to prepare my drive by using sysinst instead, although I expect that is just a script that depends upon disklabel/fdisk. However, only the partitioning aspect of it works for me on BPi so I have to quit out of it after its done that. I would've expected sysinst to run installboot on my HD too but maybe it only does that after downloading and installing the packages?

I'll have a look at the installboot manpage now and see if it makes sense. I may have to do the whole patitioning and formatting procedure manually instead of cheating by using sysinst.
Reply With Quote
  #6   (View Single Post)  
Old 13th February 2016
danboid danboid is offline
Port Guard
 
Join Date: Feb 2016
Posts: 12
Default

Aha!

This will help me for sure!

http://pbraun.nethence.com/unix/sysu...t_sysinst.html
Reply With Quote
  #7   (View Single Post)  
Old 13th February 2016
danboid danboid is offline
Port Guard
 
Join Date: Feb 2016
Posts: 12
Default

Yet another stumbling bock!

I have tried the installboot command you recommended but I get the error:

installboot: Invalid machine `evbarm' from uname()

So I need to also specify a machine type for installboot to use but none of its machine options are (32 bit) ARM platforms so I don't know which one might work the best, if any work at all?

On top of that, there is no /usr/mdec/bootxx_ffsv2 file. /usr/mdec contains a bootimx23 and a bootmini2440 file so I could try one of those instead.

I know it is possible to get NetBSD installed on the BPi HD as someone in #netbsd has done it but he was unwilling to tell me exactly how he achieved it. Someone else on the port-arm list has had success with this too. I've asked him for details yesterday but I'm still waiting for a response.
Reply With Quote
  #8   (View Single Post)  
Old 13th February 2016
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 1,027
Default

Quote:
Originally Posted by danboid View Post
I'm only familar with Linux where we only have one bootloader (GRUB or lilo on x86, u-boot on ARM) so I presumed that installboot would be analagous to GRUB in that it would be the bootloader I'd be using to boot NetBSD on x86/x64.

However, after your latest response I now get the impression that if I was dual-booting NetBSD with Linux on x86 I would need to have both GRUB and the installboot primary bootloader installed, installboot living exclusively on the NetBSD partition whilst GRUB (or u-boot in this case) would be on the MBR.
Yes, now you have it. On x86 there is that extra step, which probably has historical origins in that BSD did not originate in an environment where there would be DOS, or other, boot code on a hard disk MBR. Just to clarify, note that installboot is a system program residing in a NetBSD filesystem, and what it does is install boot code from another file into the right place on the disk (hence the name "install boot").

Quote:
As I said in my first post, I avoided using disklabel / fdisk to prepare my drive by using sysinst instead, although I expect that is just a script that depends upon disklabel/fdisk. However, only the partitioning aspect of it works for me on BPi so I have to quit out of it after its done that. I would've expected sysinst to run installboot on my HD too but maybe it only does that after downloading and installing the packages?
That seems possible (though I haven't checked the sysinst script). The reason being that it may have to unpack the install sets (what you called "packages") first so that all the system files are on the disk, then it can run installboot which is one of those files. However, installboot might already be present in the install system you booted up into too. (I am unable to verify this conveniently at the moment.)

Quote:
I'll have a look at the installboot manpage now and see if it makes sense. I may have to do the whole patitioning and formatting procedure manually instead of cheating by using sysinst.
It's always good to look at the man page. You may not have to start from scratch though, since some things were already done. But then you'll have to figure out if they were or not, and carry on at the right point.

From your following post it sounds like you are heading in the right direction on this process of discovery.
Reply With Quote
  #9   (View Single Post)  
Old 13th February 2016
danboid danboid is offline
Port Guard
 
Join Date: Feb 2016
Posts: 12
Default

I did it!

It only took a full week of my spare time!

I'm going to help the NetBSD team update the official docs but in the mean time I'll briefly cover the working process here and maybe I'll update the OP soon.

To answer our previous question, no, installboot isn't required on the BPi. What IS requred is a kernel that has been patched to boot off wd0a instead of ld0a. A suitably patched kernel for 7.0 can be downloaded here:

https://www.netbsd.org/~tnn/bpi-wd0a/netbsd.ub

There is no need to install rsync to copy the root fs to HD, pax can be used for this. After mounting the HD under /mnt you'd run:

pax -X -rwpe / /mnt

BUILDING A CUSTOM KERNEL

$ cvs -z9 -d anoncvs@anoncvs.NetBSD.org:/cvsroot co -r netbsd-7 src
$ cd src
$ vi sys/arch/evbarm/conf/BPI

# change the line:
# config netbsd root on ? type ?
# to:
# config netbsd root on wd0a type ffs

$ ./build.sh -m evbarm -a earmv7hf -j 4 -u -U tools
$ ./build.sh -m evbarm -a earmv7hf -j 4 -u -U kernel=BPI

Kernel will be located in:

src/sys/arch/evbarm/compile/obj/BPI/netbsd.ub

This kernel needs to be copied to the FAT partition of your SD card and fstab and boot.scr must be adjusted to boot off wd0a instead of ld0a.

Last edited by danboid; 14th February 2016 at 11:02 PM.
Reply With Quote
Old 13th February 2016
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 1,027
Default

Quote:
Originally Posted by danboid View Post
Did it!
Excellent! It's always great to hear success stories.

Quote:
It only took a full week of my spare time!
Not a long time at all !

Quote:
I'm going to help the NetBSD team update the official docs but in the mean time I'll briefly cover the working process here and maybe I'll update the OP soon.
That sounds great. Thank you for summarizing your results here too, I feel sure many will find it useful.
Reply With Quote
Old 14th February 2016
danboid danboid is offline
Port Guard
 
Join Date: Feb 2016
Posts: 12
Default

I have updated the OP with a complete, working NetBSD installation guide for Allwinner devices like the BPi that has been extended to cover the full process of transferring the root fs from SD card to a SATA drive in detail.

The origiinal guide that this was based on is

https://wiki.netbsd.org/ports/evbarm...nner/#index1h2

I'm going to submit a PR to hopefully get that official guide updated to cover these extra steps.

Last edited by danboid; 14th February 2016 at 11:18 PM.
Reply With Quote
Reply

Tags
banana pi, banana pi netbsd, banana pi sata hard disk ssd install

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble installing NetBSD sjakke NetBSD Installation and Upgrading 14 30th August 2011 07:28 PM
Installing KDE EverydayDiesel FreeBSD Installation and Upgrading 7 27th August 2010 04:27 AM
installing X11 hirohitosan FreeBSD Installation and Upgrading 3 25th June 2008 09:37 AM
Installing another HD Johnny2Bad FreeBSD Installation and Upgrading 4 20th May 2008 05:38 PM


All times are GMT. The time now is 11:11 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick