This paper explores how to generate a minimized Linux target from a standard distribution. Most minimalization tools either create from scratch: a new distribution dedicated to a special functionality (ex: DSL, Leaf, OpenPBX, LTSP, ...) or reduce an existing distribution by skimming installed packages (OpenSuSE/KIWI, Ubuntu/JeOS, RedHat/ELDS). This paper describes a mixed approach, where you start from a standard running distribution (Ubuntu, OpenSuSE, ...) and extract the minimum set of binaries required for your target.The advantage of this host/target approach, is that it does not impose you a special distribution, provide a simple method to keep in sync your development host and embedded target. On the other hand you should understand in deep the dependencies of selected binaries and your boot process.
How look a minimized Linux ?
A minimal Linux is a skimmed down operating system that only support required applications, This being said and independently of the number of applications, Linux needs at 4 elements:
- a booting process
- a kernel with necessary modules to support your hardware
- a root file system with basic (/etc, /dev,..)
- at least one application (apache, sshd, ...)
How small can it be ? this obviously depend on the application you want to embedded. Linux minimal footprint (kernel + minimal root filesystem) is around 6MB, if you add some minimal applications like sshd+httpd you end up with a final distribution below 8MB. On RAM side, when starting a TinyLinux with 32M of Ram 12M remain free, which set our ram footprint ~20M on which 3M are used for our root filesystem in memory.
MyTinyLinux script automates minimization of Linux and generate an ISO cd image of your target.
MkLinux is a very simple script that takes one config file as input, this files describes which binary commands you want in your target, as well as config and/or application files. The script will search for you shared libraries dependencies, will build a minimal root directory from its generic template and will finally build a bootable ISO CD image.
1) Chose binaries you want in your target OS. Obviously those binaries must be installed on your Linux host, if you miss one (ex: busybox, lighthttp, tcpdump, ...) get it from your standard package management tool (ex: zypper, apt-get, ...) Let's say that you only want "sshd" you config in your target:
| # very basic target only include ssh client & server part BINLIST=" ssh scp sshd /lib/security/pam_unix.so " |
2) Define kernel module to support your target hardware: by default outside of Ethernet interface and SATA drivers most distributions include everything you need inside their core kernel, as we run only in memory and thus do not need disk, adding your NIC driver is probably enough. If you intend to run under VirtualBox you need Intel e100 driver, for vmWare pcnet32, .... af_packet module is needed for dhcp, etc ....
| # include intel(e100) for VirtualBox and pcnet32 for vmWare.# --------------------------------------------------------------------------------------------------------------- # kernel module you want in initrd (don't forget to check dependancies) MODLIST=" e100.ko pcnet32.ko af_packet.ko " |
3) Basic basic utilities needed to operate Linux: almost independently of the application you want to run, you will need for "extra" tools. Like "ifconfig" to choose target's IP address, modeprobe to load your NIC kernel module, ... this without forgetting some basic shell commands capabilities, "vi" or equivalent to edit configuration file directly target, and often some debug tools like "tcpdump, netstat, ....". A special note for Swiss knife "busybox" , it provides most of required simple tools, indeed it is so painful to build an embedded Linux without it, that MkTinyLinux defaults its inclusion. Note that needed utilities may depend on chosen target hardware or virtualization environment.
| # Include some basic tools to support final runtime environment.# --------------------------------------------------------------------------------------------------- # Commands depending on final runtime environement chose EXTRA_OPENVZ="bash chpasswd ifup"EXTRA_ISO="modprobe lsmod insmod rmmod depmod dhcpcd"EXTRA_XEN=$EXTRA_ISO # Commands we need what ever is our final targetBASIC_CMD=" /lib/ld-linux.so.2 ldd halt shutdown ifconfig " |
4) Files/directories that cannot be detected automatically: MkTinyLinux try to discover dependencies automatically, while this works well for sharedlib, unfortunately they is no way to find that "ssd" need "/etc/ssh", that you "/lib/libnss_files.so.2" is requirer to enable login/password, that your target need a French keyboard, ...
# OpenSuSE French MAP (must be before SHARELIST) # Files must be an obsolute path |
Download MkTinyLinux
- configuration samples (OpenSuSE-tiny.conf) (sshd-only-ubuntu.conf)
- iso sample (8MB) (azerty-dhcp.iso) (qwerty-dhcp.iso)
Generate a target with MkTinyLinux script
Dependencies
MkTinyLinux is a simple "bash" script and has almost no dependencies, nevertheless you may have to add "busybox" and "mkisofs" command that are not defaulted inside typical distributions. Nevertheless they are available witjout requirering compilation, inside most of standard repositories. More rarely you may have to add some package to get supplementary kernel modules to support you hardware.
- OpenSuSE: zypper install cdrkit-cdrtools-compat busybox
- Debian: apt-get install genisoimage busybox
Command line options
mkTinyLinux config=??? target=??? [destdir=. template=generic tmpdir=/tmp root=no busybox=no verbose=1]
- config your configuration file
- target fix target runtime environment [openvz,iso,xen]
- destdir final distribution directory (.iso|.tgz) directory [default=.]
- template root-tree template [default=Templates/Generic] it is used as foundation for your final distribution, you may create here dedicated /etc/init.d scripts.
- tmpdir temporary directory use to built your distribution [default=tmp], for debug purpose tempry files are not deleted automatically
- root it is almost impossible to run MkTinyLinux without being super user, this option cancel the assertion made on root user.
- busybox Swiss knife is almost mandatory to built embedded Linux [default=yes], allow you may change default behavior, when ever busybox is not appropriated.
- verbose Provide some guidance at MkTinyLinux actions.
Quickstart MkTinyLinux
| # Download distribution wget http://www.fridu.org:/download/mktinylinux/mkTinyLinux-v1.1.tgz # Uncompress archive tar -xzf mkTinyLinux-v1.0.tgz cd mkTinyLinux # Check for typical missing packages zypper install cdrkit-cdrtools-compat busybox ;# OpenSuSE apt-get install genisoimage busybox ;# Debian, Ubuntu, ... # Generate a simple SSH only distribution ./mkTinyLinux.bash config=sshd-only-ubuntu.conf target=iso # Your ISO is done Result 6.9MB :) ls -lh sshd-only-ubuntu.iso -rw-r--r-- 1 root root 6,9M 2008-11-20 22:10 sshd-only-ubuntu.iso # install qemu, virtualbox, .... to check you new supersmall Linux qemu -cdrom httpd-sshd-tiny.iso -boot d ;# warning should not beun through SSH !!! |
Download MkTinyLinux
With configuration samples and root file system template from (here)
Something is going wrong?
1) Try a "chroot" on temporary directory
The simplest way is to use a virtualization environment like VirtualBox that is available for free for Linux & Windows. This being said if you fail to boot your ISO cdrom image, the first thing is to check your distribution with a simple "chroot" command. As mkTinyLinux script does not remove automatically temporary files you can use them "/tmp" directly.
| # Test target bourne shell chroot /tmp/sshd-tiny-ubuntu /bin/sh # Check SSHD does not miss anything chroot /tmp/sshd-tiny-ubuntu /usr/sbin/sshd -p 2222 -d |

