In this article I will explain, step by step, how to install a NetBSD server with a root LFS partition.

Contents

  1. Foreword
  2. What is LFS
  3. What are the advantages
  4. What are the disadvantages
  5. How do we aproach
  6. Booting from the liveCD
  7. fdisk
  8. disklabel
  9. newfs_lfs
  10. mounting
  11. extracting the sets
  12. configure the new system
  13. bootstrap
  14. creating devices
  15. reboot
  16. Disk capacity
  17. Remote installation

Foreword

Since LFS is considered experimental, it is highly advised to test this setup on a testbed / Virtual Machine. Use at your own risk.

In this setup, the server will solely run under LFS without any FFS partitions.

There are a lot of ways to accomplish this task. This is how I do it.

What is LFS

LFS is an implementation of a log-structured file system.

For example Sun's ZFS is a log-structured file system.

What are the advantages

LFS can recover faster from a crash, because it does not need to fsck the whole disk. It is faster than FFS.

What are the disadvantages

It has never worked reliably.
It is limited to 2 Terabytes.
It does not perform very well at constant high disk activity like ftp uploads/downloads.
It can't handle situations where the disc is almost full, i.e. it usually crashes requiring a newfs, though most data can be recovered manually. 

How do we aproach

We need to install a NetBSD system from scratch without sysinst, since sysinst is lacking LFS support at the moment. This may change in the future. Requirements

Physical access to the server.

We need a NetBSD liveCD to access the hard disks. Only liveCDs with LFS support compiled in will work. Therefore please download the Jibbed LiveCD from http://www.jibbed.org.

We will also need the NetBSD sets (base.tgz, comp.tgz, etc.tgz, man.tgz, misc.tgz, text.tgz ...). It is recommended to download all sets.

You can either download the latest sets from the NetBSD autobuild cluster (ftp://ftp.netbsd.org/pub/NetBSD-daily/HEAD/) or you can build your own release and use your own sets. I recommend to use the latest NetBSD sources.

A tutorial on how to build current can be found here: ?How to build NetBSD-current.

The sets have to be accessible from the liveCD in some way. For example via http, ftp or scp.

Booting from the liveCD

Please boot into the liveCD on the server you want to install.

Gain root privileges (su -).

fdisk

Use fdisk to create an active NetBSD (ID 169) partition.

# fdisk -iu wd0

disklabel

Use disklabel to prepare your disk. This part of the tutorial is with purpose not very detailed. You should get comfortable with disklabel beforehand.

Enter

# disklabel -i -I wd0

on the command line to enter the interactive disklabel menu. I am assuming you are using wd0. Otherwise substitute with your drive (sd0, ld0...)

We will create one big "a" partition in this example. Feel free to try another setup in your second try.

In disklabel create one big partition "a" spanning the whole disk starting from sector 63 (63s) until the end minus the space you want to give to the swap partition.

Use 4.4LFS as your file system.

Partition b is used as swap. Start from the end of partition a until the end ($).

Partition c and d are the disks itself and should be of type unused starting from 0 to the end.

Remove all other partitions (e-p).

When you are finished your label should look like this:


#        size    offset     fstype [fsize bsize cpg/sgs]
 a:  73400320        63     4.4LFS      0     0     0  # (Cyl.      0*-  72817*)
 b:   2097152  73400383       swap                     # (Cyl.  72817*-  77504*)
 c:  78124937        63     unused      0     0        # (Cyl.      0*-  77504*)
 d:  78125000         0     unused      0     0        # (Cyl.      0 -  77504*)

Label the disk (N), Write changes to disk (W), and quit (Q).

newfs_lfs

You can now create the LFS filesystem on the disk you just labeled.

# newfs_lfs wd0a

There are more options like -A and different segment and frag sizes. But we will stick to the default 1M segment size, since other values may get LFS unstable.

mounting

The rest is trivial. We mount the filesystem and extract our sets.

# mkdir /tmp/targetroot
# mount /dev/wd0a /tmp/targetroot

Create another directory to store the sets in.

# mkdir /tmp/sets 

Change in that directory

# cd /tmp/sets

And download your sets, for example via ftp. This are the sets you have prepared upfront by either compiling a release or downloading them from the autobuild cluster.

# ftp 192.168.0.200

...

extracting the sets

extract your sets using option -p (important).

# cd /tmp/sets
# tar xvzpf base.tgz -C /tmp/targetroot

repeat with all your sets, but extract only one GENERIC kernel named kern-GENERIC.tgz

configure the new system

change into /tmp/targetroot and do a base configuration. Edit etc/fstab

/dev/wd0a       /               lfs     rw      1 1
/dev/wd0b       none            swap    sw      0 0
ptyfs           /dev/pts        ptyfs   rw      0 0
tmpfs           /tmp            tmpfs   rw

ptyfs and tmpfs are optional, but recommended.

Edit etc/rc.conf

rc_configured=yes

bootstrap

Copy boot to the targetroot.

# cp /tmp/targetroot/usr/mdec/boot /tmp/targetroot 

And bootstrap

# /usr/sbin/installboot -v -m i386 -o timeout=5,console=pc /dev/rwd0a /tmp/targetroot/usr/mdec/bootxx_lfsv2

creating devices

Don't forget to create all devices.

# cd /tmp/targetroot/dev
# ./MAKEDEV all

this may take a while.

reboot

That's it. Sync and reboot.

# sync
# sync
# sync
# reboot

If everything went well, your system should boot. Once you have logged in, you can configure your system and do all the fine tuning.

Disk capacity

You should not fill up your LFS partition over 75%. This could damage the file system (at the moment).

Remote installation

If you want to install an LFS root file system on your server in your data center remotely, console access is beneficial, but not necessary. The minimum requirement is a rescue console. This is mostly a linux ramdisk. One way is to build a custom boot floppy including LFS and newfs_lfs. Because newfs_lfs does not fit on the disk, you have to exclude unnecessary tools. Then write a small shell script that is executed when you boot the floppy, summing up all steps in the tutorial including adding a user account and setting up ifconfig, resolv.conf, default gateway, to be able to log in afterwards. Make a backup of the first 5 MB you are going to overwrite with dd. Now just dd the floppy image to server harddisk and reboot. Good luck.