NetBSD on a Raspberry Pi
Install NetBSD 6 on Raspberry Pi
Although images of complete installation of NetBSD can be downloaded for the NetBSD I choose to do a fresh install.
A fresh installation won't take much time
I don't need X on this board and by doing a install you can choose what to install.
On http://nyftp.netbsd.org/pub/NetBSD-daily/ are daily builds where install images can be downloaded. The image containes only a few files to start the installer.
I downloaded the rpi_inst.img from http://nyftp.netbsd.org/pub/NetBSD-daily/HEAD/201405231330Z/evbarm/binary/gzimg/
Check the directory http://nyftp.netbsd.org/pub/NetBSD-daily for the latest version.
Write the image to a SD-card
The install image is downloaded in zipped format. On my Linux box I did the following.
dd if=rpi_inst.img of=/dev/mmcblk0
Be sure that you don't write to your harddisk, this will leave you with a broken system.
Start the installations with sysinst
Put the SD card in the Raspberry Pi and power it up. The install image gets loaded into memory. Type sysinst to start the installation.
Choose for a installation on the hard disk and choose for the full hard disk. Accept the default sectors and accept the partitioning scheme. Don't bother about the VFAT partition, the installer will take care of it.
Install from the internet
You can download all the files to your local network and install from there. However the installation won't take that much time, so you can just as well install directly from the internet.
I did choose for http to get the sets with the path http://nyftp.netbsd.org/pub/NetBSD-daily/HEAD/201405231330Z/evbarm/binary/sets/
Again choose a current directory tree.
Choose what to install
There are three options:
- full install
- install without X
- minimal install
For starters I did choose for a installation without X. This will end up in about 584Mb on your SD card.
Add a user
In the last part of the installation process, add a user that is part of the group wheel. Choose a strong password.
Protect your SD card
After the installation is done, reboot into the fresh NetBSD system.
Now we have to do some post installation configuration.
To protect the SD card we have to minimize the number of writes to it.
Edit /etc/fstab to set mount options to the root filesystem:
/dev/ld0a / ffs rw,noatime,nodevmtime 1 1
Edit /etc/rc.conf and add the following lines:
fsck_flags="-P -p -y"
as advised on Mat@Home blog.
- Put /var/log and /var/run into a ramdisk (tmpfs).
- Don't use dhcp but choose a static ip address.
- Put home on ramdisk
- Put swap on NFS
Put /var/log and /var/run into a ramdisk (tmpfs).
On NetBSD tmpfs can grow and shrink as needed.
A nice script to let /var/run and /var/log be populated can be found at Mat@Home blog.
Entries in /etc/fstab for this could be something like the following.
tmpfs /var/log tmpfs rw,-sram%10
tmpfs /var/run tmpfs rw,-sram%1
The last part (-sram%x) indicates the size we allow. This can be set both in Mb as well as in a percentage of total RAM.
home on tmpfs
Many applications use and write to files in the home directory. By putting home into tmpfs we will reduce the writing to disc.
Setup a disk based version of your $HOME
mv /home/matto /home/mattoskel
Now /home/mattoskel contains the contents of the $HOME directory, with all the dot-files and other configuration files. We will use this to populate the $HOME at boot time. When in future we want changes to our configuration files we have to edit the files in the /home/mattoskel directory on the SD card.
Edit /etc/fstab for tmpfs $HOME
tmpfs /home/matto tmpfs rw,-sram%10
On boot copy files to tmpfs in rc.local
I use a file /usr/local/bin/pop_home_tmpfs.sh for this and run that at boot time through /etc/rc.local.
cp -r ./ /home/matto/
chown -r matto:users /home/matto
This will populate our tmpfs $HOME dir so after a login we will have our environment comfortable configured. The ./ after cp -r is to make sure the dot-files are copied too.
Decide where swap will live
One option for swap is to use tmpfs, however this will reduce the amount of available memory. With NetBSD it is not very hard to mount swap over nfs. This off course is a lot slower compared to tmpfs but it will leave our RAM to our system.
Create swap file on the NFS-server
dd if=/dev/zero of=/path/to/nfs-exports/swap.<ip-number> bs=4000k count=40
This will create a swap-file of 160 Mb. The filename of the swapfile is swap.ip-number, so something like swap.192.168.1.230 - this will help to understand which swap file is used by which system.
Make sure the settings in /etc/exports on the NFS server are OK, also for /etc/hosts.allow and /etc/hosts.deny.
Setup /etc/fstab on the Raspberry Pi to mount swap over NFS
First, create a directory /swap as a mountpoint. Now we can add a line to /etc/fstab:
NFSSERVER:/path/to/nfs-exports/swap.<ip-number> none swap sw,nfsmntpt=/swap
After a reboot we should see that /swap is mounted over NFS. Also this can be seen in meminfo:
total: used: free: shared: buffers: cached:
Mem: 509812736 55328768 454483968 0 26099712 41574400
Swap: 163840000 0 163840000
MemTotal: 497864 kB
MemFree: 443832 kB
MemShared: 0 kB
Buffers: 25488 kB
Cached: 40600 kB
SwapTotal: 160000 kB
SwapFree: 160000 kB
Don't forget to harden your sshd. At minimal add the following to lines to your /etc/ssh/sshd_config:
Even better is to disable password login at all and only allow ssh key authentication.
Prepare installation of packages
pkgin install gnupg
Set the repository to ftp://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/$arch/6.1/All. The last line above (the installation of GnuPG) is just an example, choose the packages you need.
Complete system configuration
Do things like set your timezone et cetera,
ln -s /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime
See man afterboot and some other of the excellent NetBSD man pages.