5 You must read this to know how to build embedded systems with TinyBSD.
9 TinyBSD's creation conf files are available under /usr/src/tools/tools/tinybsd/conf
10 and the script are available under /usr/src/tools/tools/tinybsd/tinybsd.
12 The system has been entirely based on the ease of image customization from
13 PicoBSD, and the compilation script based on NanoBSD's.
15 # ls /usr/src/tools/tools/tinybsd/conf
16 bridge/ default/ firewall/ minimal/ vpn/ wireless/ wrap/
18 We have these six pre configured images to build. On each directory we have 3
19 main files in there. Let's see what each of them are:
21 # ls /usr/src/tools/tools/tinybsd/conf/default
22 TINYBSD etc/ tinybsd.basefiles
24 TINYBSD: Just like PicoBSD had its kernel previously compiled, we call ours
35 #To statically compile in device wiring instead of /boot/device.hints
36 #hints "GENERIC.hints" #Default places to look for devices.
39 As you can see, it's a kernel file identical to your system's, leaving only
40 the task of enabling or disabling options, according to your needs.
42 tinybsd.basefiles: Just like PicoBSD had its crunch.conf file to define which
43 files we'd want the new system to have, in this one we'll have all files to be
44 put into our embedded system, already having all available files for running
45 the system well. Put in or take out the files you need according to your
48 # more tinybsd.basefiles
49 # contents of ${WORKDIR}/boot
53 boot/defaults/loader.conf
56 # contents of ${WORKDIR}/bin
64 And so on. In case you'd want to add the binary "setkey", sitting on
65 /usr/sbin, you'd only need to add the following line inside the /usr/sbin part
66 of the file, like this:
72 tinybsd.ports: Here you can add the applications from the FreeBSD Ports Collection
73 which you want TinyBSD ports system to install in your embedded system. You whould
74 list one application per line, mentioning its category and name, like the examples:
78 etc/: This is the directory where you can put your custom /etc configuration.
80 # ls /usr/src/tools/tools/tinybsd/tinybsd
83 tinybsd: This is the script that builds the entire system. You'll hardly
84 need to modify it at all. The idea is for it to create a temporary work
85 directory for it to create the entire system tree. Once done, it'll copy all
86 files listed in tinybsd.basefiles to this tree, then it'll compile a new
87 kernel using the definitions in the TINYBSD file, and finally copy the library
88 dependencies the binaries will have. We'll then populate /etc on that
89 temporary tree and put in a few important default configurations inside on
90 /usr/src/tools/tools/tinybsd/conf/YOURCHOICE/etc/ like rc.conf, fstab and others.
92 Finally, we create an empty image, according to your media's specifications,
93 passed on to the script on the command line, and copy the entire temporary
94 work tree into the image mounted on /mnt.
98 Now that we know how it works, it's time for us to build our own image. Let's
101 1) Choose what pre-configured image you want.
103 2) Edit the TINYBSD kernel file and add/remove all options you'll need.
105 3) Edit the tinybsd.basefiles file and add/remove all binaries you'll need on
108 4) Copy all your /etc configuration which you want to conf/YOURIMAGE/etc/.
110 5) Gather the right information on your destination media. To do that, plug in
111 the device on the system and fetch the information using diskinfo(8):
113 # diskinfo -v /dev/ad2
116 20060135424 # mediasize in bytes (19G)
117 39179952 # mediasize in sectors
118 38869 # Cylinders according to firmware.
119 16 # Heads according to firmware.
120 63 # Sectors according to firmware.
122 To create my image, I'll need to know the media size in sectors, Heads
123 according to firmware and Sectors according to firmware. Optionally, you may
124 define the name of the generated image's file, but if you don't, it'll be
125 named tinybsd.bin. Now that we have gathered these informations through
126 diskinfo, all we need to do is run tinybsd. Remember that it has 3
127 parameters plus 1 optional, and if you don't pass on the required ones, the
128 script will warn you about it:
130 # /usr/src/tools/tools/tinybsd/tinybsd
132 Usage: tinybsd <mediasize in sectors> <heads according to firmware>
133 <sectors according to firmware> <conf> [<tinybsd image name>]
135 Example: tinybsd 62592 4 32
139 /usr/src/tools/tools/tinybsd/tinybsd 62592 4 32 wireless
141 Run diskinfo(8) -v against your CF device to get correct information
144 Passing on the parameters correctly:
146 # /usr/src/tools/tools/tinybsd/tinybsd 39179952 16 63 wireless
147 Creating directory hierarchy...
148 ./bin missing (created)
149 ./boot missing (created)
150 ./boot/defaults missing (created)
151 ./boot/kernel missing (created)
152 ./boot/modules missing (created)
153 ./dev missing (created)
154 ./etc missing (created)
157 In the end, we have the generated tinybsd.bin image. Now we have to copy it to
158 its final destination:
160 # dd if=/usr/src/tools/tools/tinybsd/tinybsd.bin of=/dev/ad2
162 Boot up your new embedded system and log on it. If you're ever going to modify
163 it, you must first remount the root slice as read-write, as it operates by
164 default on read-only mode, saving disk writes and preventing data-loss in case
165 of power failures. To mount it for read-write, use mount:
169 Once you're done, return it to read-only mode:
173 The first thing you need to do after logging for the first time, is to set a
174 root password. By default, it's created with no root password.
176 If you run df(1), you'll see the following partitions:
179 Filesystem 1K-blocks Used Avail Capacity Mounted on
180 /dev/ad0a 29359 19446 7565 72% /
181 devfs 1 1 0 100% /dev
182 procfs 4 4 0 100% /proc
183 /dev/md0 3694 114 3286 3% /var
184 /dev/md1 19566 6 17996 0% /tmp
186 As you can see, /var and /tmp are mounted on /dev/md0 and /dev/md1
187 respectively, using memory disk devices. That's because both /var and /tmp are
188 write-intensive, and as our system works mostly on read-only mode, we'd suffer
189 with writing problems there, so the memory disk approach works fine. On the
190 other hand, whenever you reboot the system, those directories' contents
191 (including logs on /var/log) will be lost. If you need to keep the contents of
192 those directories, I suggest you to always upload them to another box.
194 The configuration line that fires up the system script to create /var as a
195 memory disk partition is "varmfs="YES"", inside
196 /etc/rc.conf. Besides mounting /var as a memory disk device, it also populates
197 its tree with the necessary subdirectories. Initially, /var is created on
198 memory using only 32MB of space, and that's usually enough. Although, if you
199 find it necessary to tweak that configuration, you may edit this line of
204 Change 32m to whatever value you see fit (in MBytes). Take care of not using
205 your entire memory for /var.
209 You can also install ports on the new system via ports. For that, you'll need
210 to set the PREFIX environment variable to the image's destination path. Let's
211 assume you want to install apache on the newly-created image. For that, I'd do
214 # mdconfig -a -t vnode -f /usr/src/tools/tools/tinybsd/tinybsd.bin -u 0
216 That uses mdconfig to enable the memory disk 0.
218 # mount /dev/md0a /mnt
220 Now we've mounted the image on the temporary directory /mnt. Let's then
221 install apache via ports:
223 # cd /usr/ports/www/apache13
224 # make install PREFIX=/mnt/usr/local
225 ===> Vulnerability check disabled
226 >> apache_1.3.31.tar.gz doesn't seem to exist in /usr/ports/distfiles/.
227 >> Attempting to fetch from http://www.apache.org/dist/httpd/.
229 This port has installed the following startup scripts which may cause
230 these network services to be started at boot time.
231 /mnt/usr/local/etc/rc.d/apache.sh
234 Once the install is finished, let's verify that apache has indeed been
235 properly installed under our /mnt directory:
237 # cd /mnt/usr/local/sbin
239 -rwxr-xr-x 1 root wheel 252439 Jul 14 15:31 httpd
241 Our software has been successfully installed. You must notice that at the end
242 of the install, it shows the full path for the PREFIX variable we passed it.
243 The problem with that is that at boot-time, your system is going to look for
244 it under /mnt instead of /usr. So we need to edit apache's initialization
245 script under /usr/local/etc/rc.d (apache.sh) and remove all instances of
248 WARNING: A very important thing to care about are dependencies. Before
249 installing anything, check to see if it has any dependencies, and that you'll
250 have enough disk space on the destination system for both the application
251 you're installing and its dependencies.
255 TinyBSD is still a project under heavy development, both the script itself and
258 In case you'd like to try or use the BETA version of the script, feel free to
259 download it from the project's official site at http://code.google.com/p/tinybsd/.