2) try to boot with virtualbox
the next step is too check your init process. Unfortunately you cannot do this with "chroot" command, and you need a real virtualization tool as VirtualBox, KVM, QEMU, vmWare, etc. You only need to define boot cdrom through its ISO image, VirtualBox will warn you that you forgot to define a hard disk, just ignore the advice and move forward. Usually what's happen is that your init process fail to execute some commands from /etc/init.d or from what ever is your initial boot process [ex: /etc/evend.d for ubuntu, /etc/inittab for OpenSuSE, ...] If everything works you should arrive to Linux boot prompt.(see VirtualBox snapshot here after).





file : sshd-tiny-ubuntu.conf
rows: # OpenSuSE French MAP (must be before SHARELIST)
FRENCHMAP="/usr/share/kbd/keymaps/i386/azerty/fr-pc.map.gz"
============= Fulup respond ==========
Obviously it works :(
Nevertheless with Ubuntu-9.04 you need mkTinyLinux-v1.1.tgz,and as you pointed out, I forgot to update this section of my page :(
Ubuntu has changed French keyboard mapping files, I renamed sample config to sshd-only-ubuntu.conf to reflect this. For 9.04 French section need to be updated as: FRENCHMAP="
/usr/share/kbd/keymaps/i386/azerty/fr-pc.map.gz
/usr/share/kbd/keymaps/i386/include/azerty-layout.inc
/usr/share/kbd/keymaps/i386/include/linux-with-alt-and-altgr.inc
/usr/share/kbd/keymaps/i386/include/linux-keys-bare.inc"
Outside of this French keyboard mapping and minor Busybox options, they're is no difference in between Ubuntu and OpenSuSE. MkTinyLinux works on both. Nevertheless you should understand that for each new version of a distribution, configuration files may need a tiny update.
Thanks
=== Fulup Respond =====
You may quite easily use this technique to build a very minimal proxmox template (ex: tomcat, LAMP, ...) and reduce your downloadable appliance size by ~10. This being said if your goal if to build the main installation of proxmod, then you need to discover the hardware, format the disk, install everything, ... This is a significant job and will end up with just and other distribution, as a result using something like JeOS(ubuntu) of KIKI(opensuse) to reduce and existing distribution to the minimum looks a better approach for your problem for your specific problem (if I understand it correctly)