Changes between Initial Version and Version 1 of FreeBSD11_Guide


Ignore:
Timestamp:
Dec 19, 2016, 9:53:51 AM (9 years ago)
Author:
rick
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FreeBSD11_Guide

    v1 v1  
     1= Nodefactory based on FreeBSD-10 =
     2
     3----
     4
     5== Scope ==
     6
     7We intend to implement a number of changes/improvements.
     8
     9Done:
     10- implement new package management (pkgng)
     11- cleanup packages that are no longer required: nrpe, vim, bash-static, pftop, nmap, python-Jinja2, sixxs-aiccu, openvpn
     12- implement latest version of lvrouted (auto update default route)
     13- add [https://code.google.com/p/ladvd/ net/ladvd]
     14- add inet check in snmpd.conf
     15- update scripts to use 'drill' instead of 'dig'
     16- remove the "rcvar='set_rcvar'" statement from startup scripts in /etc/rc.d/ and /usr/local/etc/rc.d
     17- based on FreeBSD-10.2-RELEASE
     18- [http://unbound.net/ unbound] replaces bind; recursive dns server on standard-node; authorative server for wleiden.net domain on two special servers in the network; [https://calomel.org/unbound_dns.html unbound tutorial]. Unbound optimizes forwarders automatically, so nameservershuffle is no longer needed. Use unbound from ports, not local_unbound.
     19- replaced thttpd by [http://httpd.apache.org/ apache-2.4]
     20- no longer soft-updates
     21- update captive portal to increase speed: use of static html landing page
     22- merged APU specifics into generic configuration (we do not use X64, MIPS or ARM)
     23- added NSD, may be used as authorative nameserver
     24- correction of dhcpd.conf for aliased interfaces (no 'shared-networks')
     25- use [wiki:Poudriere] for package building
     26
     27
     28ToDo:
     29- use ipfw instead of pf in order to make usb-lan adapter work, see ticket #206 for problem description.  Functionality:
     30{{{
     31  Requirements:
     32    direct new user to the Captive Portal page (rdr, blocking acl) on node.
     33    only allow http/https traffic to internet (gateway setup).
     34    NAT on gateways.
     35    Incoming RDR/NAT voor (webcam) services on gateways.
     36  Nice-to-have features:
     37    Bandwidth limiting (FUP).
     38    Bad traffic detection and blocking.
     39}}}
     40- add 'welcome back' page to captive portal (activated when connection interrupted)
     41- bsnmp may replace net-snmp (low priority)
     42- wl-web page redesign for local users / maintainance
     43- add ssh-guard or no password-login, only keys
     44- watchdog for critical daemons?
     45- evaluate use of nsd for wleiden.net local domain dns service
     46- correct /tools/wl-config external fetch url (wirelessleiden.nl/config/)
     47- gformat should include ssh-redirect rule in pf.hybrid.conf.local for the gateways.
     48{{{
     49# Redirect SSH on internetport 1022 to 22 because of ssh spam, block external port 22:
     50rdr on $ext_if inet proto tcp from any to $ext_if port 1022 tag SRV -> 172.17.87.1 port 22
     51}}}
     52- captive portal: allow some (specified) external IP's (such as the sponsor website or to allow browsing the WirelessLeiden website e.g. for support information online). Also the captive portal page could provide node specific information that would be maintained through a website (CMS).
     53- captive portal (enhancement): For user support it might be helpful to provide technical user-related information on the bottom of the captive portal; maybe a comment field and button to allow the user to send input to support@wirelessleiden.nl.
     54
     55Will keep
     56 - ucspi-tcp-0.88_2 for redirect captive portal
     57 - python
     58 - mtr, curl, screen, sudo
     59 - dnsmasq (for Soekris hardware and possibly dhcpd service)
     60 - pen
     61 - tinyproxy
     62
     63
     64Gradually we are implementing the various changes, starting from the present software configuration (9.0-RELEASE) on FreeBSD10.2-RELEASE with the next generation package management system (pkgng). The procedure to build this 'work-in-progress' nodefactory-host is described below.
     65
     66A [http://svn.wirelessleiden.nl/svn/node-config/genesis/nodes/TestTienThuis/wleiden.yaml test-node-configuration] is available in svn.
     67This wleiden.yaml file can be used to test the image by installing on an Alix-board with connection to the local network. We are also evaluating the new APU-board, see the [wiki:AlixAPU wiki-page].
     68
     69==  A. Setup a FreeBSD host ==
     70----
     71Warning: 1) Make sure ''/usr'' is '''at least 12 GB''' but better is '''20 GB''' in size, as building images requires quite some space. 2) Make sure you install the 32bit '''i386''' release of FreeBSD also when your system does support amd64, as cross compiling can give some nasty surprises.
     72
     73Tip: use a separate hard disk, mounted on /usr/obj to speed up the compilation process.
     74----
     75Get yourself a fresh i386 freebsd host with ports and subversion installed as follows:
     76=== A.1. Run the basic CD installer  ===
     77The procedure below has been tested with 10.2 (standard developer install - no ports -, e.g. with default partitioning will fit our needs). Installing FreeBSD is outside the scope of this document, take a look into [http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/bsdinstall.html the FreeBSD handbook Chapter 2 Installing FreeBSD] if you do not know the details.
     78
     79Please do mind that all commands below need to be executed as root, because of the many mounts and unmounts done in various phases. It maybe convenient to ''' permit ssh root login''' (''modify /etc/ssh/sshd_config'' accordingly).
     80
     81Internet connection is required.
     82
     83Set correct date/time, e.g:
     84build# ntpdate 0.nl.pool.ntp.org
     85
     86(You may also wish to add ''ntpd_enable="YES"'' to /etc/rc.conf)
     87
     88=== A.2 Install Ports ===
     89
     90Install a fresh ports collection, this takes some time!
     91
     92build# portsnap fetch extract
     93
     94
     95=== A.3 set some useful variables ===
     96Alter the shell configuration file:/root/.cshrc:
     97
     98Ensure ftp is set to passive mode, to avoid potential firewall issues:
     99build# echo 'setenv FTP_PASSIVE_MODE YES' >> /root/.cshrc
     100
     101Set a default password for the images that you will produce
     102build# echo 'setenv CFG_ROOT_PASSWORD DefaultPassword12!' >> /root/.cshrc
     103 
     104Define your nanobsd (svn) working directory:
     105NOTE: All commands at later stages will refer to this so you better get it right!
     106build# echo 'setenv R /root/nanobsd' >> /root/.cshrc
     107
     108
     109Next load your file (or login again):
     110build# source /root/.cshrc
     111
     112=== A.4. OPTIONAL, every developer has his own preferences, e.g. ===
     113build# pkg install vim-lite
     114build# pkg install sudo
     115build# pkg install screen
     116
     117Tip: screen can be a handy tool if you are working on a remote host.
     118{{{
     119With 'screen' you can open a virtual terminal, in which you can do everything like in the normal terminal. But you can detach it if you want to do other things in the main terminal and reattach it later. It even works after you quit your main terminal.
     120
     121Common screen commands:
     1221. Start a new terminal:
     123build# screen
     1242. Type CTRL+A and D to detach this new terminal
     1253. Reattach it:
     126build# screen -R
     127}}}
     128
     129=== A.5. get latest sources ===
     130build# pkg install subversion
     131
     132
     133build# svn co svn://svn0.eu.FreeBSD.org/base/releng/10.2 /usr/src
     134
     135=== A.6 set up Poudriere ===
     136Setting up of Poudriere is taken care off by the package-build.sh script see section B.2 below.
     137For details refer to separate page [wiki:Poudriere]
     138
     139== B. Build environment ==
     140
     141=== B.1 Download the environment from the Wireless Leiden svn repository ===
     142
     143build# svn checkout https://svn.wirelessleiden.nl/svn/code/hybrid/branches/releng-10/nanobsd $R
     144build# cd $R
     145
     146
     147If svn is not found: svn is in /usr/local/bin, alternatively log out and in, or use {{{rehash}}} in a {{{csh}}} shell to make it available.
     148
     149=== B.2. Compile all required packages ===
     150
     151First time use: set up Poudriere environment by running
     152
     153build# $R/tools/package-build.sh initenv
     154
     155This will take some time (on remote host use <screen>): the required packages are installed, ports are updated and the Poudriere jail is setup and loaded.
     156
     157Build all required packages:
     158
     159build# $R/tools/package-build.sh build
     160
     161This will take quite some time (on remote host use <screen>), depending on your hardware of course. Packages are created in /root/nanobsd/pkg/All:
     162{{{
     163build# ls $R/pkg/All
     164GeoIP-1.6.6.txz                 isc-dhcp43-server-4.3.3.txz     pkg-1.6.1_2.txz
     165apache24-2.4.17.txz             ladvd-1.0.4_2.txz               py27-setuptools27-17.0.txz
     166apr-1.5.2.1.5.4.txz             ldns-1.6.17_5.txz               py27-yaml-3.11.txz
     167ca_root_nss-3.20.txz            libevent2-2.0.22_1.txz          python-2.7_2,2.txz
     168curl-7.45.0.txz                 libffi-3.2.1.txz                python2-2_3.txz
     169db5-5.3.28_2.txz                libidn-1.31.txz                 python27-2.7.10_1.txz
     170dnsmasq-2.75,1.txz              lvrouted-13473.txz              screen-4.3.1_2.txz
     171expat-2.1.0_3.txz               mtr-0.86.txz                    sudo-1.8.15.txz
     172gdbm-1.11_2.txz                 net-snmp-5.7.3_11.txz           tinyproxy-1.8.3_1,1.txz
     173gettext-runtime-0.19.6.txz      nettle-2.7.1.txz                ucspi-tcp-0.88_2.txz
     174gmp-5.1.3_2.txz                 nsd-4.1.5.txz                   unbound-1.5.5.txz
     175iftop-1.0.p4.txz                pcre-8.37_4.txz                 vim-lite-7.4.900.txz
     176indexinfo-0.2.4.txz             pen-0.31.1.txz
     177iperf-2.0.5.txz                 perl5-5.20.3_8.txz
     178
     179
     180(list updated nov 6, 2015)
     181}}}
     182
     183
     184Tip: if you have installed packages before on this machine it may be a good idea to clean up all remains by running the /tools/clean-ports.sh script
     185
     186=== B.3. Set your favorite root password to be used in the image ===
     187
     188 Note: you can skip this step if you are satisfied with the default password set in step A.3 above.
     189
     190build# setenv CFG_ROOT_PASSWORD `dd if=/dev/random bs=10k count=10 | tr -cd '[a-zA-Z0-9]' | cut -c -15`
     191build# echo $CFG_ROOT_PASSWORD
     192
     193If you like a simple password, substitute the {{{ `dd if=/dev/random bs=10k count=10 | tr -cd '[a-zA-Z0-9]' | cut -c -15` }}} with your password.
     194
     195=== B.4  Build nanobsd (make sure to prepare some coffee;-) ; use screen) ===
     196
     197build# sh /usr/src/tools/tools/nanobsd/nanobsd.sh -c $R/cfg/nanobsd.wleiden
     198
     199 Note 1: Take a coffee of go for a hike, this normally takes 2 - 8 hours depending on the machine configuration. If you like to save some power use the script provided by Rick ([http://rickvanderzwet.nl/svn/personal/misc/power-saver]). This script is mainly used on a home server for building FreeBSD world and kernels. As soon it is done it can shutdown if not being used anymore. The system has Wake-On-Lan support and can thus be activated again from remote.
     200
     201 Even this little script got flags, check the output of {{{sh /usr/src/tools/tools/nanobsd/nanobsd.sh -h}}}
     202 {{{
     203-b suppress builds (both kernel and world)
     204-k suppress buildkernel
     205-w suppress buildworld
     206-c specify config file
     207...
     208 }}}
     209
     210 Tip: a '''safe alternative''' is the image-script available in $R/tools/ : {{{ build# $R/tools/image build }}}. This script checks whether a kernel and/or world are already available and skips these steps. This may prevent lengthy, unnecessary builds.
     211
     212
     213 Note 2: The geometry of the cf card is defined in the nanobsd configuration file $R/cfg/nanobsd.wleiden
     214 The 'default' values are for a Peak 1 GB card. They also work on an Alix2D3 board with a 1 GB PCEngines 'blanc' cf card and 1 or 2 GB Transcend cf cards although those geometries are different. There are issues with Soekris boards, depending on the BIOS version. The geometry of the cf-disk is as follows:
     215{{{
     216parameters extracted from in-core disklabel are: cylinders=1966 heads=16 sectors/track=63 (1008 blks/cyl)
     217Figures below won't work with BIOS for partitions not in cyl 1
     218parameters to be used for BIOS calculations are: cylinders=1966 heads=16 sectors/track=63 (1008 blks/cyl)
     219Media sector size is 512
     220Warning: BIOS sector numbering starts with sector 1
     221Information from DOS bootblock is:
     222The data for partition 1 is:
     223    sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
     224    start 63, size 820449 (400 Meg), flag 80 (active)
     225    beg: cyl 0/ head 1/ sector 1;
     226    end: cyl 406/ head 31/ sector 63
     227The data for partition 2 is:
     228    sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
     229    start 820575, size 820449 (400 Meg), flag 0
     230    beg: cyl 407/ head 1/ sector 1;
     231    end: cyl 813/ head 31/ sector 63
     232The data for partition 3 is:
     233    sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
     234    start 1641024, size 10080 (4 Meg), flag 0
     235    beg: cyl 814/ head 0/ sector 1;
     236    end: cyl 818/ head 31/ sector 63
     237The data for partition 4 is: <UNUSED>
     238}}}
     239
     240 Note 3: For PCEngines [http://pcengines.ch/pdf/apu1.pdf APU board] use:
     241{{{
     242$ sh /usr/src/tools/tools/nanobsd/nanobsd.sh -c $R/cfg/nanobsd.wleiden.apu
     243}}}
     244
     245
     246
     247== C. Fetch node configuration onto image, write to CF disk or remotely update ==
     248
     249=== C.1. Fetch node-configuration ===
     250 
     251 build# $R/tools/image config for <Nodename>
     252
     253The script is connecting to the [http://svn.wirelessleiden.nl/svn/node-config/genesis/nodes/ Wireless Leiden 'genesis' database]. First make sure that the configuration file is up to date by clicking the 'update' button on [http://wirelessleiden.nl/config/].
     254
     255You can inspect the image bij mounting as memory disk:
     256
     257build# mdconfig -a -t vnode -f /usr/obj/nanobsd.wleiden-hybrid/_.disk.full
     258build# mount /dev/md0s1a /mnt
     259build# ls /mnt
     260build# umount /mnt
     261build# mount /dev/md0s3 /mnt
     262build# ls /mnt
     263build# umount /mnt
     264build# mdconfig -d -u 0
     265
     266Editing can also be done using the image script:
     267
     268build# $R/tools/image edit
     269
     270
     271=== C.2. Write the correct image to CF (media based on SLC and not MLC flash seem to perform much better)===
     272----
     273    ''NOTE:'' '''''_.disk.full''''' is required for '''new CF cards''' as it contains two base system-partitions and one configuration partition. [[BR]]
     274              '''''_.disk.image''''' can be used to update one system-partitioin on an '''existing CF card'''
     275----
     276
     277    a. '''New image to local, fresh CF disk''': Put full image on a fresh compact flash disk using a card reader/writer attached to your buildbot PC. Minimum size of the CF disk is 1 GB.
     278    Use the script if you are using a usb connected cf-disk reader/writer:
     279   
     280    build# $R/tools/write-image.sh
     281   
     282or the command line:
     283   
     284    build# dd bs=64k if=/usr/obj/nanobsd.wleiden-hybrid/_.disk.full of=/dev/da0
     285     
     286    (assuming {{{/dev/da0}}} is your compact flash entry; this takes about 15 minutes, check progress by typing Ctrl-T; you may wish to check afterwards with fdisk whether there are three partitions on the disk. You can also mount /dev/da0s1a and /dev/da0s3 and check the configuration)
     287
     288    b. '''CF disk with existing image''': Put partial new image on slice (slice 2) of CF disk using a card reader/writer attached to the buildbot PC with the CF disk containing the existing image.
     289   
     290    build# dd bs=64k if=/usr/obj/nanobsd.wleiden-hybrid/_.disk.image of=/dev/da0s2
     291   
     292 
     293== D. Check the cf card and apply last minute changes ==
     294
     295=== D.1. Check cf card ===
     296
     297While the cf card is still in your flash card reader you can check whether the image has been written correctly. Check whether you can mount the partitions, e.g.
     298
     299build# mount /dev/da0s1a /mnt
     300build# ls /mnt
     301build# umount /mnt
     302
     303and the configuration partition:
     304
     305build# mount /dev/da0s3 /mnt
     306build# ls /mnt
     307
     308
     309If you cannot mount the partitions, take a fresh cf card and start again with writing the image.
     310
     311=== D.2 Adjust captive portal ===
     312
     313We now use a ''static'' landing page (in previous versions of the nodefactory the landing page was generated on the fly by a python script, this caused a considerable delay). You can find this page in the /usr/local/www/wlportal directory.
     314
     315(to be completed)
     316
     317
     318== F. Notes ==
     319
     320=== F.1 update buildbot ===
     321If you want to update the buildbot:
     322build# freebsd-update fetch
     323build# freebsd-update install
     324
     325=== F.2 update lvrouted port (ONLY) if necessary ===
     326
     327Warning: Skip the following steps unless you want to update the current lvrouted version (12879) and know what you are doing:
     328
     329Checkout latest version of lvrouted (i.e. beyond 13473):
     330{{{
     331build# svn checkout http://svn.wirelessleiden.nl/svn/node-config/other/lvrouted/trunk /usr/local/share/lvrouted
     332}}}
     333run the release.sh script to produce the tar 'release' file (lvrouted-.......tar.gz):
     334{{{
     335build# cd /usr/local/share/lvrouted/
     336build# tools/release.sh
     337}}}
     338
     339Upload the lvrouted-13473.tar.gz to the webfolder.wirelessleiden.nl/lvrouted/ directory and
     340
     341- update PORTVERSION in $R/ports/net/lvrouted/Makefile
     342- run {{{# make makesum -C $R/ports/net/lvrouted}}} to update hash values
     343- commit  $R/ports/net/lvrouted
     344
     345=== F.3 Existing image on node, remote update (slice 2) (network connection to machine 172.x.y.z required) ===
     346
     347    For remotely updating an existing node software configuration use the image script
     348   
     349    build# $R/tools/image deploy on <node> [and reboot]
     350   
     351    or manually:
     352   
     353    build# dd if=/usr/obj/nanobsd.wleiden-hybrid/_.disk.image bs=10k | ssh root@172.x.y.z /tools/updatep2
     354   
     355 
     356   You may adjust the block size to make the transfer more efficient (additionally ssh -C is possible) and you can use Ctrl-T to check progress.
     357