summaryrefslogtreecommitdiff
path: root/distribution/elbe-example/pres_elbe-example_en.tex
blob: e80a2e11989ef368e5d25afe1f784f502aa6e41e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
\input{configpres}

\title{ELBE example}
\maketitle

\subsection{What will be done?}

\begin{frame}
\frametitle{Goal}
\begin{itemize}
\item generate an ELBE buildenv
\item generate a software component and manage it with debian tools
\item build own software component inside the ELBE buildenv
\item include own application in target RFS
\item define a stripped target RFS
\item setup a local debian mirror
\end{itemize}
\end{frame}

\subsection{generate a buildenv}

\begin{frame}[fragile]
\frametitle{minimal XML file}
\begin{verbatim}
<ns0:RootFileSystem
 xmlns:ns0="https://www.linutronix.de/projects/Elbe"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 created="2009-05-20T08:50:56" revision="6"
 xsi:schemaLocation="https://www.linutronix.de/projects/Elbe dbsfed.xsd">
  <project>
    <name>mini xml</name>
    <version>1</version>
    <description>
      optimal to use as buildenv
    </description>
    <buildtype>armel</buildtype>
    <mirror>
      <primary_host>ftp.debian.org</primary_host>
      <primary_path>/debian</primary_path>
      <primary_proto>http</primary_proto>
      <url-list>
        <url>
          <binary>http://debian.linutronix.de/elbe wheezy main</binary>
        </url>
      </url-list>
    </mirror>
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{minimal XML file}
\begin{verbatim}
    <suite>wheezy</suite>
    <buildimage>
      <kinitrd>elbe-bootstrap</kinitrd>
      <pkg-list>
        <pkg>build-essential</pkg>
        <pkg>debhelper</pkg>
        <pkg>devscripts</pkg>
        <pkg>autotools-dev</pkg>
        <pkg>automake</pkg>
      </pkg-list>
    </buildimage>
  </project>
  <target>
    <hostname>mini</hostname>
    <domain>linutronix</domain>
    <passwd>foo</passwd>
    <finetuning>
    </finetuning>
    <pkg-list>
      <pkg>bash</pkg>
    </pkg-list>
  </target>
</ns0:RootFileSystem>
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{create and build mini.xml}
\begin{lstlisting}
$ elbe create --directory=./buildenv mini.xml
$ cd buildenv
$ make
\end{lstlisting}
\end{frame}

\subsection{build an own application}

\begin{frame}[fragile]
\frametitle{myapp.c}
\begin{lstlisting}
$ mkdir myapp
$ cd myapp
$ $EDITOR myapp.c
\end{lstlisting}
\begin{lstlisting}
#include <stdio.h>
#include <time.h>

int main (int argc, char **argv)
{
    while (1) {
        printf ("Hello ELBE\n");
        sleep (1);
    }

    return 0;
}
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{use autotools}
\begin{lstlisting}
$ $EDITOR Makefile.am
\end{lstlisting}
\begin{lstlisting}
bin_PROGRAMS = myapp
myapp_SOURCES = myapp.c
\end{lstlisting}
\begin{lstlisting}
$ autoscan
$ mv configure.scan configure.ac
$ rm autoscan.log
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle {use autotools}
\begin{lstlisting}
$ $EDITOR configure.ac
\end{lstlisting}
\begin{verbatim}
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([myapp], [1.0], [manut@linutronix.de])
AM_INIT_AUTOMAKE([-Wall -Werror])
AC_CONFIG_SRCDIR([myapp.c])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_CONFIG_FILES([Makefile])

