tomclegg.net |
Building a FreeBSD router on a 256M disk Posted June 3, 2003 Assemble the computer. Put the solid state hard disk on the primary ATA controller, and a bootable CD-ROM drive on the second controller. BIOS setup: date/time = current UTC date/time Boot with FreeBSD [4.7] CD #1 in the CD-ROM drive. FreeBSD installer:
Press Delete or whatever to re-enter BIOS setup. Change boot device to "drive C" or "primary ATA" or whatever the disk is. Save & exit. FreeBSD will boot with no network configuration ("Amnesiac"). Log in as root. Set hostname and override some inappropriate defaults: cat <<EOF >>/etc/rc.conf hostname= Add network configuration: echo nameserver Yank the power cord. Wait. Restore power. The machine should power up, and FreeBSD should boot automatically after fixing the filesystem. Log in as root. Type " Install some packages (if desired): mount /cdrom cd /cdrom/packages/All pkg_add bash-2.05b.004.tgz && chsh -s /usr/local/bin/bash pkg_add psmisc-17.tgz pkg_add rsync-2.5.5_1.tgz Type "df -m" again. I have 109MB available. Install daemontools and ucspi-tcp: cd /tmp fetch http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz tar xzf ucspi-tcp-0.88.tar.gz (cd ucspi-tcp-0.88; make setup check) rm -r /tmp/ucspi-tcp-0.88* cd /tmp fetch http://cr.yp.to/daemontools/daemontools-0.76.tar.gz mkdir -p /package cd /package tar xzf /tmp/daemontools-0.76.tar.gz (cd admin/daemontools-0.76 && package/install && rm -r compile) rm /tmp/daemontools-0.76.tar.gz Do a quick reboot: type " Type " Power up again, and log in as root. Install djbdns: cd /tmp fetch http://cr.yp.to/djbdns/djbdns-1.05.tar.gz tar xzf djbdns-1.05.tar.gz (cd djbdns-1.05 && make setup check) rm -r /tmp/djbdns-* Set up a DNS cache.
cd pw useradd Gdnscache -s /usr/bin/true -d /nonexistent -u 901 pw useradd Gdnslog -s /usr/bin/true -d /nonexistent -u 902 mkdir -p /etc/service dnscache-conf Gdnscache Gdnslog /etc/service/dnscache Install qmail: pw groupadd qmail -g 82 pw groupadd nofiles -g 81 pw useradd alias -g nofiles -u 81 -s /nonexistent -d /var/qmail pw useradd qmaill -g nofiles -u 83 -s /nonexistent -d /var/qmail pw useradd qmaild -g nofiles -u 82 -s /nonexistent -d /var/qmail pw useradd qmailp -g nofiles -u 84 -s /nonexistent -d /var/qmail pw useradd qmailq -g qmail -u 85 -s /nonexistent -d /var/qmail pw useradd qmailr -g qmail -u 86 -s /nonexistent -d /var/qmail pw useradd qmails -g qmail -u 87 -s /nonexistent -d /var/qmail cd /tmp fetch http://cr.yp.to/software/qmail-1.03.tar.gz tar xzf qmail-1.03.tar.gz (cd qmail-1.03 && make setup check) rm -r /tmp/qmail-1.03* Set up QMQP service on some other machine(s), so that connections are accepted from this machine. (Details not included here.) Configure qmail to deliver mail via QMQP instead of trying to queue it on this machine.
cd /var/qmail/control echo Configure a new kernel. (Do this on a different machine with more disk space to spare!) Here are the significant changes I made to GENERIC to come up with SAUNA: # cd /usr/src/sys/i386/conf # diff GENERIC SAUNA Build the new kernel. Skip the buildworld step if you haven't updated anything in /usr/src since your last buildworld. cd /usr/src make -j4 buildworld make buildkernel KERNCONF=SAUNA mkdir -p /tmp/SAUNA/modules mkdir -p /tmp/SAUNA/usr/{bin,sbin} mkdir -p /tmp/SAUNA/usr/share/man/{man4,man8} make installkernel KERNCONF=SAUNA DESTDIR=/tmp/SAUNA tar -C /tmp/SAUNA -cjf /tmp/SAUNA.tbz kernel modules usr Copy cd /tmp fetch http://tomclegg.net/software/SAUNA.tbz md5 SAUNA.tbz Set up ramdisks for supervised services, /var/run, /var/spool/lock, and /dev: mkdir /mfs mkdir /dev.boot cp /dev/MAKEDEV /dev.boot/ cd /dev.boot && sh MAKEDEV all cat <<EOF >>/etc/rc.early /sbin/fsck -y / /sbin/umount -f /mfs /sbin/mount_mfs -s 1600 -T qp120at dummy /mfs /bin/mkdir -p /mfs/run /mfs/spool/lock /mfs/service /usr/bin/tar -C /etc/service -cpf - . | /usr/bin/tar -C /mfs/service -xf - /sbin/umount -f /dev /sbin/mount_mfs -s 1600 -i 1024 -T qp120at dummy /dev /usr/bin/tar -C /dev.boot -cpf - . | /usr/bin/tar -C /dev -xf - EOF rm -r /var/run ln -s /mfs/run /var/ rm -r /var/spool/lock ln -s /mfs/spool/lock /var/spool/ ln -sf /mfs/service/dnscache /service/ echo /mfs/service/dnscache/root >/etc/service/dnscache/env/ROOT reboot " df Now, change " Change mount -u -o rw / cat <<EOF >/etc/mail/mailer.conf sendmail /var/qmail/bin/sendmail send-mail /var/qmail/bin/sendmail mailq /usr/bin/true newaliases /var/qmail/bin/qmail-newu hoststat /usr/bin/true purgestat /usr/bin/true EOF Set up a supervised mount -u -o rw / cd /etc/service mkdir natd cd natd cat <<EOF >run #!/bin/sh killall -9 natd exec fghack natd -f natd.conf EOF cat <<EOF >natd.conf interface fxp0 dynamic yes EOF chmod +x run ln -s /mfs/service/natd /service/ reboot Set up a name server on 127.0.0.1 for local dns data: pw useradd Gtinydns -u 903 -d /nonexistent -s /usr/bin/true tinydns-conf Gtinydns Gdnslog /mfs/service/tinydns 127.0.0.1 cd /mfs/service/tinydns/log cp -i -p run run.orig (echo '#!/bin/sh'; echo 'exec cat >/dev/null') >run cp -r -p /mfs/service/tinydns /etc/service/tinydns ln -s /mfs/service/tinydns /service/ Remove some of the larger unnecessary programs: rm /usr/libexec/sendmail/sendmail rm /usr/libexec/named-xfer rm /usr/sbin/named rm /usr/sbin/ntpd Things left to do:
|