Creating the root Filesystem

   


Creating the root Filesystem

The Project Trailblazer engineers' decision to use the MontaVista compiled versions of the binary, library, and configuration files that are required in order for the kernel to execute init and bash was just the beginning. Many Linux programs aren't distributed singly; rather, they're grouped by functionality and distributed as a package. For example, the ls program doesn't exist as the ls package, nor does the ls source code exist on its own. The GNU developers bundled ls and other file utilities into the fileutils package, which contains chgrp, chmod, chown, cp, dd, df, dir, dircolors, du, install, ln, ls, mkdir, mkfifo, mknod, mv, rm, rmdir, touch, vdir, and sync. If you want only the ls program, you have to extract it from the fileutils package.

You should extract files from packages into a temporary directory. After all the packages are extracted, the required binaries from Table 4.1 should be copied from the temporary directory to a new root filesystem directory. Linux distribution packages, whether they're Red Hat Package Management (RPMs2) files or Debian Package Management (debs3) files, contain extra files, such as man pages, that may not have any application in the new root filesystem. These extra files just take up space. When you build the root filesystem, the contents of a package are extracted to a temporary directory and then you can copy required files to the new root filesystem directory. Later, this new root filesystem directory can be used to create the actual root filesystem that the target systems will mount.

Deciding Which Package to Use

The engineers used the Debian Web site (www.debian.org) to determine what packages contained the programs the new root filesystem requires. They searched the Debian package section (www.debian.org/distrib/packages) for the program they wanted, using the "search on descriptions" option. For example, they found that the ls program is contained in the fileutils package. If they couldn't determine which package to use for a program, they explored the MontaVista Journeyman FTP site (ftp.mvista.com) to find it. Table 4.2 shows the engineers' list of files from Table 4.1 and the packages in which these programs are contained.

Table 4.2. Packages Required for the Target root Filesystem
MontaVista Journeyman Package File
netbase /etc/protocols
 /etc/services
bash /bin/bash
textutils /bin/cat
shellutils /bin/echo
fileutils /bin/ls
 /bin/df
 /bin/chmod
 /bin/touch
 /bin/rm
mount /bin/mount
 /bin/umount
procps /bin/ps
 /bin/kill
 /lib/libproc.so.2.0.7
netkit-ping /bin/ping
sysvint /sbin/init
net-tools /sbin/ifconfig
 /sbin/route
glibc-2.2.3 /lib/ld-2.2.3.so
 /lib/ld.so.1
 /lib/libc-2.2.3.so
 /lib/libc.so.6
 /lib/libutil-2.2.3.so
 /lib/libutil.so.1
 /lib/libdl-2.2.3.so
 /lib/libdl.so.2
 /lib/libnss_dns-2.2.3.so
 /lib/libnss_dns.so.2
 /lib/libnss_files-2.2.3.so
 /lib/libnss_files.so.2
 /lib/libresolv-2.2.3.so
 /lib/libresolv.so.2
 /lib/libpthread-0.9.so
 /lib/libpthread.so.0
 /lib/libm-2.2.3.so
 /lib/libm.so.6
 /lib/librt-2.2.3.so
 /lib/librt.so.1
libncurses /lib/libncurses.so.5
 /lib/libncurses.so.5.2
libstdc++ /lib/libstdc++-3-libc6.1-2-2.10.0.so
 /lib/libstdc++-libc6.1-2.so.3
netkit-telnet-client /usr/bin/telnet
gdbserver-5.0 /usr/bin/gdbserver

The Process for Building the root Filesystem