AC_OUTPUT
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{use autotools}
\begin{lstlisting}
$ touch NEWS README AUTHORS ChangeLog
$ $EDITOR autogen.sh
\end{lstlisting}
\begin{lstlisting}
#!/bin/bash
automake --add-missing
autoreconf -sif
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{use autotools}
\begin{lstlisting}
$ chmod +x autogen.sh
$ ls -lh
insgesamt 12K
-rw-r--r-- 1 local local   0 Jan  7 09:45 AUTHORS
-rwxr-xr-x 1 local local  28 Jan  7 09:24 autogen.sh
-rw-r--r-- 1 local local   0 Jan  7 09:45 ChangeLog
-rw-r--r-- 1 local local 496 Jan  7 09:20 configure.ac
-rw-r--r-- 1 local local  35 Jan  7 09:35 Makefile.am
-rw-r--r-- 1 local local 143 Jan  7 09:18 myapp.c
-rw-r--r-- 1 local local   0 Jan  7 09:45 NEWS
-rw-r--r-- 1 local local   0 Jan  7 09:45 README
# these files may be added to your vcs
$ ./autogen.sh
$ ./configure
$ make
$ ./myapp
Hello ELBE
Hello ELBE
^C
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{debianize myapp}
\begin{lstlisting}
$ dh_make -n -p myapp_1.0 -e manut@linutronix.de
$ cd debian
$ rm *.ex *.EX docs README* copyright
$ $EDITOR changelog
\end{lstlisting}
\begin{lstlisting}
myapp (1.0) stable; urgency=low

  * Initial Release.

 -- Manuel Traut <manut@linutronix.de>  Tue, 07 Jan 2014 10:20:20 +0100
\end{lstlisting}
\begin{lstlisting}
$ ls -lh
insgesamt 16K
-rw-r--r-- 1 local local 122 Jan  7 10:20 changelog
-rw-r--r-- 1 local local   2 Jan  7 10:20 compat
-rw-r--r-- 1 local local 517 Jan  7 10:20 control
-rwxr-xr-x 1 local local 135 Jan  7 10:20 rules
drwxr-xr-x 2 local local  19 Jan  7 10:20 source
# these files may be added to your vcs
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{debianize myapp}
\begin{lstlisting}
$ cd ..
$ $EDITOR Makefile.am
\end{lstlisting}
\begin{lstlisting}
bin_PROGRAMS = myapp
myapp_SOURCES = myapp.c

EXTRA_DIST = debian/changelog debian/compat debian/control debian/rules \
  debian/source/format
\end{lstlisting}
\begin{lstlisting}
$ dpkg-buildpackage
$ ls ..
myapp                     myapp_1.0_i386.deb
myapp_1.0.dsc             myapp_1.0.tar.gz
myapp_1.0_i386.changes
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{host myapp in a debian repository}
\begin{lstlisting}
$ cd ..
$ mkdir -p myrepo/conf
$ cd myrepo
$ $EDITOR conf/distributions
\end{lstlisting}
\begin{verbatim}
Origin: myrepo
Label: myrepo
Suite: stable
Codename: wheezy
Update: - myremoterepo
Version:
Architectures: i386 amd64 source
Components: main
Description: my debian packages
\end{verbatim}
\end{frame}


\begin{frame}[fragile]
\frametitle{host myapp in a debian repository}
\begin{lstlisting}
$ reprepro include wheezy ../myapp_1.0_i386.changes
$ sudo mkdir /var/www/
$ sudo rsync -av --exclude=db --exclude=conf * \
/var/www/myrepo/
\end{lstlisting}
\end{frame}


\begin{frame}[fragile]
\frametitle{build debian package inside the buildenv}
\begin{lstlisting}
$ cd ../buildenv
$ make run-con
\end{lstlisting}
login into buildenv and configure apt to use myrepo
\begin{lstlisting}
$ echo 'deb-src http://10.0.2.2/myrepo wheezy main' >> /etc/apt/sources.list
$ apt-get update
\end{lstlisting}
retrive myapp source package and build armel binary package
\begin{lstlisting}
$ apt-get source myapp
$ cd myapp-1.0
$ ./autogen.sh
$ dpkg-buildpackage -b
\end{lstlisting}
copy the package to the host PC and install it into the buildenv
\begin{lstlisting}
$ scp ../myapp*.changes ../myapp*.deb 10.0.2.2:/tmp
$ dpkg -i ../myapp*.deb
$ myapp
\end{lstlisting}
\end{frame}


