| 1 | [[PageOutline(1-3,"Table of Content")]] |
| 2 | This guide will tell you how-to put FreeBSD 9.x on an (ALIX) embedded device. For FreeBSD 8.x see the archived guide for hints [[wiki:Archive/FreeBSDOnEmbeddedDevice]] |
| 3 | |
| 4 | TODO: This is NOT complete yet. |
| 5 | |
| 6 | = Initial disk configuration = |
| 7 | {{{#!sh |
| 8 | ## Hack to find memory card and have partion entries re-read |
| 9 | # - No cards: |
| 10 | # dd: /dev/da0: Device not configured |
| 11 | # - Inactive card: |
| 12 | # dd: /dev/da4: Operation not permitted |
| 13 | # - Active card: |
| 14 | # 0+0 records in |
| 15 | # 0+0 records out |
| 16 | # 0 bytes transferred in 0.000018 secs (0 bytes/sec) |
| 17 | }}} |
| 18 | build# ls /dev/da? | xargs -I %%DA%% -n 1 dd if=/dev/zero of=%%DA%% count=0 |
| 19 | build# setenv DA /dev/da0 |
| 20 | |
| 21 | Hack to __really__ have all old partition information is detroyed: |
| 22 | build# dd if=/dev/zero of=$DA bs=1m count=1 |
| 23 | |
| 24 | build# fdisk -BI $DA |
| 25 | build# echo "a: * * 4.2BSD" | bsdlabel -R -B -m i386 ${DA}s1 /dev/stdin |
| 26 | build# newfs ${DA}s1a |
| 27 | build# mount ${DA}s1a /mnt |
| 28 | |
| 29 | = Disk population = |
| 30 | |
| 31 | build# setenv RELEASE 8.2-RELEASE |
| 32 | build# mkdir -p /usr/data/$RELEASE |
| 33 | build# cd /usr/data/$RELEASE |
| 34 | |
| 35 | build# mkdir kernels base manpages |
| 36 | build# (cd base; echo 'mget *' | ftp -i ftp://ftp.nl.freebsd.org/pub/FreeBSD/releases/i386/$RELEASE/base/) |
| 37 | build# (cd kernels; echo 'mget *' | ftp -i ftp://ftp.nl.freebsd.org/pub/FreeBSD/releases/i386/$RELEASE/kernels/) |
| 38 | build# (cd manpages; echo 'mget *' | ftp -i ftp://ftp.nl.freebsd.org/pub/FreeBSD/releases/i386/$RELEASE/manpages/) |
| 39 | |
| 40 | More sophisticated approach (rsync not in base): |
| 41 | build# rsync -vaz ftp.nl.freebsd.org::FreeBSD/releases/i386/$RELEASE/kernels . |
| 42 | |
| 43 | |
| 44 | build# setenv DESTDIR /mnt |
| 45 | |
| 46 | build# (cd base; cat base.?? | tar --unlink -xpzf - -C $DESTDIR) |
| 47 | build# (cd kernels; sh install.sh generic) |
| 48 | build# (cd manpages; sh install.sh) |
| 49 | |
| 50 | Tip: Soekris 2521 requires CPU_ELAN which is not included into the kernel by default. For optimal performance compile the kernel yourself |
| 51 | |
| 52 | Activate right kernel: |
| 53 | build# rm -r /mnt/boot/kernel/ ; mv /mnt/boot/GENERIC/ /mnt/boot/kernel |
| 54 | |
| 55 | = Disk configuration = |
| 56 | |
| 57 | Need resolving power at later stage inside chroot: |
| 58 | build# cp /etc/resolv.conf /mnt/etc/ |
| 59 | build# chroot /mnt |
| 60 | |
| 61 | Important: if you FAIL to chroot and continue you will now start destroying your build system |
| 62 | |
| 63 | Need rw on first boot for ssh keys and such: |
| 64 | chroot# echo "/dev/ad0s1a / ufs rw,noatime 0 1" > /etc/fstab |
| 65 | Tip: On Soekris net4801 v1.33 Flash is secondary |
| 66 | net4801# echo "/dev/ad1s1a / ufs rw,noatime 0 1" > /etc/fstab |
| 67 | |
| 68 | Make sure to continue to check the disks on reboot, instead of waiting for user input: |
| 69 | chroot# echo "fsck_y_enable=YES" >> /etc/rc.conf |
| 70 | |
| 71 | {{{#!sh |
| 72 | chroot# cat <<EOF > /boot/loader.conf |
| 73 | console=comconsole |
| 74 | autoboot_delay=3 |
| 75 | |
| 76 | hw.ata.ata_dma=0 # Soekris boot failure |
| 77 | EOF |
| 78 | }}} |
| 79 | |
| 80 | Serial console boot only: |
| 81 | chroot# echo "-h" > /boot.config |
| 82 | |
| 83 | Enable serial console: |
| 84 | chroot# sed '/ttyu0/ s/off/on /' /etc/ttys > /etc/ttys.new && mv /etc/ttys.new /etc/ttys |
| 85 | |
| 86 | Cosmetic: disable all vidconsoles as a soekris embedded device does not have any: |
| 87 | chroot# sed '/ttyv[0-7]/ s/on /off/g' /etc/ttys > /etc/ttys.new && mv /etc/ttys.new /etc/ttys |
| 88 | |
| 89 | == Accounting & access control == |
| 90 | chroot# echo "sshd_enable=YES" >> /etc/rc.conf |
| 91 | chroot# pw usermod root -w random |
| 92 | |
| 93 | Administive user (admin for example): |
| 94 | chroot# setenv FTP_PASSIVE_MODE yes |
| 95 | chroot# pkg_add -r sudo |
| 96 | chroot# pw useradd admin -G wheel -c 'Admin User' -s /bin/csh -m -w random |
| 97 | chroot# echo '%wheel ALL=(ALL) ALL' >> /usr/local/etc/sudoers |
| 98 | |
| 99 | == Networking == |
| 100 | chroot# echo "hostname=riff.vanderzwet.net" >> /etc/rc.conf |
| 101 | |
| 102 | Package installation using 7.2 kernel and 8.0-RC2 world is core dumping, postponing for later stage |
| 103 | |
| 104 | Make any other optional changes before first boot inside chroot(8): |
| 105 | chroot# vi /etc/rc.conf |
| 106 | |
| 107 | |
| 108 | chroot# exit |
| 109 | build# umount /mnt |
| 110 | |
| 111 | = Initial boot = |
| 112 | Note: NOT READY YET: Insert card into your embedded device and get yourself a prompt, using serial of ssh login. |
| 113 | == Package install == |
| 114 | |
| 115 | === dnsmasq === |
| 116 | |
| 117 | dnsmasq used for local network dns and dhcp: |
| 118 | node# pkg_add -r dnsmasq |
| 119 | node# echo "dnsmasq_enable=YES" >> /etc/rc.conf |
| 120 | |
| 121 | {{{#!sh |
| 122 | node# cat <<EOF > /usr/local/etc/dnsmasq.conf |
| 123 | interface=sis0 |
| 124 | |
| 125 | dhcp-range=192.168.42.100,192.168.42.200 |
| 126 | |
| 127 | domain=vanderzwet.net |
| 128 | EOF |
| 129 | }}} |
| 130 | |
| 131 | === ntp === |
| 132 | node# echo "ntpd_enable=YES" >> /etc/rc.conf |
| 133 | {{{ |
| 134 | node# cat <<EOF > /etc/ntp.conf |
| 135 | server 0.nl.pool.ntp.org |
| 136 | server 1.nl.pool.ntp.org |
| 137 | server 2.nl.pool.ntp.org |
| 138 | |
| 139 | driftfile /var/db/ntp.drift |
| 140 | EOF |
| 141 | }}} |
| 142 | |
| 143 | === motd === |
| 144 | |
| 145 | node# (sed '3,$ d' /etc/motd; echo "WWW: http://rickvanderzwet.nl" ) > /etc/motd.new; mv /etc/motd.new /etc/motd |
| 146 | |
| 147 | === Flash disk protection === |
| 148 | node# echo "update_motd=NO" >> /etc/rc.conf |
| 149 | node# echo "tmpmfs=YES" >> /etc/rc.conf |
| 150 | Tip: You could make /var completely read-only, but I hate the details like package management getting lost. Flash cards these days are cheap anyways, mine lived for 1 year after extensive use. Of course with read-only this will be _much_ longer. |
| 151 | node# echo "varmfs=YES" >> /etc/rc.conf |
| 152 | Tip: Having your flash living in read-only gives you added security and increases the live-time of your (older) Flash cards |
| 153 | node# sed '/1a/ s/rw/ro/' /etc/fstab > /etc/fstab.new; mv /etc/fstab.new /etc/fstab |
| 154 | |
| 155 | === various === |
| 156 | node# pkg_add -r tinyproxy sudo vim-lite |
| 157 | |
| 158 | = Put into production = |
| 159 | node# reboot |
| 160 | |
| 161 | = Adding packages = |
| 162 | Tip: As space is limited unpacking packages can result in I/O errors due to (memory) disks which run out of space. Installing for example the package apache22 goes as follows: |
| 163 | node# mkdir /usr/local/tmp |
| 164 | node# setenv PKG_TMPDIR /usr/local/tmp |
| 165 | node# pkg_add -r -t /usr/local/tmp/instmp.XXXXXX apache22 |