OpenBSD diskless install

Here is a recipe to boot OpenBSD (4.1) from an OpenBSD (4.1) box. This can be used to boot any machine that has no disks and supports pxeboot. The advantage is you save a little money on not buying hard-disks, but on the other hand, the "server" that serves everything must be always on.

This could be a good solution in a clustered environment.

Well, if you decide you would like to play, follow these instructions.

Install an OpenBSD system. This will be your boot-server. Just select generic settings that you prefer.

Here is the IP-scheme I have used:

server: 192.168.1.254
client: 192.168.1.253
netmask: 255.255.255.0 (or /24)
broadcast: 192.168.1.255
gateway: 192.168.1.1

When the install is done, modify these files on the boot server to look like this.

First, configure an IP-address.

# cat /etc/hostname.pcn0
inet 192.168.1.254 255.255.255.0 192.168.1.255
# cat /etc/mygate
192.168.1.1
# cat /etc/resolv.conf
lookup file bind
nameserver 192.168.1.1

Then make sure some daemons are started at boot time on the boot server.

# cat /etc/rc.conf.local
# For the PXEBOOT and the OS, DHCP is used.
dhcpd_flags=""
# After PXEBOOT, the kernel uses rarp to discover its IP-address.
rarpd_flags="-a"
# Then bootparamd to figure out options for mounting things.
bootparamd_flags=""
portmap="YES"
# And NFS to serve directories like /root, /usr and swap.
nfs_server="YES"
nfsd_flags="-tun 4"

For rarp, add an entry like this to represent the client "diskless". The first column, the mac-address will need to be changed to the mac-address of the client you would like to boot. You can find out a MAC-address of your client by typing ifconfig on it, but you then need some sort of an os. Try a livecd from whatever distribution you like.

# cat /etc/ethers
00:0c:29:ad:c8:32 diskless

Also add this machine to the hosts file. I gave my client the 192.168.1.253 IP-address, change it to anything you like. This IP-address is the address the kernel will boot with.

# cat /etc/hosts
192.168.1.253 diskless

Tell the clients kernel where to get the root directory and swap from.

# cat /etc/bootparams
diskless root=192.168.1.254:/export/diskless/root swap=192.168.1.254:/export/diskless/swap

Configure DHCP. This is used by PXEBOOT, and by the running Operating System, but not by the kernels IP address. It is logical and wise to use the same IP address here and in /etc/ethers, /etc/hosts, but it's not required.

# cat /etc/dhcpd.conf
shared-network LOCAL-NET {
        option  domain-name "my.domain";
        option  domain-name-servers 192.168.1.1;

        subnet 192.168.1.0 netmask 255.255.255.0 {
                option routers 192.168.1.1;
                filename "pxeboot";
        }
}

host diskless {
        hardware ethernet 00:0c:29:ad:c8:32;
        fixed-address 192.168.1.253;
}

Make sure tftp is started in inetd.conf. (I enables only the default, not the ipv6 version.)

# cat /etc/inetd.conf | grep tftp
tftp            dgram   udp     wait    root    /usr/libexec/tftpd      tftpd -s
/tftpboot
#tftp           dgram   udp6    wait    root    /usr/libexec/tftpd      tftpd -s
/tftpboot

The /tftpboot directory must contain the pxeboot code and an openbsd kernel called bsd. (By the way, replacing that bsd by bsd.rd makes this an install-server!) You can get these file form any openbsd mirror in the pub/OpenBSD/4.1/i386/ directory.

# ls /tftpboot
bsd
pxeboot

Now export a few filesystems in /etc/exports.

# cat /etc/exports
/export/diskless -maproot=root -alldirs diskless

And create the 128 megabytes swap space like this:

# mkdir -p /export/diskless/root
# dd if=/dev/zero bs=1m count=128 of=/export/diskless/swap

Now you will have to unpack some sets (the minimal base41.tgz and etc41.tgz) into the diskless root and create a few devices. The sets can be downloaded from one of the openbsd mirrors. The devices, like /dev/console also need to be created.

Be aware about the -p option in the tar extract, it preservers permissions and that is required.

# cd /export/diskless/root
# tar -xvzpf base41.tgz
# tar -xvzpf etc41.tgz
# cd dev
# ./MAKEDEV all
# cd ../

Also edit the /export/diskless/root/etc/fstab.

192.168.1.254:/export/diskless/root     /       nfs     rw      0       0
192.168.1.254:/export/diskless/swap     none    swap    sw,nfsmntpt=/swap

At the end of this all, reboot the server to start everything.

# reboot

When the server is booted, boot up the client and see the magic! Here is an overview of what happens:

  1. The machine boots and runs the built in PXEBOOT.
  2. PXEBOOT will do a DHCP request.
  3. The DHCP server will tell the client it IP-address and what to boot (pxeboot).
  4. The /ftpboot/pxeboot is downloaded using tftp.
  5. The downloaded pxeboot is executed. This downloads the kernel (bsd) and start that kernel.
  6. The bsd kernel does a rarp (/etc/ethers, /etc/hosts, /etc/bootparams) request to find out who he is, and where to get the swap and root filesystem.
  7. The kernel mounts swap and root and starts /sbin/init.
  8. From here on init takes over and normal OpenBSD boot will proceed.

Now check if it boots, there is still a few things to do. Lets set a hostname in /export/diskless/root/myname and set the password.

# echo "diskless" > /export/diskless/root/etc/myname
# chroot /export/diskless/root
# passwd root
Changing local password for root.
New password:
Retype new password:
# exit

Now you are done! have fun with it!

I have installed this setup in a virtual host on my intel mac, you can download a packed-up version of the images and the configuration to peek around. The root password installed on these images is "OpenBSD"
The Vmware Fusion boot-server. (229 Mb packed)
The Vmware Fusion client. (27 Kb packed)