\begin{frame}[fragile]
\frametitle{add myapp armel package to the repo}
\begin{lstlisting}
$ cd ../myrepo
$ reprepro include wheezy /tmp/myapp_1.0_armel.changes
$ sudo rsync -av --exclude=db --exclude=conf * \
/var/www/myrepo/
\end{lstlisting}
\end{frame}


\subsection{include app in target RFS}

\begin{frame}[fragile]
\frametitle{add repo including myapp}
\begin{lstlisting}
$ cd ..
$ $EDIT mini.xml
\end{lstlisting}
\begin{verbatim}
...
    <mirror>
      <primary_host>ftp.debian.org</primary_host>
      <primary_path>/debian</primary_path>
      <primary_proto>http</primary_proto>
      <url-list>
        <url>
          <binary>http://debian.linutronix.de/elbe wheezy main</binary>
        </url>
        <url>
          <binary>http://LOCALMACHINE/myrepo wheezy main</binary>
          <source>http://LOCALMACHINE/myrepo wheezy main</source>
        </url>
      </url-list>
    </mirror>
    <noauth/>
...
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{add myapp}
\begin{verbatim}
...
  <target>
    <hostname>mini</hostname>
    <domain>linutronix</domain>
    <passwd>foo</passwd>
    <finetuning>
      <rm>var/cache/apt/archives/*.deb</rm>
    </finetuning>
    <pkg-list>
      <pkg>bash</pkg>
      <pkg>myapp</pkg>
    </pkg-list>
  </target>
</ns0:RootFileSystem>
\end{verbatim}
\end{frame}

\subsection{define a striped target RFS}
\begin{frame}[fragile]
\frametitle{define sdcard image}
\begin{verbatim}
...
  <target>
    <hostname>mini</hostname>
    <domain>linutronix</domain>
    <passwd>foo</passwd>
    <console>ttyAMA0,115200</console>
    <package>
      <tar>
        <name>rootfs.tar.gz</name>
      </tar>
    </package>
    <images>
      <msdoshd>
        <name>my.img</name>
        <size>64MiB</size>
        <partition>
          <size>remain</size>
          <label>rfs</label>
        </partition>
      </msdoshd>
    </images>
...
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{create fstab and set elbe mode}
\begin{verbatim}
...
    </images>
    <fstab>
      <bylabel>
        <label>rfs</label>
        <mountpoint>/</mountpoint>
        <fs>
          <type>ext2</type>
          <tune2fs>-i 0</tune2fs>
        </fs>
      </bylabel>
    </fstab>
    <diet />
    <norecommend />
    <finetuning>
...
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{build and extract target as nfsroot}
\begin{lstlisting}
$ elbe create mini.xml --directory=./target
$ cd target
$ make
\end{lstlisting}
hint: it is possible to generate a html page from the elbe-report.txt:
\begin{lstlisting}
$ asciidoc elbe-report.txt
\end{lstlisting}
host the nfs root filesystem
\begin{lstlisting}
$ sudo mkdir -p /nfs/elbe-armel
$ sudo tar xzf rootfs.tar.gz -C /nfs/elbe-armel
$ su -c \
'echo "/nfs *(rw,sync,no_subtree_check,insecure) \
>> /etc/exports"'
$ sudo /etc/init.d/nfs-kernel-server restart
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{build current kernel for qemu armel boot}
\begin{verbatim}
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux
$ cd linux
$ mkdir ../linux-qemu-arm
$ ARCH=arm CROSS_COMPILE=arm-none-eabi- make O=../linux-qemu-arm versatile_defconfig
$ # enable Kernel Features / Use the ARM EABI to compile the kernel
$ #                  Allow old ABI binaries to run with this kernel
$ #        Networking support / Networking options / TCP/IP networking /
$ #           IP: kernel level autoconfiguration / IP: DHCP Support
$ ARCH=arm CROSS_COMPILE=arm-none-eabi- make O=../linux-qemu-arm menuconfig
$ ARCH=arm CROSS_COMPILE=arm-none-eabi- make O=../linux-qemu-arm -j5 
$ cd ..
\end{verbatim}
\end{frame}


\begin{frame}[fragile]
\frametitle{boot nfsroot with qemu}
\begin{lstlisting}
qemu-system-arm -M versatilepb -no-reboot \
  -m 256 -usb \
  -kernel linux-qemu-arm/arch/arm/boot/zImage \
  -append 'root=/dev/nfs nfsroot=10.0.2.2:/nfs/elbe-armel
           ip=dhcp init=/usr/bin/myapp'
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{strip the nfsroot}
\begin{verbatim}
$ sudo rm -rf /nfs/elbe-armel/etc
$ sudo rm -rf /nfs/elbe-armel/sbin
$ sudo rm -rf /nfs/elbe-armel/var
$ sudo rm -rf /nfs/elbe-armel/usr/share
$ sudo rm -rf /nfs/elbe-armel/usr/lib
$ sudo rm -rf /nfs/elbe-armel/usr/sbin
$ sudo cp /nfs/elbe-armel/usr/bin/myapp .
$ sudo rm -rf /nfs/elbe-armel/usr/bin/*
$ sudo mv myapp /nfs/elbe-armel/usr/bin/
$ sudo cp -a /nfs/elbe-armel/lib/arm-linux-gnueabi/ld-* .
$ sudo cp -a /nfs/elbe-armel/lib/arm-linux-gnueabi/libc-2.13.so .
$ sudo cp -a /nfs/elbe-armel/lib/arm-linux-gnueabi/libc.so.6 .
$ sudo rm /nfs/elbe-armel/lib/arm-linux-gnueabi/*
$ sudo mv libc-2.13.so /nfs/elbe-armel/lib/arm-linux-gnueabi/
$ sudo mv libc.so.6 /nfs/elbe-armel/lib/arm-linux-gnueabi/
$ sudo mv ld-* /nfs/elbe-armel/lib/arm-linux-gnueabi/
\end{verbatim}
\end{frame}


\begin{frame}[fragile]
\frametitle{update the ELBE XML file}
\begin{verbatim}
$ sudo mkdir /nfs/elbe-armel-orig
$ sudo tar xzf rootfs.tar.gz -C /nfs/elbe-armel-orig/
$ elbe pkgdiff
$ sudo elbe diff /nfs/elbe-armel-orig /nfs/elbe-armel > diff.txt
$ cd ..
\end{verbatim}
\begin{verbatim}
$ vim mini.xml
$ # place cursor in finetuning section
$ <ESC>:read target/diff.txt<RETURN>
$ # remove everything until 'suggesting:'
$ <ESC>:x<RETURN>
\end{verbatim}
\begin{verbatim}
$ elbe create --directory=target-stripped mini.xml
$ cd target-stripped
$ make
$ # get debian kernel and initrd from the buildenv:
$ make .elbe-vm/vmkernel .elbe-vm/vminitrd
$ # boot the image
$ qemu-system-arm -M versatilepb \
-kernel .elbe-vm/vmkernel -initrd .elbe-vm/vminitrd \
-append 'root=/dev/sda1 init=/usr/bin/myapp' my.img
\end{verbatim}
\end{frame}

\subsection{setup own debian mirror}

\begin{frame}[fragile]
\frametitle{partial clone a remote debian mirror}
\begin{lstlisting}
$ mkdir -p /mirrors/debian
$ cd debian
$ debmirror -p -d wheezy, -a i386,amd64,armel,armhf \
     --di-dist=wheezy \
     --method=http --no-check-gpg \
     -h ftp.de.debian.org .
$ cd /var/www/html
$ ln -s  /mirrors/debian
\end{lstlisting}
\end{frame}

\subsection{Conclusion}
\begin{frame}
\begin{itemize}
\item generate an ELBE buildenv with a minimal XML file
\item manage software components with autotools, dpkg and reprepro
\item build own software component inside the ELBE buildenv
\item include own debian packages in the target RFS
\item edit a running rootfs and make it reproducable
\item setup a partial, local debian mirror
\end{itemize}
\end{frame}

\input{tailpres}