The Linux root FilesystemThe Linux root filesystem contains files and executables that the kernel requires, as well as executables for system administration. In a desktop workstation installation, the kernel mounts a hard disk partition on the / directory. The following directories exist beneath the / directory:
The Trailblazer engineers began to understand the root filesystem contents by examining tbdev1 (the Debian distribution development computer, which is described in Chapter 3, "Selecting a Platform and Installing Tool Sets"). They found that the root filesystem contained 10,734 files and used 67.428MB of hard disk space. They found that a default Red Hat installation contains 29,296 files and uses 382.020MB. Clearly, taking the simple approach of merely copying the contents from a default Debian or Red Hat disk exceeds the storage capability of the engineers' four target platforms, which ranges from 4MB to 16MB. The engineers needed to decide what files are really necessary to boot Linux and execute a bash prompt. TIP Developing a root filesystem by examining the Linux boot process from start_kernel to the bash prompt results in a minimum set of required files and gives you an understanding of Linux's interaction with programs and libraries. Someone suggested that they could just start deleting files and see what happens. That hit-or-miss approach was quickly dismissed. The engineers learned from the Linux boot process that the kernel starts the init process that executes network and system initialization scripts and then executes bash. The engineers then wondered what files are required for init, the network and system initialization, and bash. Then, concern surfaced about this init/bash file approach and the four target platforms. The engineers wondered if they could determine what files are necessary for init and bash, would those same files be required for all architectures? Or would some architecture-based files be missing? No one had an answer other than to say that after the kernel boots, all architectures shared the same source code for init, bash, and the shared libraries. This means that if the engineers determine a root filesystem for one architecture, it should work for the others. Required Files for initAfter the kernel initializes its caches and various hardware devices, it executes the first user process, init, which spawns all other process. In order for init to run, it needs certain files and libraries to be present in the filesystem. On tbdev1, the engineers used a program called ldd to discover init's shared library dependencies. This is the output of ldd: root@tbdev1[514]: ldd /sbin/init libc.so.6 => /lib/libc.so.6 (0x40015000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) The first file the new root filesystem needs is /sbin/init, which requires /lib/libc.so.6 and /lib/ld-Linux.so.2. By reading the man page for init, the engineers determined that init uses a configuration file called /etc/inittab that contains instructions for init. On a desktop or server Linux workstation, the init process initializes the networking and system services, and then it enters a runlevel typically the login process. On the target systems, the engineers are not concerned with runlevels per se; rather, they want to boot the system and get bash running. So they aren't using a predefined runlevel, as in the Unix/Linux world. They are configuring init to simply initialize the network. Then they are configuring init to execute bash without authentication and to respawn bash if bash terminates. TIP The kernel completes booting by executing the first user process, init. init's scripts start all the system services. You can configure init to start programs and then to restart them if they terminate. The engineers examined the /etc/inittab file on the tbdev1 workstation. They then created a simplified version that initializes the network and then executes bash. Here's their simplified inittab file: id:2:initdefault: l2:2:wait:/etc/init.d/rcS 1:2435:respawn:/bin/bash 2:6:wait:/etc/init.d/umountfs In this version of the /etc/inittab file, id:2:initdefault: tells init the default level to enter. l2:2:wait:/etc/init.d/rcS tells init to run the /etc/init.d/rcS script before entering runlevel 2, and then to wait for completion. 1:2435:respawn:/bin/bash tells init to run /bin/bash and respawn it if bash terminates. 2:6:wait:/etc/init.d/umountfs tells init that upon entering runlevel 6, someone is rebooting the target board, to run the umountfs script and wait for its completion. Required Files for bashThe bash shell requires libraries to execute. On tbdev1, the engineers again used ldd to discover bash's shared library dependencies. Here is the output of ldd: root@tbdev1[516]: ldd /bin/bash libncurses.so.5 => /lib/libncurses.so.5 (0x40016000) libdl.so.2 => /lib/libdl.so.2 (0x40055000) libc.so.6 => /lib/libc.so.6 (0x40059000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) In addition to init, inittab, rcS, umountfs, ld-linux.so.2, and libc.so.6, the new root filesystem needs bash, libdl.so.2, and libncurses.so.5. The engineers poked around in the /bin, /sbin, and /usr/bin directories and found that the following programs would also be necessary in order to have a functional system: cat, ls, mount, umount, ps, df, kill, ping, chmod, touch, rm, ifconfig, route, telnet, and gdbserver. They checked for shared library and configuration file dependencies, and after a little trial and error, they compiled the root filesystem file list shown in Table 4.1. These files exist in a directory structure that consists of these directories: /bin, /dev, /etc, /etc/init.d, /lib, /proc, /sbin, /tmp, /usr, and /usr/bin. With this root filesystem, the kernel calls init, which initializes the network and then executes bash. A user can then ping other network computers and run helloworld. This booted system will fulfill all seven PBRs. TIP The Linux program ldd outputs a list of shared libraries required by a program or library. When adding programs to the root filesystem, you should use ldd to determine whether additional libraries are required.
The root Filesystem Binary Files: Compile or Download?The engineers determined that it would be easy to find all these files for the i386 platforms. They could just copy them from the tbdev1 computer. The ARM and PowerPC versions would require cross-compiling. Although this list is short compared to the Debian base installation of 10,734 files, cross-compiling all these executables would require significant effort. The most current source code would have to be located and downloaded. The individual makefiles would require modification for cross-compiling and library linking. Finally, the code would need to be compiled. The engineers thought that there must be an easier way, that someone else had probably already done this ARM and PowerPC cross-compiling. During their initial research, the engineers found that the Debian Linux site (www.debian.org) contains source and compiled binaries for Alpha, ARM, i386, m68k, PowerPC, and SPARC processors. This availability of compiled binaries looked promising, until the engineers investigated the source code versions. The Debian software distribution lags behind current versions of open-source software. Debian publicly acknowledges this and distributes software "when it's time." In addition, the Debian versions of PowerPC binaries are compiled for microprocessors that have floating-point units. The Trailblazer RPX-CLLF target board uses a Motorola MPC860 that doesn't have a floating-point unit. They decided to look elsewhere. Recently, MontaVista software released Hard Hat Linux (HHL), version 2 using kernel version 2.4.2.1 MontaVista distributes two varieties of HHLv2: the Journeyman and the Professional editions. The Journeyman edition caught the engineers' attention because it supports i386, ARM, and PowerPC, specifically the MPC8xx processors and it's free. The Journeyman CD contents as well as CD images are publicly available at the MontaVista FTP site (ftp.mvista.com/pub/Journeyman). TIP Some PowerPC microprocessors don't have a floating-point unit and don't execute floating-point instructions gracefully. When executing PowerPC programs, you should make sure they have been compiled correctly for your microprocessor. MontaVista's HHLv2 isn't just a repackaging of the open-source GNU software. MontaVista's engineers are considered leading developers in architecture porting issues and development activities. They have incorporated much of their work (via patches) into the MontaVista distribution. All their architecture-specific work for the kernel and other GNU software is incorporated into the HHLv2 source and binaries. The Project Trailblazer engineers, who aren't architecture experts, were excited that they wouldn't have to become experts just to get their target platforms booted. The engineers decided that instead of reinventing the wheel, they could use MontaVista's Journeyman product, including the Journeyman cross-compiled versions of the programs for their ARM and PowerPC root filesystem. After a successful booting of both the ARM and PowerPC target platforms, they decided to use Journeyman for i386 root filesystem as well. This decision simplified their lives in ways they didn't imagine. Building a root filesystem for all the target platforms eventually involved running a script that would download the Journeyman Red Hat Package Management (RPM) binaries, extract the files, copy various binary programs to the new root filesystem, and create all the configuration files. This script, called buildrootfilesystem, is shown in Listing 4.1 and can be found at www.embeddedlinuxinterfacing.com/chapters/04/buildrootfilesystem. Listing 4.1 The buildrootfilesystem Script[View full width] #!/bin/bash # buildrootfilesystem v0.2 10/23/01 # www.embeddedlinuxinterfacing.com # # The original location of this script is # http://www.embeddedlinuxinterfacing.com/chapters/04/buildrootfilesystem # # Copyright (C) 2001 by Craig Hollabaugh # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Library General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at your # option) any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License # for more details. # # You should have received a copy of the GNU Library General Public License # along with this program; if not, write to the Free Software Foundation, # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # umask 022 SRCFILELOC=/root/cross BUILDLOC=$SRCFILELOC/builds case "$1" in "ppc" ) ARCH=powerpc TARGET=powerpc-linux MVRPMLOC=ftp://ftp.mvista.com/pub/Journeyman/cd2/ppc_8xx/apps/ #MVRPMLOC=http://www.embeddedlinuxinterfacing.com/ftp.mvista.com/pub/ Journeyman/cd2/ |
Top |