NetBSD desktop Part 1: Manual NetBSD installation on GPT/UEFI


I share here a quick guide I wrote a while ago about manually installing NetBSD on UEFI firmware with a GPT partition table, initially recently tested anfd fixed by myself on bare metal. Thanks to @pin for having tested it and cooperated fixing typos and inconsistencies no sooner had I posted it on DaemonForums

create a new GPT disklabel

gpt destroy wd0
gpt create -f wd0

create partitions

gpt add -a 2m -s 65536 -t efi -l "ESP" wd0
gpt add -a 2m -s 5g -t ffs -l "netbsd-root" wd0
gpt add -a 2m -s 8g -t swap -l "netbsd-swap" wd0
gpt add -a 2m -s 5g -t ffs -l "netbsd-var" wd0
gpt add -a 2m -s 20g -t ffs -l "netbsd-usr" wd0
gpt add -a 2m -t ffs -l "netbsd-home”

format partitions

newfs_msdos -F 16 /dev/rwd0a
newfs -O 2 -V2 -f 2048 /dev/rwd0b
newfs -O 2 -V2 -f 2048 /dev/rwd0d
newfs -O 2 -V2 -f 2048 /dev/rwd0e
newfs -O 2 -V2 -f 2048 /dev/rwd0f
swapctl -a -p 1 /dev/wd0c

mount filesystems

 mount  /dev/wd0b /mnt
 cd /mnt 
 mkdir {var,usr,home}
 swapon /dev/wd0c
 mount /dev/wd0d /mnt/var
 mount /dev/wd0e /mnt/usr
 mount /dev/wd0f /mnt/home

extract binary sets

cd  /mnt

for set in KERN-GENERIC base comp etc  games man misc modules tests text xbase xcomp xetc xfont xserver; do
    > tar -xzpf /amd64/binary/sets/$set.tgz
    >  done

mv  netbsd netbsd.gen && ln -fh netbsd.gen netbsd

set up bootloader

 mount -t msdos /dev/wd0a /media
 mkdir -p  /media/EFI/boot
 cp /usr/mdec/*.efi /media/EFI/boot

 cat > /media/EFI/boot/boot.cfg << EOF
 > menu=Boot normally:rndseed /etc/entropy-file;boot hd0b:netbsd
 > menu=Boot single user:rndseed /etc/entropy-file;boot hd0b:netbsd -s
 > menu=Disable ACPI:rndseed /etc/entropy-file;boot hd0b:netbsd -2
 > menu=Disable ACPI and SMP:rndseed /etc/entropy-file;boot hd0b:netbsd -12
 > menu=Drop to boot prompt:prompt
 > default=1
 > timeout=5
 > clear=1
 > EOF	

 installboot -v /dev/rwd0b /mnt/usr/mdec/bootxx_ffsv2

create devnodes

 cd /mnt/dev
 sh MAKEDEV all

set up a chroot env

mkdir {kern,proc}
mount_kernfs  kernfs   /mnt/kern
mount_procfs  procfs   /mnt/proc
mount_tmpfs  tmpfs   /mnt/var/shm
mount_ptyfs  ptyfs   /mnt/dev/pts
chroot  /mnt su -


/dev/wd0b               /       ffs     rw               1 1
/dev/wd0c               none    swap    sw,dp            0 0
/dev/wd0d               /usr    ffs     rw               1 2
/dev/wd0e               /var    ffs     rw               1 2
/dev/wd0f               /home   ffs     rw               1 2
kernfs                  /kern   kernfs  rw
ptyfs                   /dev/pts        ptyfs   rw
procfs                  /proc   procfs  rw
/dev/cd0a               /cdrom  cd9660  ro,noauto
tmpfs                   /var/shm        tmpfs   rw,-m1777,-sram%25                                    

set root password

passwd root

set keyboard layout

echo "encoding $layout" >> /etc/wscons.conf

disable speaker beep

echo "setvar  wskbd   bell.volume     0"  >> /etc/wscons.conf
echo "setvar  wskbd   bell.pitch         0"  >> /etc/wscons.conf

set a reasonable framebuffer console speed

echo "setvar  wskbd   repeat.del1     250"  >> /etc/wscons.conf
echo "setvar  wskbd   repeat.deln      30"  >> /etc/wscons.conf

set timezone

ln -sf  /usr/share/zoneinfo/${region}/${state} /etc/localtime


if [ -r /etc/defaults/rc.conf ]; then
        . /etc/defaults/rc.conf

system-wide locale settings

echo "export LANG=\"en_US.UTF-8\"" >> /etc/profile
echo "export LC_CTYPE=\"en_US.UTF-8\"" >> /etc/profile
echo "export LC_ALL=\"\"" >> /etc/profile


domain         $hostname.$domain.$extension
nameserver     $nameserver  

configure ethernet interface

cat > /etc/ifconfig.${if} << EOF
> up
> media autoselect
> dhcp

set your IP

echo "$my_ip         $hostname  $hostname.$domain.$extension" >> /etc/hosts

add a standard user

useradd -g wheel -G users -s /bin/${shell} -c "foo's real name" -m foo 
passwd foo

enable networking (ifconfig -l lists available interfaces)

ifconfig $if up dhcp
dhcpcd $if

fetch a quarterly release pkgsrc tarball

tar -xzf pkgsrc.tar.gz -C /usr 
rm pkgsrc.tar.gz

install pkgin and update the binary package repo

cd /usr/pkgsrc/pkgtools/pkgin 
make install clean clean-depends 
echo "$(uname -m)/$(uname -r)_${quarterly_release}/All" >> /usr/pkg/etc/pkgin/repositories.conf 
pkgin -f update

exit chroot

umount /media
umount -fR /mnt




Nice :hugs:
Thx! :sunglasses: