10015.Linux EMBEDDING mini HOWTO

转载 2004年10月18日 10:26:00

Luc Hermans, lhermans@dobit.com

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

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.

2. 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. (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.

4. Compile the Linux kernel

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.

5. Build an initial ramdisk image

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 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 e.g. rootfs/ then execute the following commands:

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 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: 

7. Putting everything together

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!

8. Download and Quick start

  • After downloading the floppy disk image emblin.img use the command
    dd 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 own Linux system use the new busybox which has much more features now (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. Useful links

C++ dlopen mini HOWTO

C++ dlopen mini HOWTO Aaron Isotton aaron@isotton.com> $Id: C++-dlopen-mini-HOWTO.xml,v 1.15 200...
  • zjq2008wd
  • zjq2008wd
  • 2013年12月26日 15:33
  • 705

[mini howto] JSP debug

之前jsp開發常常會遇到debug很痛苦,給剛入門的人一個debug方式參考 , 不假藉任何IDE,希望可以幫助解決大部分的問題 0. 直接看 jspc產生的.java檔以tomcat為例.../wo...
  • llp1217
  • llp1217
  • 2004年08月26日 09:36
  • 955


http://linux-ip.net/articles/Traffic-Control-HOWTO/components.html 翻译 4. Linux TC模块(代码在 net/sche...
  • batmancn
  • batmancn
  • 2015年12月21日 14:07
  • 949

ncurses programming howto 书中源代码-2

/*  * =====================================================================================  *  *...
  • yskcg
  • yskcg
  • 2010年09月29日 08:49
  • 356

python magic method

A Guide to Python's Magic Methods Copying Sometimes, particularly when dealing with mutable obj...
  • qq550764107
  • qq550764107
  • 2014年03月01日 21:39
  • 447

Word Embedding中Embedding的解释

今天在看部分NLP中关于词处理的过程中,多次看到word embedding,word representation等关键词,其中对于嵌入的一个直观感受是将word从一个空间映射到另一个空间,这样做的...
  • Nicholas_Liu2017
  • Nicholas_Liu2017
  • 2017年07月05日 10:00
  • 545


Samba计划文档 (初稿)Samba小组编译:meaculpa 中文译稿声明: 该文档是Samba软件的一部分,受GNU GPL保护,使用时请注意版权问题;由于译者水平有限,错误之处在所难免,希望各...
  • freexploit
  • freexploit
  • 2005年01月29日 11:25
  • 4081

CAS 统一认证服务器及应用。

预备知识:详细请见:Tomcat的帮助文档,:https://localhost:8080/tomcat-docs/ssl-howto.html  。1、用keytool生成证书:        ke...
  • lmn13
  • lmn13
  • 2011年07月13日 11:09
  • 4275

Functional Programming HOWTO(Python It's great)

Functional Programming HOWTO http://docs.python.org/dev/howto/functional
  • lantianjialiang
  • lantianjialiang
  • 2013年06月28日 12:27
  • 677


Writing Linux LCD drivers Writing Linux LCD drivers Abstract 1 LCD Module/Driver/Controller 2 Linux ...
  • BackStrokeFish
  • BackStrokeFish
  • 2005年05月30日 10:53
  • 2599
您举报文章:10015.Linux EMBEDDING mini HOWTO