160 likes | 390 Views
Cheap Off-the-Shelf Tiny Linux By Dzuy Nguyen dzuy@itlogistic.net. COST Linux. What it is. Home-brewed tiny Linux distro. More like Linux From Scratch. Made from readily available hardware (i386) and binaries from your favorite distro. Customed compiled kernel.
E N D
Cheap Off-the-Shelf Tiny Linux By Dzuy Nguyen dzuy@itlogistic.net COST Linux
What it is • Home-brewed tiny Linux distro. More like Linux From Scratch. • Made from readily available hardware (i386) and binaries from your favorite distro. • Customed compiled kernel. • Small storage device: Solid State Disk (SSD) rather than spinning hard drive.
Usage: network appliances • Firewall/VPN • Router • DNS server • Load Balancer (LVS) • Proxy server • Any dedicated network service • Other projects: • Carputer • Home automation
Advantage • Secured. • Reliable (no spinning part). • Crash proof. • Hardened (no extra software that you don't need). • Easy upgrade: just replace file system images. • Flexible: separation of root and application file system. • Did I mention low COST?
Ingredients • Kernel: (custom) compiled as module as much as you can to keep kernel small. • Boot strap initrd to pre-load module and prepare memory as disk. • /: Busy box • Login: Tiny login (with PAM) • Logs: can be remote or local (clean with cron). • Other: binaries from your RPM or compiled apps.
Compressed file system images • Root FS: for /. Resides in RAM disk (initrd), rw. Size: 4MB file system, ~2MB populated. • Local FS: Other apps and libraries. Mount either from memory or flash disk. (ro). Size: 4-8MB depends on amount of apps. • Sysconfig FS: Resides on flash disk (rw) for permanent storage. Stores system's configurations. Size: 100KB and up.
Prepare file system on disk • Create a loopback file system (need loop module): • # dd if=/dev/zero of=rootfs bs=1k count=<size> • Make file system: • # mke2fs -N 2048 rootfs • Mount the file system • # mount -o loop rootfs /mnt • Copy files from target workspace.
The root file system • Need: /dev, /proc, /etc, /sbin, /bin, /lib, /mnt, /usr, /var, /home, /tmp • /dev: device files (hd*, ram*, tty*, std*, etc.) • # cp -dpR /dev/hda[0-5] /mnt/dev/ • /etc: fstab, passwd, group, inittab, mtab, resolv.conf, sysconfig, etc. • (/usr)/bin and (/usr)/sbin: system utilities to be provided by busy box (and more). • /lib: libc (must have), ld-linux (most popular), libscrypt (busybox), libdl, libnsl, libresolv (and more).
Shrink binaries - strip them • Strip -s: remove debug symbols • Strip -g: remove all symbols • Strip libraries and executables only. Do not strip modules
Apps (/usr/local) file system • /usr/local/bin, /usr/local/sbin: application binaries • /usr/local/etc: rc scripts • /usr/local/lib: other supporting library • /usr/local/lib/modules: kernel modules • /usr/local/lib/security: PAM modules • /usr/local/lib/iptables: iptables modules (if firewall).
Sysconfig file system • Store system configuration stuffs • Network configuration files. • modules.conf • Other: syslog, logrotate.conf, sysctl.conf, hosts, passwd, shadow, group (link to /etc) • Other apps' config files can be stored here and called appropriately.
Initrd file system • Similar to root file system • There must be a /linuxrc executable. • The linuxrc executable can be a script or binary. If script, the shell must be present. • All linked libraries must be present and accessible. • Use linuxrc to pre-load modules and prepare (RAM) file system.
Boot loader • Choice of your favorite bootloader: GRUB or LILO. • GRUB • Advantages: easy to config and don't need to re-run like LILO when kernel is upgraded. Splash screen possible. • Disadvantages: larger than LILO. • LILO • Advantages: small, works on all medium. • Must re-run LILO when kernel changes.
Boot process • BIOS -> Boot loader -> kernel -> initrd -> linuxrc -> init • Init is not really needed. Can run system from linuxrc, just make sure it does not exit. Most commercial embedded system does not use init. • Init -> inittab -> rc -> rc.sys • Busybox has its own init and shell (ash). • Modify rc and rc.sys to bring up your system.
Hardware • Any system with BIOS that is willing to boot our bootloader or kernel. • Cheap thin clients are available on eBay • Netier XL and SL series • Capio II 2992 • Acute Network Technologies • GTC Allwell • IBM NetVista 8363 N2200 • Single Board Computers • More (not yet hacked).
Solid State Disk • DiskOnChip: manufactured by M-Systems. Available on selected boards only. GRUB must be burned in. Special driver module is needed. • DiskOnModule: available in 40 and 44 pin IDE. Sticks right on your IDE port. BIOS sees it as hard disk. • Compact Flash: cheapest SSD. Some boards have CF interface on board. IDE to CF converter is also available. • DiskOnStick: USB flash disk. Some boards can boot from these. Need to load some USB drivers in order to see as /dev/sd (SCSI) disk.