File:  [NetBSD Developer Wiki] / wikisrc / tutorials / how_to_install_a_server_with_a_root_lfs_partition.mdwn
Revision 1.2: download - view: text, annotated - select for diffs
Sun Feb 5 07:14:36 2012 UTC (8 years, 9 months ago) by schmonz
Branches: MAIN
CVS tags: HEAD
dos2unix

    1: In this article I will explain, step by step, how to install a NetBSD server with a root LFS partition. 
    2: 
    3: **Contents**
    4: 
    5: [[!toc]]
    6: 
    7: #Foreword
    8: 
    9: Since LFS is considered experimental, it is highly advised to test this setup on a testbed / Virtual Machine. Use at your own risk.
   10: 
   11: In this setup, the server will solely run under LFS without any FFS partitions.
   12: 
   13: There are a lot of ways to accomplish this task. This is how I do it.
   14: #What is LFS
   15: 
   16: LFS is an implementation of a [log-structured file system](http://en.wikipedia.org/wiki/Log-structured_File_System_%28BSD%29).
   17: 
   18: For example [Sun's ZFS](http://en.wikipedia.org/wiki/ZFS) is a log-structured file system.
   19: #What are the advantages
   20: 
   21: LFS can recover faster from a crash, because it does not need to fsck the whole disk. It is faster than FFS.
   22: #What are the disadvantages
   23: 
   24:     It has never worked reliably.
   25:     It is limited to 2 Terabytes.
   26:     It does not perform very well at constant high disk activity like ftp uploads/downloads.
   27:     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. 
   28: 	
   29: #How do we aproach
   30: 
   31: 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.
   32: Requirements
   33: 
   34: Physical access to the server.
   35: 
   36: We need a NetBSD [liveCD](http://www.jibbed.org/) 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>.
   37: 
   38: 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.
   39: 
   40: 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.
   41: 
   42: A tutorial on how to build current can be found here: [[How to build NetBSD-current]].
   43: 
   44: The sets have to be accessible from the liveCD in some way. For example via http, ftp or scp. 
   45: 
   46: #Booting from the liveCD
   47: 
   48: Please boot into the liveCD on the server you want to install.
   49: 
   50: Gain root privileges (su -).
   51: #fdisk
   52: 
   53: Use fdisk to create an active NetBSD (ID 169) partition.
   54: 
   55:     # fdisk -iu wd0
   56: 
   57: #disklabel
   58: 
   59: Use disklabel to prepare your disk. This part of the tutorial is with purpose not very detailed. You should get comfortable with disklabel beforehand.
   60: 
   61: Enter
   62: 
   63:     # disklabel -i -I wd0
   64: 
   65: on the command line to enter the interactive disklabel menu. I am assuming you are using wd0. Otherwise substitute with your drive (sd0, ld0...)
   66: 
   67: We will create one big "a" partition in this example. Feel free to try another setup in your second try.
   68: 
   69: 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.
   70: 
   71: Use 4.4LFS as your file system.
   72: 
   73: Partition b is used as swap. Start from the end of partition a until the end ($).
   74: 
   75: Partition c and d are the disks itself and should be of type **unused** starting from 0 to the end.
   76: 
   77: Remove all other partitions (e-p).
   78: 
   79: When you are finished your label should look like this:
   80: <pre><code>
   81: #        size    offset     fstype [fsize bsize cpg/sgs]
   82:  a:  73400320        63     4.4LFS      0     0     0  # (Cyl.      0*-  72817*)
   83:  b:   2097152  73400383       swap                     # (Cyl.  72817*-  77504*)
   84:  c:  78124937        63     unused      0     0        # (Cyl.      0*-  77504*)
   85:  d:  78125000         0     unused      0     0        # (Cyl.      0 -  77504*)
   86: </code></pre>
   87: Label the disk (N), Write changes to disk (W), and quit (Q).
   88: #newfs_lfs
   89: 
   90: You can now create the LFS filesystem on the disk you just labeled.
   91: 
   92:     # newfs_lfs wd0a
   93: 
   94: 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.
   95: #mounting
   96: 
   97: The rest is trivial. We mount the filesystem and extract our sets.
   98: 
   99:     # mkdir /tmp/targetroot
  100:     # mount /dev/wd0a /tmp/targetroot
  101: 
  102: Create another directory to store the sets in.
  103: 
  104:     # mkdir /tmp/sets 
  105: 
  106: Change in that directory
  107: 
  108:     # cd /tmp/sets
  109: 
  110: 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.
  111: 
  112:     # ftp 192.168.0.200
  113: 
  114:     ...
  115: #extracting the sets
  116: 
  117: extract your sets using option -p (important).
  118: 
  119:     # cd /tmp/sets
  120:     # tar xvzpf base.tgz -C /tmp/targetroot
  121: 
  122: repeat with all your sets, but extract only one GENERIC kernel named kern-GENERIC.tgz
  123: #configure the new system
  124: 
  125: change into /tmp/targetroot and do a base configuration. Edit etc/fstab
  126: 
  127:     /dev/wd0a       /               lfs     rw      1 1
  128:     /dev/wd0b       none            swap    sw      0 0
  129:     ptyfs           /dev/pts        ptyfs   rw      0 0
  130:     tmpfs           /tmp            tmpfs   rw
  131: 
  132: ptyfs and tmpfs are optional, but recommended.
  133: 
  134: Edit etc/rc.conf
  135: 
  136:     rc_configured=yes
  137: 
  138: #bootstrap
  139: 
  140: Copy boot to the targetroot.
  141: 
  142:     # cp /tmp/targetroot/usr/mdec/boot /tmp/targetroot 
  143: 
  144: And bootstrap
  145: 
  146:     # /usr/sbin/installboot -v -m i386 -o timeout=5,console=pc /dev/rwd0a /tmp/targetroot/usr/mdec/bootxx_lfsv2
  147: 
  148: #creating devices
  149: 
  150: Don't forget to create all devices.
  151: 
  152:     # cd /tmp/targetroot/dev
  153:     # ./MAKEDEV all
  154: 
  155: this may take a while.
  156: #reboot
  157: 
  158: That's it. Sync and reboot.
  159: 
  160:     # sync
  161:     # sync
  162:     # sync
  163:     # reboot
  164: 
  165: If everything went well, your system should boot. Once you have logged in, you can configure your system and do all the fine tuning.
  166: #Disk capacity
  167: 
  168: You should not fill up your LFS partition over 75%. This could damage the file system (at the moment).
  169: #Remote installation
  170: 
  171: 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. 

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb