NetBSD boot straps from GNU/Linux (FAIL)

Introduction

Two ways are discussed here

Requirements

English please, and no colors

export LANG=C
export LC_MESSAGES=C
alias ll='ls -alkF'
echo 'syn off' >> ~/.vimrc
apt update
apt install -y man-db manpages mlocate

Freaking Ubuntu — it mounts the swap space if it finds one

swapon -s
swapoff -a

And proceed

source=http://ftp.fr.netbsd.org/pub/NetBSD/NetBSD-8.0/amd64/
#source=http://ftp.fr.netbsd.org/pub/NetBSD-daily/netbsd-8/201903100010Z/amd64

wget $source/binary/kernel/netbsd-GENERIC.gz
wget $source/binary/kernel/netbsd-INSTALL.gz
zcat netbsd-INSTALL.gz > netbsd

wget $source/binary/sets/base.tgz
#wget $source/binary/sets/base.tar.xz
mkdir base/
tar xzphf base.tgz -C base/
#tar xJphf base.tar.xz -C base/
ls -lF base/usr/mdec/mbr
ls -lF base/usr/mdec/bootxx_ext2fs
ls -lF base/usr/mdec/boot

Watch for possible errors

apt install -y binutils
strings base/usr/mdec/mbr
strings base/usr/mdec/bootxx_ext2fs
strings base/usr/mdec/boot

Start clean

mount | grep sda
#umount /mnt/dev/
#umount /mnt/
#dd if=/dev/zero of=/dev/sda bs=1M count=1

THE NETBSD MBR WAY

THIS WILL ERASE THE PARTITION TABLE AS WELL (512 bytes)

dd if=base/usr/mdec/mbr | hexdump -vC
dd if=base/usr/mdec/mbr of=/dev/sda
#dd if=base/usr/mdec/mbr of=/dev/sda bs=1 count=440

DOS Partitions

Not sure we really need to force sector 63

#fdisk -c=dos -u /dev/sda
#o
#n p 1 63 +25G
#t a9
#a

cfdisk /dev/sda

25G a9 BOOTABLE

TODO try with Linux instead of a9 and lilo (netbsd mbr wants a9)

build the filesystem without -r 0 as largefiles is available now

mkfs.ext2 -O^dir_index /dev/sda1
tune2fs -l /dev/sda1 | grep features:

gives

ext_attr resize_inode dir_index filetype sparse_super large_file

Secondary boot strap & kernel

mount /dev/sda1 /mnt
cp base/usr/mdec/boot /mnt/
cp netbsd-GENERIC.gz netbsd-INSTALL.gz netbsd /mnt/
umount /mnt

Primary boot strap

everything is almost zeroes so far in sectors 0,1,2-11

dd if=/dev/sda1 count=13 skip=0 | hexdump -C | less

backup the first sectors of the partition

dd if=/dev/sda1 of=sda1.13sec.bkp count=13
ls -lF sda1.13sec.bkp # 6656 bytes

WRITE

dd if=base/usr/mdec/bootxx_ext2fs of=/dev/sda1

#DO NOT
#fsck.ext2 -y /dev/sda1

#ext2fs_open2: Bad magic number in super-block
#fsck.ext2: Superblock invalid, trying backup blocks...

check and compare against the 13 blocks long pbr+bootxx

dd if=/dev/sda1 count=1 skip=0 | hexdump -vC
dd if=/dev/sda1 count=1 skip=1 | hexdump -vC
dd if=/dev/sda1 count=11 skip=2 | hexdump -vC | less

dd if=base/usr/mdec/bootxx_ext2fs count=1 skip=0 | hexdump -vC
dd if=base/usr/mdec/bootxx_ext2fs count=1 skip=1 | hexdump -vC
dd if=base/usr/mdec/bootxx_ext2fs count=11 skip=2 | hexdump -vC | less

FOUND PROBLEM. that part has been wiped by fsck.ext2

#hexdump -vC base/usr/mdec/bootxx_ext2fs | less
#dd if=/dev/sda1 count=13 | hexdump -vC | less

mount /dev/sda1 /mnt
diff base/usr/mdec/boot /mnt/boot
diff netbsd-GENERIC.gz /mnt/netbsd-GENERIC.gz
diff netbsd.gz /mnt/netbsd.gz
diff MD5 /mnt/MD5
diff netbsd /mnt/netbsd
umount /mnt

FAIL – Got this (no boot prompt)

NetBSD MBR boot
Error no magic

==> this string is from base/usr/mdec/bootxx_ext2fs meaning that we cannot reach the secondary bootstrap so far.

THE LILO WAY

apt install -y lilo

mount /dev/sda1 /mnt
ls -lF /mnt/
mkdir /mnt/etc

LILO’s required /boot/ folder conflicts with the NetBSD /boot secondary boot strap file. This is why we define map and backup.

vi /mnt/etc/lilo.conf

lba32
boot = /dev/sda
root = /dev/sda1
prompt  
timeout = 30
vga = normal
compact
map=/bootalt/map
backup=/bootalt

other=/dev/sda1
    label=netbsd

mkdir /mnt/dev/
mount -o bind /dev /mnt/dev
mkdir /mnt/bootalt/

lilo -V # 24.2
lilo -r /mnt
#lilo -P ignore -r /mnt

FAIL – Got the LILO boot prompt (boot:). It then says

Loading netbsd
Error no magic

READY TO GO

cd ~/
sync
mount | grep sda
umount /mnt/dev
umount /mnt

and finally SWITCH TO NORMAL MODE

Troubleshooting

NetBSD MBR

NetBSD MBR boot
Error no slice

==> needs a9/netbsd DOS partition, not 83/linux

LILO

When running lilo

Fatal: creat /boot/boot.0800: Not a directory

==> cannot use both netbsd boot file and required boot/ folder.

Fatal: raid_setup: stat("/dev/sda")

==> /mnt/dev not binded

Fatal: First sector of /dev/sda1 doesn't have a valid boot signature
strings base/usr/mdec/mbr

==> bootxx not applied

Resources

NetBSD MBR

LILO


Nethence | Pub | Lab | Pbraun | SNE Russia | xhtml