]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - tools/tools/tinybsd/README
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / tools / tools / tinybsd / README
1 # $FreeBSD$
2
3 - TinyBSD
4
5 You must read this to know how to build embedded systems with TinyBSD.
6
7 - TinyBSD files
8
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.
11
12 The system has been entirely based on the ease of image customization from
13 PicoBSD, and the compilation script based on NanoBSD's.
14
15 # ls /usr/src/tools/tools/tinybsd/conf
16 bridge/   default/  firewall/ minimal/  vpn/      wireless/  wrap/
17
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:
20
21 # ls /usr/src/tools/tools/tinybsd/conf/default
22 TINYBSD            etc/               tinybsd.basefiles
23
24 TINYBSD: Just like PicoBSD had its kernel previously compiled, we call ours
25 TINYBSD.
26
27 # more TINYBSD
28
29 machine         i386
30 cpu             I486_CPU
31 cpu             I586_CPU
32 cpu             I686_CPU
33 ident           TINYBSD
34
35 #To statically compile in device wiring instead of /boot/device.hints
36 #hints          "GENERIC.hints"         #Default places to look for devices.
37 ...
38
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.
41
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
46 needs. Let's see it:
47
48 # more tinybsd.basefiles
49 # contents of ${WORKDIR}/boot
50 boot/boot0
51 boot/boot1
52 boot/boot2
53 boot/defaults/loader.conf
54 boot/device.hints
55 ...
56 # contents of ${WORKDIR}/bin
57 bin/[:bin/test
58 bin/cat
59 bin/chflags
60 bin/chio
61 bin/chmod
62 ...
63
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:
67
68 usr/sbin/pw
69 usr/sbin/pwd_mkdb
70 usr/sbin/setkey
71
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:
75 www/mini_httpd
76 net-mgmt/rate 
77
78 etc/: This is the directory where you can put your custom /etc configuration.
79
80 # ls /usr/src/tools/tools/tinybsd/tinybsd
81 tinybsd
82
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.
91
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.
95
96 - Running TinyBSD
97
98 Now that we know how it works, it's time for us to build our own image. Let's
99 do that step-by-step.
100
101 1) Choose what pre-configured image you want.
102
103 2) Edit the TINYBSD kernel file and add/remove all options you'll need.
104
105 3) Edit the tinybsd.basefiles file and add/remove all binaries you'll need on
106 your system.
107
108 4) Copy all your /etc configuration which you want to conf/YOURIMAGE/etc/.
109
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):
112
113 # diskinfo -v /dev/ad2
114 ad2
115         512             # sectorsize
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.
121
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:
129
130 # /usr/src/tools/tools/tinybsd/tinybsd
131 Woops!
132    Usage: tinybsd <mediasize in sectors> <heads according to firmware> 
133    <sectors according to firmware> <conf> [<tinybsd image name>]
134
135    Example: tinybsd 62592 4 32
136
137         or
138
139    /usr/src/tools/tools/tinybsd/tinybsd 62592 4 32 wireless
140
141    Run diskinfo(8) -v against your CF device to get correct information
142    about your disk.
143
144 Passing on the parameters correctly:
145
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)
155 ...
156
157 In the end, we have the generated tinybsd.bin image. Now we have to copy it to
158 its final destination:
159
160 # dd if=/usr/src/tools/tools/tinybsd/tinybsd.bin of=/dev/ad2
161
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:
166
167 # mount -u -o rw /
168
169 Once you're done, return it to read-only mode:
170
171 # mount -u -o ro /
172
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.
175
176 If you run df(1), you'll see the following partitions:
177
178 # df
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 
185
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.
193
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
200 /etc/rc.conf:
201
202 varsize="32m"
203
204 Change 32m to whatever value you see fit (in MBytes). Take care of not using
205 your entire memory for /var.
206
207 - Ports and TinyBSD
208
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
212 this:
213
214 # mdconfig -a -t vnode -f /usr/src/tools/tools/tinybsd/tinybsd.bin -u 0
215
216 That uses mdconfig to enable the memory disk 0.
217
218 # mount /dev/md0a /mnt
219
220 Now we've mounted the image on the temporary directory /mnt. Let's then
221 install apache via ports:
222
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/.
228 ...
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
232 ....
233
234 Once the install is finished, let's verify that apache has indeed been
235 properly installed under our /mnt directory:
236
237 # cd /mnt/usr/local/sbin
238 # ls -lga httpd
239 -rwxr-xr-x  1 root  wheel  252439 Jul 14 15:31 httpd
240
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
246 "/mnt" in it.
247
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.
252
253 - Script download
254
255 TinyBSD is still a project under heavy development, both the script itself and
256 its documentation. 
257
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/.