Linux Embedding Mini HOWTO
Luc Hermans, Lhermans@dobit.comv0.2, 15 March 2000
This Document Shows How To Strip Down Your Linux OS, and Provides One Method of Putting It in An Embedded i386 PC And Hopefully Get It Running.
Content
1. Introduction 2. Getting Linux 3. Linux boot process 4. Compile the Linux kernel 5. Build an initial ramdisk image 6. Build and install additional packages 7. Putting everything together 8. Download 9. Useful links
INTRODUCTION
This document is written in the hope that it will be useful to those who want to embed Linux. Specially the one that are new to Linux (like me, I was a DOS / Win user). It will spare you the wrestling true all the Documentation, HOWTO'S AND MAN PAGES I have gone true.
Getting Linux
You can download Linux from the internet or you can take a full Linux distribution. The last one contains everything you need (utilities, sources, compiler, debugger, documentation ...) and is easy to install. (Next to my other OS)
3. Linux Boot Process
We Should Know Some Basics Before We Go Any Further
After the PC starts, the boot manager (found at the MBR of the boot device) launches the linux kernel. With a boot manager like lilo, syslinux, loadlin ... you can pass parameters to the kernel. These parameters are neccessary to boot The Kernel from another root device like a ramdisk.
The kernel then checks your hardware and mounts the root device which contains the root file system. If / linuxrc is present at the root file system it is executed. Next init is started. Init is the parent of all the other processes that will run in your Linux OS, and as a good parent, it will watch these processes and start / stop / re-launch them if things changes. (This process creation is done by the fork = clone_me and execve = replace_me system calls.) Init takes all Information from / ETC / INTTAB Which in Turn Refers to Scripts named / etc / rc ... to do the system setup. inittab also has an entry to start getty for every virtual console.
Getty will launch / bin / login and after a user has logged in, login starts the users default shell (found in / etc / passwd) in the users home directory. Then the shell will execute the users profile. If the user exits the shell INIT WILL RE-Run (Respawn) Getty.
IF / ETC / IS NOT PRESENT The shell / bin / sh is start (in The Hope That Some Intelligent Operator Will Be Present To Tell It What To Do Next).
More Info Can Be Found At Linux Documentation Project and the man page
4. Compile the Linux Kernel
Compiling The Kernel Is Easy and is Done with The Following Commands:
CD / USR / SRC / Linux
Make Xconfig (kernel configuration)
Make Clean (Cleanup Old Objects)
Make DEP (Make All De Arpendencies)
Make Zimage (Compile the Kernel, this can take a while)
With the kernel configuration utility 'make xconfig' you can select each feature to compile into the kernel statically, modular or not at all. You can remove everything you'll never need. For the file systems I choose minix and dos. Because minix will be my root file system on ramdisk, minix and ramdisk must be compiled in statically.For some special devices like the DiskOnChip flash driver you first need to patch the kernel sources, and then recompile the kernel.After a successful compilation the new kernel image is Found AT Arch / i386 / boot / zimage.5. Build An Initial Ramdisk Image
The minimum root file system should Contain The Following:
/LIB/LIBC.SO5 /LIB/ld-Linux.so.1
/etc/ld.so.cach / bin / sh
/ dev / console / dev / null
/ dev / ram / dev / system
/ DEV / TTY1 / DEV / TTY2
We Could Keep It Simple and Just Run One Application and Named It / Bin / Sh, But Mostly We need more So Add the Following:
/ SBIN / INIT / ETC / RC
/ BIN / MOUNT / BIN / CAT
/ BIN / CP / BIN / ECHO
/ dev / fd0 / proc
/ mnt / linuxrc
/ bin / star / bin / zcat (or tar / gzip to install tgz packages)
You can strip down commands by executing objcopy --strip-all srccmd dstcmd (for libraries use objcopy --strip-debug srclib dstlib.) When you add commands you must also include the libraries used. The ldd command gives you a list of all THE LIBRARIES Used by a command.there Are Small Versions of Commands Available, Frequently Used IS ASH, A Tiny Shell, And
Busybox
. BusyBox Contains Different Commands in Just One Binary and SPARE you a lot of ram / disk space.
To build a ramdisk image we will use the loop device (if necessary enable this by insmod loop.o) Copy the files above in a sub dir eg rootfs / then execute the following commands:. Dd if = / dev / zero of = rootfs .IMG BS = 1k count = 400 (make An Empty file of 400k)
Mkfs.minix -c rootfs.img (Make a file system on it)
Mount -o loop -t minix rootfs.img / mnt (mount this as loopback device)
Cp -av rootfs / * / mnt (Copy My Rootfs to the loopback device)
Umount / MNT (un mount the loopback device)
gzip -v9 -c rootfs.img> rootfs.gz (compress it into rootfs.gz)
This will make a compressed ramdisk image rootfs.gz.Maybe its best to keep the rootfs as small as possible. You can always install more features as described below. This way its easier to upgrade, change or download new features.
6. Build and Install Additional Packages
To add more utilities to your system, just copy everything you need (a root tree) into a sub dir eg pack_01 Then compress everything using cd pack_01;. Tar -zcpf ../pack_01.tgz * Be sure to include all dependencies (libraries , configurations / etc / ...) in the package.
To install this at boot time copy all the package ket, and inflicment application. If ified device is a dos formatted floppy at / dev / fd0 Then Linuxrc (Which is in rootfs.gz) CAN Look Like:
# --- / linuxrc ---
#! / bin / sh
Mount -T DOS / DEV / FD0 / MNT
CP / MNT / ETC / * / ETC
Linuxrc Copies Everything from / etc On the root device.a Simple / etc / inittab and / etc / rc:
# --- / etc / inittab ---
#SYNTAX ID: RUNLVEL: Action: Path
ID: 2: INitDefault:
Si :: sysinit: / etc / rc
01: 12345: Respawn: / sbin / getty 38400 TTY102: 2345: Respaw: / sbin / getty 38400 TTY2
# --- / etc / rc ---
#! / bin / sh
Echo -n> / etc / mtab (Write New MTAB)
Mount -o Remount -t minix / dev / ram /
Mount -o Remount -t Proc Proc / Proc
Mount -o Remount -t DOS / DEV / FD0 / MNT
Package = `LS / MNT / PACK` (Get a list of all packages)
For f in $ package; do
Zcat <$ f | star (Decompress and Install Every Package Found)
DONE
...
IF you run out of ramdisk you can always mount some more:
MKDIR / USR
Mkfs.minix -i 400 / dev / ram1
Mount -t minix / dev / ram1 / usr
You can add your owrnel boot parameters (e.g. loadlin.exe zimage init = rootfs.gz root = / dev / ram mypar1 = test1 mypar2 = test2) and get it to do do this:
CAT / proc / cmdline> / etc / cmdline
Echo -n "f = fix" >> / etc / cmdline
. / etc / cmdline
Echo $ mypar1
Echo $ mypar2
7. Putting Everything Together
We are almost there. Just Copy The Linux Kernel, Ramdisk Image, etc AND package your boot device and install a boot manager. For syslinux this boot dir contains:
/ ldlinux.sys
/syslinux.cfg
/ zimage
/rootfs.gz
/ etc / inittab
/ ETC / RC
/PACK/PACK_01.TGZ
/Pack/pack_02.tgz
WHERE SYSLINUX.CFG SHOULD Contain:
TIMEOUT 0
Default zimage
Append = loading_ramdisk = 1 initrd = rootfs.gz root = / dev / ram
You Can Also Put All this stuff in a sub Dir of Your Hard Drive and launch Linux from the Harddisk with: loadinglin.exe zimage initrd = rootfs.gz root = / dev / ram
Thats all. Good luck!
8. Download and Quick Start
After downloading the floppy disk image emblin.img use the commanddd if = emblin.img of = / dev / fd0 to make a bootable floppy.From DOS you can run the dos app rawrite3 or WinImage to build the floppy. Reboot from this floppy and type config.cmd to edit the one and only configuration script rc.cmd. Set your network_interface eth0, ip_addr, network_mask, default gateway, DNS ... Save your settings with Esc, Datei, Beenden, Y and restart Emblin. From another network stations browse to EmbLin with your favorite navigator (enter http: ip_addr) and you will get the EmbLin home page Try out the sysstat CGI-script, ftp, telnet, tftp.PS:. If you run the windows telnet use Ctrl-J ( LF) instead of Enter (CR) you can also use EmbLin as a client;. lynx, ftp, telnet and tftp For more help you can always try help This floppy also contains the sources of a tiny init, extracted from an old version of Busybox i modified. if you build your owybox System Use The New BusyBox Which Has Much More Features N OW (But Did Not Compile ON My System) .install with tar -xzvpf source.tgz / emblin and do the reverse of the mypack / build.pac script.9. Useseful Links
Emblin Home Embedded Linux HOWTO Linux Documentation Project Linux Bootdisk HOWTO Linux-Embedded www.linux.org www.linux.com