10015.Linux EMBEDDING mini HOWTO
Luc Hermans, v0.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.
- 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
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.
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)
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. (or you can patch these settings into the kernel using rdev)
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/inittab 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/init is not present the shell /bin/sh is started (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 pages of init and inittab.
Compiling the kernel is easy and is done with the following commands:
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.
The minimum root file system should contain the following:We could keep it simple and just run one application and named it /bin/sh, but mostly we need more so add the following:
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
lddcommand 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 e.g.
rootfs/ then execute the following commands:
This will make a compressed ramdisk image
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.
To add more utilities to your system, just copy everything you need ( a root tree) into a sub dir e.g.
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 packages.
To install this at boot time copy all the packages to /pack, and inittab and rc to /etc of our boot device. If our boot device is a dos formatted floppy at /dev/fd0 then linuxrc (which is in rootfs.gz) can look like:Linuxrc copies everything from /etc on our boot device to /etc on the root device.
A simple /etc/inittab and /etc/rc:
If you run out of ramdisk you can always mount some more: You can add your own kernel boot parameters (e.g.
loadlin.exe zimage initrd=rootfs.gz root=/dev/ram mypar1=test1 mypar2=test2) and get them into your script. An easy way to do this:
We are almost there now. Just copy the linux kernel, ramdisk image, etc and packages to your boot device and install a boot manager. For syslinux this boot dir contains:Where syslinux.cfg should contain:
You can also put all this stuff in a sub dir of your hard drive and launch linux from the harddisk with:
loadlin.exe zImage initrd=rootfs.gz root=/dev/ram
Thats all. Good Luck!
- After downloading the floppy disk image emblin.img use the command
dd if=emblin.img of=/dev/fd0to 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.cmdto 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 own Linux system use the new busybox which has much more features now (but did not compile on my system).
tar -xzvpf source.tgz /EmbLinand do the reverse of the