The procedure for building a root filesystem consists of the two steps: Edit the buildrootfilesystem script PACKAGES line, incorporating the package information from Table 4.2, and then execute the buildrootfilesystem script. The buildrootfilesystem script performs the following operations:

  1. It determines what packages to download.

  2. It creates the build and new target root filesystem directories.

  3. It downloads the packages defined in the PACKAGES script line.

  4. It extracts the packages' contents into a temporary directory.

  5. It copies the required programs (see Table 4.2) from the temporary directory to the new target root filesystem directory.

    TIP

    Do you want the buildrootfilesystem script to add another program to your root filesystem? If so, determine which package contains the program you want. Edit the buildrootfilesystem script, add the package name to the PACKAGES line, add the program name to the script's step 5 section and re-run the script.

  6. It strips the required programs of their debugging information. (Many programs are compiled with the -g debugging flag, which creates executables that have larger file sizes. You're probably not going to debug these particular executables, so you can strip the debugging information to get more file space.)

  7. It creates the extra configuration files, such as inittab and rcS.

  8. It creates devices in the /dev directory.

  9. It prepares the new root filesystem for operation on the target board.

Running buildrootfilesystem

buildrootfilesystem simplifies the creation of the root filesystem for the ARM, PowerPC, and i386 target boards. This script downloads the current versions of packages, extracts their contents, copies required programs, strips these programs of their debugging information, creates configuration files, creates devices, and prepares the root filesystem for target board operation. Before you run the buildrootfilesystem script, you need to add two additional packages to the tbdev1 workstation that you built in Chapter 3: lynx and alien. The buildrootfilesystem script uses lynx in dump mode to get the contents of an FTP directory. alien converts packages from one format to another (for example, it converts an RPM file to a compressed tar archive). You can start building the root filesystem by installing lynx and alien and then downloading the buildrootfilesystem script from the Web site. On tbdev1, log in as root and execute these commands:

 root@tbdev1[501]: apt-get -y install lynx root@tbdev1[502]: apt-get -y install alien root@tbdev1[503]: cd /root/cross root@tbdev1[504]: wget http://www.embeddedlinuxinterfacing.com/chapters/04/  graphics/ccc.gifbuildrootfilesystem/buildrootfilesystem root@tbdev1[505]: chmod 755 buildrootfilesystem 

The following sections describe the buildrootfilesystem script steps.

Step 1: Determine What Packages to Download

The Project Trailblazer engineers determined what packages are required for the root filesystem. They edited the PACKAGES line in the buildrootfilesystem script. Step 1 sets the PACKAGES variable:

 PACKAGES="glibc-2 bash procps textutils fileutils shellutils sysvinit netbase libncurses  graphics/ccc.giflibstdc mount telnet-client net-tools ping gdbserver" 
Step 2: Create the Build and New Target root Filesystem Directories

Step 2 of the buildrootfilesystem script creates the build and the new target root filesystem directories. You can use the same build directory from Chapter 2: /root/cross/build. A separate directory, one per architecture within /root/cross/build, holds the downloaded RPMs. buildrootfilesystem then creates a separate root filesystem directory in /tftpboot for each architecture in the case of Project Trailblazer, /tftpboot/powerpc-rootfs, /tfpboot/arm-rootfs, and /tftpboot/i386-rootfs. In Chapter 5, "Debugging," targets use the /tftpboot directories to mount their root filesystems using Network File System (NFS).

Within the root filesystem, buildrootfilesystem creates these directories: dev, etc, etc/init.d, bin, sbin, lib, usr, usr/bin, proc, and tmp.

Step 3: Download the Packages

Step 3 of the buildrootfilesystem script uses lynx to download the current list of files at the MontaVista FTP site. From this list, buildrootfilesystem scans PACKAGES and downloads the package RPM file by using wget.

Step 4: Extract the Packages' Contents into a Temporary Directory

The MontaVista binaries are contained within an RPM file. You don't want to install the entire RPM file contents; you just want to extract the contents to a temporary directory. The program alien converts the RPM into a compressed tar archive (called a tarball). Using tar decompresses the archive and extracts the contents into a temporary directory. This seems like a lot of work, but this extraction instead of installation into a temporary directory will make step 5 easier.

Step 5: Copy the Required Programs to the New Target root Filesystem Directory

The tar command from step 4 extracts the MontaVista binaries in the temporary directory, for example /root/cross/builds/powerpc-rootrpms/opt/hardhat/devkit/ppc/8xx/target. Step 5 of the buildrootfilesystem script changes into that directory, and then copies the required binaries from lib, usr, sbin, bin, and usr/bin to the new root filesystem directory.

In step 5, the script also creates helloworld.c in the /tmp directory and then compiles it. We'll use this cross-compiled version of helloworld to verify PBR-6.

Step 6: Strip the Required Programs of Their Debugging Information

Step 6 of the buildrootfilesystem script uses the cross-compiled version of strip to remove the debugging symbols from libraries and other binary executables within the new target root filesystem. How can you tell if a binary contains debugging symbols? You use the file command, as in the following example:

 root@tbdev1[515]: cd /root/cross/builds/powerpc-rootrpms/ root@tbdev1[516]: cd opt/hardhat/devkit/ppc/8xx/target/ root@tbdev1[517]: file bin/bash bin/bash: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1, dynamically linked  graphics/ccc.gif(uses shared libs), not stripped root@tbdev1[518]: ls -l bin/bash -rwxr-xr-x    1 5003     510        702350 May 23 15:16 bin/bash* root@tbdev1[519]: powerpc-linux-strip -s -g bin/bash root@tbdev1[520]: file bin/bash bin/bash: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1, dynamically linked  graphics/ccc.gif(uses shared libs), stripped root@tbdev1[521]: ls -l bin/bash -rwxr-xr-x    1 5003     510        605480 Aug 23 15:08 bin/bash* 
Step 7: Create Extra Configuration Files

Step 7 of the buildrootfilesystem script creates the following files:

File Description
/etc/services Provides a mapping between textual names for Internet services and their underlying assigned port numbers and protocol types
/etc/protocols Describes Internet protocols within the TCP/IP subsystem
/etc/fstab Provides information about various file systems used by mount
/etc/inittab Describes processes that are started at bootup and during normal operation
/etc/init.d/rcS Functions as a startup script that is run by init
/etc/init.d/umountfs Functions as a shutdown script that is run by init to unmount filesystems
/etc/resolv.conf Provides configuration information to the DNS resolver

Step 8: Create the Devices in the /dev Directory

Step 8 of the buildrootfilesystem script creates the tty, tty0, ttyS0, console, null, and ram devices in the /dev directory. These are the minimum devices needed for Linux to run.

Step 9: Prepare the root Filesystem for Operation on the Target Board

When step 8 completes, the new target root filesystem, located in /tftpboot /powerpc-rootfs, is almost ready for use. Step 9 of the buildrootfilesystem script prepares the root filesystem for the target board. The ARM and PowerPC target boards in field operation will extract the contents of their root filesystem into a RAM disk. The i386 platforms won't use a RAM disk; instead, they will use their flash memory as an IDE hard disk. During debugging in Chapter 5, this root filesystem won't exist as a RAM disk or hard disk. The platforms will mount their root filesystem over the Ethernet network via NFS, which makes remote debugging of code more efficient.

In summary, the preparation of the root filesystem is dependent on the field application and target board architecture. The specific preparations for Project Trailblazer are as follows:

  • A. Field ARM and PowerPC target boards require a root filesystem for RAM disk use.

  • B. Field i386 target boards require the root filesystem to exist on their Flash IDE disk drives.

  • C. For debugging, the root filesystem will be mounted over the network, using NFS.

Each preparation requires different procedures, as described in the following sections.

Step 9, Preparation A: The root Filesystem on a RAM Disk

If it is configured with RAM disk support, the kernel contains code to create a disk drive in RAM memory, extract the contents of this RAM disk from another location, and then mount this RAM disk as its root filesystem. This common procedure allows embedded system operation without a hard disk. Keep in mind that the RAM disk exists only until the power cycles or the machine reboots. The contents of the RAM disk are not typically stored across reboots. (Project Trailblazer accepts this limitation because no field unit will store information locally.)

To prepare a RAM disk, the buildrootfilesystem script implements these steps:

  1. It creates a file, called ramrootfs, that is the same size as the final RAM disk.

  2. It fills ramrootfs with zeros.

  3. It makes a filesystem in ramrootfs.

  4. It mounts ramrootfs using a loopback device.

  5. It copies the contents of the target root filesystem directory to ramrootfs.

  6. It unmounts ramrootfs.

  7. It compresses ramrootfs.

Step 9 of the buildrootfilesystem script contains the commands to create, fill, and compress ramrootfs. See the section "Booting the Embedded Planet RPX-CLLF," later in this chapter for specific instructions on getting the PowerPC board booted using ramrootfs. See the section "Booting the Brightstar Engineering MediaEngine," later in this chapter, for specific instructions to boot the ARM board.

Step 9, Preparation B: The root Filesystem on a Flash IDE Drive

The buildrootfilesystem script can completely configure an IDE drive to boot an i386 platform. With a partitioned drive, either hard disk or Flash disk, located as the master on tbdev1's secondary IDE controller (that is, /dev/hdc1), step 9 in the script creates additional devices, creates lilo and mount configuration files, copies the root filesystem to the drive, and executes lilo and installs lilo in the master boot record (MBR) of the second drive. When step 9 completes, you can place this second drive on the primary IDE controller, and Linux will boot from it. See the section "Booting i386 Platforms," later in this chapter for specific instructions to boot the i386 boards.

TIP

buildrootfilesystem gives you the option to erase all the files in /dev/hdc1 to effectively make a clean minimum root filesystem. Make sure that you have your disk drives connected properly before you erase all the files.


Step 9, Preparation C: The root Filesystem for NFS Mounting

Chapter 5 addresses mounting the target root filesystem using NFS. See that chapter for more information.


       
    Top


    Embedded LinuxR. Hardware, Software, and Interfacing
    Embedded LinuxR. Hardware, Software, and Interfacing
    ISBN: N/A
    EAN: N/A
    Year: 2001
    Pages: 103

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net