This commit is contained in:
gferg 2003-03-31 22:50:52 +00:00
parent a3ff14e302
commit 417b405209
13 changed files with 3532 additions and 0 deletions

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://docbook.org/xml/4.2/docbookx.dtd" [
<!ENTITY legal SYSTEM "legal.xml">
<!ENTITY intro SYSTEM "intro.xml">
<!ENTITY initiation SYSTEM "initiation.xml">
<!ENTITY phase1 SYSTEM "phase1.xml">
<!ENTITY phase2 SYSTEM "phase2.xml">
<!ENTITY phase3 SYSTEM "phase3.xml">
<!ENTITY phase4 SYSTEM "phase4.xml">
<!ENTITY phase5 SYSTEM "phase5.xml">
<!ENTITY phase6 SYSTEM "phase6.xml">
<!ENTITY phase7 SYSTEM "phase7.xml">
<!ENTITY wrap-up SYSTEM "wrap-up.xml">
<!ENTITY appendix-a SYSTEM "appendix-a.xml">
]>
<book>
<title>Pocket Linux Guide</title>
<bookinfo>
<author>
<firstname>David</firstname>
<surname>Horton</surname>
<affiliation>
<address>
<email>dhorton@megsinet.net</email>
</address>
</affiliation>
</author>
<revhistory>
<revision>
<revnumber>1.0</revnumber>
<date>2003-02-17</date>
<authorinitials>DH</authorinitials>
<revremark>Initial Release, reviewed by LDP.</revremark>
</revision>
<revision>
<revnumber>0.4</revnumber>
<date>2003-01-15</date>
<authorinitials>DH</authorinitials>
<revremark>Added Project Initiation and Wrap-up sections.</revremark>
</revision>
<revision>
<revnumber>0.3</revnumber>
<date>2003-01-08</date>
<authorinitials>DH</authorinitials>
<revremark>Revised for readability.</revremark>
</revision>
<revision>
<revnumber>0.2</revnumber>
<date>2002-11-29</date>
<authorinitials>DH</authorinitials>
<revremark>Converted to Docbook XML from original HTML.</revremark>
</revision>
<revision>
<revnumber>0.1</revnumber>
<date>2002-11-15</date>
<authorinitials>DH</authorinitials>
<revremark>First draft proposed, written in HTML.</revremark>
</revision>
</revhistory>
<abstract>
<para>
The Pocket Linux Guide is for anyone interested in learning the techniques of building a GNU/Linux system from source code. The guide is structured as a project that builds a small diskette-based GNU/Linux system called Pocket Linux. Each chapter explores a small piece of the overall system explaining how it works, why it is needed and how to build it. After completing the Pocket Linux project, readers should possess an enhanced knowledge of what makes GNU/Linux systems work as well as the confidence to explore larger, more complex source-code-only projects.
</para>
</abstract>
</bookinfo>
&legal;
&intro;
&initiation;
&phase1;
&phase2;
&phase3;
&phase4;
&phase5;
&phase6;
&phase7;
&wrap-up;
&appendix-a;
</book>

View File

@ -0,0 +1,601 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<appendix id="a">
<title>Hosting Applications</title>
<sect1>
<title>Analysis</title>
<para>
An operating system by itself is not much fun. What makes an OS great is the applications that can be run on top of it. Unfortunately, the Pocket Distribution currently does not have much room for anything other than system programs. Still, it would be nice to expand the system just enough to host some cool applications. Obviously a full-blown X-Windows GUI is out of the question, but running a small console based program should be within our reach.
</para>
<para>
Rather than doing a typical "hello world" program as an example, application hosting will be demonstrated using a console based audio player called mp3blaster. Building mp3blaster offers more technical challenge than "hello world" and the finished product should be a lot more fun. However, it should not be construed that a console based jukebox is the only application for Pocket Linux. On the contrary, after completing this phase the reader should have the knowledge and tools to build almost any console based program he or she desires.
</para>
<para>
So what will it take to turn a pocket sized GNU/Linux system into a pocket sized mp3 player? A few things are listed below.
</para>
<itemizedlist>
<listitem><para>Add support for audio hardware.</para></listitem>
<listitem><para>Create space for the mp3blaster program.</para></listitem>
<listitem><para>Provide a convenient way to access audio files.</para></listitem>
</itemizedlist>
</sect1>
<sect1>
<title>Design</title>
<sect2>
<title>Support for audio hardware</title>
<para>
There is a vast proliferation of audio hardware on the market and each sound card has its own particular configuration. For details on how to set up a particular sound card we can turn to the Sound-HOWTO available from The Linux Documentation Project at <ulink url="http://www.tldp.org">http://www.tldp.org</ulink>. In a broader sense, however, we can treat a sound card like any other piece of new hardware. To add new hardware to a GNU/Linux system we will need configure the kernel to recognize it and configure /dev files on the root disk to access it.
</para>
<sect3>
<title>Kernel support for audio</title>
<para>
In order to support sound cards, a new kernel will have to be built. It is very important that audio hardware support be configured as built-in, because the Pocket Distribution is not set up to handle kernel modules.
</para>
</sect3>
<sect3>
<title>Root disk support for audio</title>
<para>
Searching devices.txt for the keyword "sound" will list quite a few possible audio devices, but usually only /dev/dsp and /dev/mixer are required to get sound from a PC. These two files control the digital audio output and mixer controls, respectively.
</para>
</sect3>
</sect2>
<sect2>
<title>Creating space for the program</title>
<para>
Probably the easiest way to create more space for the mp3blaster program is to mount an additional storage device. There are several choices for mount points. So far /usr, /home and /opt are all empty directories and any one of them could be used to mount a floppy, CD-ROM or additional compressed ramdisk image. The /usr directory is a logical choice for a place to put an application, but what about the choice of media? Mp3blaster and its required libraries are too big to fit on a 1.44M floppy and burning a CD-ROM seems like a lot of work for one little program. So given these constraints, the best choice would be to put the program on a compressed floppy.
</para>
<sect3>
<title>Mounting additional compressed floppies</title>
<para>
Mounting CD's and uncompressed diskettes is easy, but what about loading compressed images from floppy into ramdisk? It will have to be done manually, because automatic mounting of compressed floppies only works for the root diskette. And using "mount /dev/fd0" will not work because there is no filesystem on the diskette, there are only the contents of a gzip file. The actual filesystem is contained inside the gzip file. So how can we mount the filesystem buried beneath the gzip file? This puzzle can be solved by examining at the steps used to create the familiar compressed root disk floppy.
</para>
<orderedlist>
<listitem><para>A ramdisk is created, mounted and filled with files.</para></listitem>
<listitem><para>The ramdisk device is dismounted.</para></listitem>
<listitem><para>The contents of the ramdisk are dumped to an image file using "dd".</para></listitem>
<listitem><para>The image file is compressed with "gzip".</para></listitem>
<listitem><para>The compressed image file is written to floppy with "dd".</para></listitem>
</orderedlist>
<para>
If that is how the compressed image makes its way from ramdisk to compressed floppy, then going from compressed floppy to ramdisk should be as simple as running through the steps in reverse.
</para>
<orderedlist>
<listitem><para>The compressed image file is read from floppy with "dd".</para></listitem>
<listitem><para>The image file is uncompressed with "gunzip".</para></listitem>
<listitem><para>The contents of the image file are dumped into ramdisk using "dd".</para></listitem>
<listitem><para>The ramdisk device is mounted.</para></listitem>
<listitem><para>The files are available.</para></listitem>
</orderedlist>
<para>
We can cut out the intermediate image file by using a pipe to combine "dd" and "gunzip" like this: "<computeroutput>dd if=/dev/fd0 | gunzip -cq > /dev/ram1</computeroutput>". Now the compressed floppy goes straight into ramdisk, decompressing on the fly.
</para>
</sect3>
<sect3>
<title>Root disk support for additional ramdisks</title>
<para>
We already have kernel support for ramdisks, because we are using a compressed root disk, but we will need to create more ramdisks in /dev. Typically the kernel supports eight ramdisks on /dev/ram0 through /dev/ram7 with ram0 being used for the rootdisk. The devices.txt file included in the Linux source code documentation (/usr/src/linux/Documentation/devices.txt) will be helpful for matching devices to their major and minor numbers.
</para>
</sect3>
</sect2>
<sect2>
<title>Accessing audio files</title>
<para>
The sample mp3 file that we will be using in our example is small enough to fit on an uncompressed floppy disk so that there is no need to burn a CD. However, serious music lovers may want to have the capability to mount a custom CD-ROM full of tunes and that option will require support for additional hardware.
</para>
<sect3>
<title>CD-ROM hardware support</title>
<para>
Most modern CD-ROM drives will use IDE devices like /dev/hdc or /dev/hdd. To support these CD-ROM drives we will have to configure IDE support in the kernel and create the appropriate device files on the root disk.
</para>
</sect3>
<sect3>
<title>CD-ROM filesystem support</title>
<para>
CD-ROM's have different filesystems than hard disks and floppies. Most CD burning applications use a filesystem called ISO-9660 and have the capability to support joliet or rockridge extensions. We will have to include support for these filesystems in the kernel in order to mount CD-ROM's.
</para>
</sect3>
</sect2>
<sect2>
<title>Other required files</title>
<para>
We will want to have all of the required libraries and other supporting files available as part of the compressed /usr image so that mp3blaster can run correctly. The familiar "ldd" command can be used to determine which libraries mp3blaster requires. Any additional libraries can be placed in /usr/lib. Even though some of the libraries may appear in /lib on the development system, they can still go in /usr/lib on the Pocket Linux system. The linker is smart enough to look in both places when loading libraries.
</para>
<para>
Because mp3blaster uses the curses (or ncurses) screen control library there is one additional file we need. The curses library needs to know the characteristics of the terminal it is controlling and it gets that information from the terminfo database. The terminfo database consists of all the files under the /usr/share/terminfo directory and is very large compared to our available disk space. But, since Pocket Linux only supports the PC console, we only have one terminal type to worry about and therefore need only one file. The piece of the terminfo database we need is the file /usr/share/terminfo/l/linux, because we are using a "Linux" terminal. (For more information about the subject of curses, see John Strang's book entitled "Programming with Curses" available from O'Reilly publishing at <ulink url="http://www.oreilly.com">http://www.oreilly.com</ulink>.)
</para>
</sect2>
<sect2>
<title>Summary of tasks</title>
<para>
Between sound cards, ramdisks, CD-ROM's and terminfo there is quite a bit to keep track of. So let's take a moment to organize and summarize the tasks necessary to make the pocket jukebox a reality.
</para>
<itemizedlist>
<listitem>
<para>
Create a new kernel disk that includes built-in support for audio hardware, IDE devices and CD-ROM filesystems.
</para>
</listitem>
<listitem>
<para>
Create the appropriate /dev files on the root disk to support audio hardware, additional ramdisks and IDE CD-ROM's.
</para>
</listitem>
<listitem>
<para>
Create a startup script to load a compressed image from floppy into a ramdisk and mount the ramdisk on /usr.
</para>
</listitem>
<listitem>
<para>
Create a compressed floppy that holds the mp3blaster program, its required libraries and terminfo files.
</para>
</listitem>
</itemizedlist>
</sect2>
</sect1>
<sect1>
<title>Construction</title>
<sect2>
<title>Create an enhanced boot disk</title>
<sect3>
<title>Build a new kernel</title>
<para>
<programlisting>bash# cd /usr/src/linux
bash# make menuconfig</programlisting>
</para>
<para>Be sure to configure support for the following:</para>
<itemizedlist>
<listitem><para>386 processor</para></listitem>
<listitem><para>floppy disk</para></listitem>
<listitem><para>RAM disk</para></listitem>
<listitem><para>Text console</para></listitem>
<listitem><para>Audio hardware</para></listitem>
<listitem><para>CD-ROM hardware</para></listitem>
<listitem><para>ISO-9660 and Joliet filesystems</para></listitem>
</itemizedlist>
<para>
<programlisting>bash# make dep
bash# make clean
bash# make bzImage</programlisting>
</para>
</sect3>
<sect3>
<title>Copy the kernel to diskette</title>
<para>
Place the boot disk in drive fd0
</para>
<para>
<programlisting>bash# cp /usr/src/linux/arch/i386/boot/bzImage /mnt/boot/vmlinuz
bash# mount /dev/fd0 /mnt</programlisting>
</para>
</sect3>
<sect3>
<title>Install the LILO boot loader</title>
<para>
<programlisting>bash# lilo -r /mnt</programlisting>
</para>
</sect3>
<sect3>
<title>Unmount the boot disk</title>
<para>
<programlisting>bash# cd /
bash# umount /mnt
bash# sync</programlisting>
</para>
</sect3>
</sect2>
<sect2>
<title>Create an enhanced root disk</title>
<sect3>
<title>Create additional device files</title>
<sect4>
<title>IDE CD-ROM</title>
<para>
<programlisting>bash# mknod -m640 ~/staging/dev/hdc b 22 0
bash# mknod -m640 ~/staging/dev/hdd b 22 64</programlisting>
</para>
<para>
Optionally create additional IDE devices.
</para>
</sect4>
<sect4>
<title>Ramdisk</title>
<para>
<programlisting>bash# mknod -m 640 ~/staging/dev/ram1 b 1 1
bash# mknod -m 640 ~/staging/dev/ram2 b 1 2
bash# mknod -m 640 ~/staging/dev/ram3 b 1 3
bash# mknod -m 640 ~/staging/dev/ram4 b 1 4
bash# mknod -m 640 ~/staging/dev/ram5 b 1 5
bash# mknod -m 640 ~/staging/dev/ram6 b 1 6
bash# mknod -m 640 ~/staging/dev/ram7 b 1 7</programlisting>
</para>
</sect4>
<sect4>
<title>Audio</title>
<para>
<programlisting>bash# mknod -m664 ~/staging/dev/dsp c 14 3
bash# mknod -m664 ~/staging/dev/mixer c 14 0</programlisting>
</para>
</sect4>
</sect3>
<sect3>
<title>Write a startup script to mount a compressed floppy</title>
<para>
Use a text editor to create the following script and save it as ~/staging/etc/init.d/usr_image
</para>
<para>
<programlisting>#!/bin/sh
#
# usr_image - load compressed images from floppy into ramdisk and
# mount on /usr.
#
echo -n "Is there a compressed diskette to load for /usr [y/N]? "
read REPLY
if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]; then
echo -n "Please insert the /usr floppy into fd0 and press &lt;ENTER&gt;."
read REPLY
echo "Clearing /dev/ram1."
dd if=/dev/zero of=/dev/ram1 bs=1k count=4096
echo "Loading compressed image from /dev/fd0 into /dev/ram1..."
(dd if=/dev/fd0 bs=1k | gunzip -cq) >/dev/ram1 2>/dev/null
fsck -fp /dev/ram1
if [ $(($?)) -gt $((1)) ]; then
echo "Filesystem errors on /dev/ram1! Manual intervention required."
else
echo "Mounting /usr."
mount /dev/ram1 /usr
fi
fi
#
# end of usr_image</programlisting>
</para>
<para>
Configure the script to run right after root is mounted.
</para>
<para>
<programlisting>bash# ln -s ../init.d/usr_image ~/staging/etc/rcS.d/S21usr_image</programlisting>
</para>
</sect3>
<sect3>
<title>Create a compressed root disk</title>
<para>
<programlisting>bash# cd /
bash# dd if=/dev/zero of=/dev/ram7 bs=1k count=4096
bash# mke2fs -m0 /dev/ram7
bash# mount /dev/ram7 /mnt
bash# cp -dpR ~/staging/* /mnt
bash# umount /dev/ram7
bash# dd if=/dev/ram7 of=~/phase8-image bs=1k
bash# gzip -9 ~/phase8-image</programlisting>
</para>
<para>
Insert the diskette labled "root disk" into drive fd0.
</para>
<para>
<programlisting>bash# dd if=~/phase8-image.gz of=/dev/fd0 bs=1k</programlisting>
</para>
</sect3>
<sect3>
<title>Unmount the root disk</title>
<para>
<programlisting>bash# cd /
bash# umount /mnt
bash# sync</programlisting>
</para>
</sect3>
</sect2>
<sect2>
<title>Create a compressed /usr disk for mp3blaster</title>
<para>
The compressed /usr diskette will be created in using the same process that is used to create the compressed root disk. We will copy files to a staging area, copy the staging area to ramdisk, compress the ramdisk and write it to diskette.
</para>
<sect3>
<title>Create a staging area</title>
<para>
<programlisting>bash# mkdir ~/usr-staging
bash# cd ~/usr-staging
bash# mkdir bin lib
bash# mkdir -p share/termcap/l</programlisting>
</para>
</sect3>
<sect3>
<title>Install the mp3blaster program</title>
<para>
Download the latest version of mp3blaster source code from its home at <ulink url="http://www.stack.nl/~brama/mp3blaster">http://www.stack.nl/~brama/mp3blaster</ulink>.
</para>
<para>
<programlisting>bash# cd ~/usr/src/mp3blaster-3.13
bash# ./configure
bash# make
bash# cp src/mp3blaster ~/usr-staging/bin</programlisting>
</para>
</sect3>
<sect3>
<title>Copy additional libraries and terminfo</title>
<para>
Note: This is an example from the author's development system. Different systems may yield slightly different results.
</para>
<para>
<programlisting>bash# cd ~/usr-staging/lib
bash# ldd ~/usr-staging/bin/mp3blaster
bash# cp /usr/lib/ncurses.so.5.0 .
bash# cp /usr/lib/stdc++.so.3 .
bash# cp /lib/libm.so.6 .
bash# cp /usr/lib/libgcc_s.so.1 .
bash# cd ~/usr/staging/share/terminfo/l
bash# cp /usr/share/terminfo/l/linux .</programlisting>
</para>
</sect3>
<sect3>
<title>Make a compressed image and copy it to diskette</title>
<para>
<programlisting>bash# cd /
bash# dd if=/dev/zero of=/dev/ram7 bs=1k count=4096
bash# mke2fs -m0 /dev/ram7
bash# mount /dev/ram7 /mnt
bash# cp -dpR ~/usr-staging/* /mnt
bash# umount /dev/ram7
bash# dd if=/dev/ram7 of=~/mp3blaster-image bs=1k
bash# gzip -9 ~/mp3blaster-image</programlisting>
</para>
<para>
Insert the diskette labled "mp3blaster" into drive fd0.
</para>
<para>
<programlisting>bash# dd if=~/mp3blaster-image.gz of=/dev/fd0 bs=1k</programlisting>
</para>
</sect3>
</sect2>
<sect2>
<title>Create a data diskette for testing</title>
<para>
Go to the internet site <ulink url="http://www.paul.sladen.org">http://www.paul.sladen.org</ulink> and download the mp3 file of Linus Torvalds pronouncing "Linux." The direct link is: <ulink url="http://www.paul.sladen.org/pronunciation/torvalds-says-linux.mp3">http://www.paul.sladen.org/pronunciation/torvalds-says-linux.mp3</ulink>. Create a Second Extended (ext2) filesystem on a floppy and copy the mp3 file onto the diskette.
</para>
</sect2>
</sect1>
<sect1>
<title>Implementation</title>
<sect2>
<title>System Startup</title>
<orderedlist>
<listitem><para>Boot from the kernel diskette.</para></listitem>
<listitem><para>Insert the root floppy when prompted.</para></listitem>
<listitem><para>When prompted for a /usr diskette, say 'Y'.</para></listitem>
<listitem><para>Insert the mp3blaster diskette and press <keycap>Enter</keycap>.</para></listitem>
</orderedlist>
</sect2>
<sect2>
<title>Verify that the /usr diskette loaded properly</title>
<para>
<programlisting>bash# mount
bash# ls -lR /usr</programlisting>
</para>
</sect2>
<sect2>
<title>Check the audio device initialization</title>
<para>
<programlisting>bash# dmesg | more</programlisting>
</para>
<para>
If everything worked there should be a line or two indicating that the kernel found the audio hardware. The example below shows how the kernel might report a Yamaha integrated sound system.
</para>
<para>
<screen>ymfpci: YMF740C at 0xf4000000 IRQ 10
ac97_codec: AC97 Audio codec, id: 0x4144:0x5303 (Analog Devices AD1819)
</screen>
</para>
</sect2>
<sect2>
<title>Test audio output</title>
<para>
<programlisting>bash# echo "10101010" > /dev/dsp</programlisting>
</para>
<para>
A short burst of static coming from the PC speakers indicates that sound is working.
</para>
</sect2>
<sect2>
<title>Play a sample file</title>
<para>
<programlisting>mount /dev/fd0 /home
bash# /usr/bin/mp3blaster</programlisting>
</para>
<para>
Use mp3blaster to select and play the file /home/torvalds-says-linux.mp3. Use mp3blaster's mixer controls to adjust the volume as needed.
</para>
</sect2>
<sect2>
<title>System shutdown</title>
<para>
Bring the system down gracefully with the "shutdown" command.
</para>
</sect2>
</sect1>
</appendix>

View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<chapter id="initiation">
<title>Project Initiation</title>
<sect1>
<title>A Brief History of GNU/Linux</title>
<para>In the early 90&#39;s GNU/Linux systems consisted of little more
than a beta-quality Linux kernel and a small collection of software ported
from the GNU project. It was a true hacker&#39;s operating system. There
were no CD-ROM&#39;s or GUI installation tools; everything had to be
compiled and configured by the end user. Being a Linux Expert meant
knowing your system inside and out.</para>
<para>Toward the middle of the decade several GNU/Linux distributions
began appearing. One of the first was Slackware (<ulink
url="http://www.slackware.org">http://www.slackware.org</ulink>) in 1993
and since then there have been many others. Even though there are many
&#34;flavors&#34; of Linux today, the main purpose of the distribution
remains the same. The distribution automates many of the tasks involved in
GNU/Linux installation and configuration taking the burden off of the
system administrator. Being a Linux Expert now means knowing which button
to click in the GUI administration tool.</para>
<para>Recently there has been a yearn for a return to the &#34;good old
days&#34; of Linux when men were men, sysadmins were hardcore geeks and
everything was compiled from source code. A notable indication of this
movement was the publication of the Linux From Scratch HOWTO version 1.0
by Gerard Beekmans in 1999. Being a Linux Expert once again means knowing
how to do it yourself.</para>
<para>For more historical information, see Ragib Hasan&#39;s
&#34;History of Linux&#34; at <ulink
url="http://ragib.hypermart.net/linux/">http://ragib.hypermart.net/linux/</ulink></para>
</sect1>
<sect1>
<title>The Goal of Pocket Linux</title>
<para>The purpose of Pocket Linux is to support and encourage people who
wish to build a GNU/Linux system from nothing but source code. It is not
intended to be a full featured system, but rather to give the reader a
taste of what is involved in building an operating system from source
code. After completing the Pocket Linux system the reader should have
enough knowledge to confidently build almost any project using only source
code. Given this direction we can put a few constraints on the project.</para>
<itemizedlist>
<listitem>
<para>The main focus should be learning. The project should not just
describe how to do something, it should also describe why it should be
done.</para>
</listitem>
<listitem>
<para>The required time commitment should be minimal and manageable.</para>
</listitem>
<listitem>
<para>The project should not require any investment in additional
hardware or reconfiguration of existing hardware to set up a lab
environment.</para>
</listitem>
<listitem>
<para>Readers should not need to know any programming languages in
order to complete the project.</para>
</listitem>
<listitem>
<para>To remain true to the spirit of GNU/Linux, all software used in
the project should be covered under the GNU/GPL or another, similarly
liberal, open-source license.</para>
</listitem>
</itemizedlist>
</sect1>
<sect1>
<title>Working Within The Constraints</title>
<para>The Pocket Linux project gets its name from the fact that the bulk
of the project fits onto two diskettes making it possible to carry the
entire, working system around in one&#39;s pocket. This has the advantage
of not requiring any additional hardware since any PC can be booted from
the diskettes without disrupting any OS that exists on the hard drive.
Using diskettes also partially addresses the aspect of time commitment,
because the project size and complexity is necessarily limited by the 1.44
Megabyte size of the installation media.</para>
<para>To further reduce the time commitment, the Pocket Linux project is
divided into several phases, each one chapter in length. Each phase builds
only a small piece of the overall project, but at the same time the
conclusion of each chapter results in a self-contained, working system.
This step-by-step approach should allow readers to pace themselves and not
feel the need to rush to see results.</para>
<para>Chapters are further subdivided in to four sections. The first two
sections, analysis and design, focus on the theory of what is to be
accomplished in each phase and why. The last two sections, construction
and implementation, detail the steps needed to do the actual building.
Advanced readers, who may be familiar with the theories laid out in a
particular chapter are encouraged to gloss over the analysis and design
sections in the interest of time. The separation of theory from hands-on
exercises should allow readers of all skill levels to complete the project
without feeling either completely lost or mired in too much detail.</para>
<para>Finally, the Pocket Linux project will strive to use GNU/GPL
software when possible and other open-source licensed software when there
is no GNU/GPL alternative. Also, Pocket Linux will never require any
programming more complex than a BASH shell script.</para>
</sect1>
</chapter>

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<preface id="intro">
<title>Introduction</title>
<sect1>
<title>About Pocket Linux</title>
<para>
The Pocket Linux Guide demonstrates how to build a small console based GNU/Linux system using only source code and a couple of diskettes. It is intended for Linux users who would like to gain a deeper understanding about how their system works beneath the shroud of distribution specific features and tools.
</para>
</sect1>
<sect1>
<title>Prerequisite Skills</title>
<para>
This guide is intended for intermediate to advanced Linux users. It is not intentionally obscure, but certain assumptions about the readers skill level are made. Success with this guide depends in part on being able to perform the following tasks:
</para>
<itemizedlist>
<listitem><para>Use basic shell commands</para></listitem>
<listitem><para>Reference man and info pages</para></listitem>
<listitem><para>Build a custom Linux kernel</para></listitem>
<listitem><para>Compile source code using make and related tools</para></listitem>
</itemizedlist>
</sect1>
<sect1>
<title>Project Format</title>
<para>
The Pocket Linux Guide takes a hands-on approach to learning. The guide is written with each chapter building a piece of an overall project. Chapters are further broken into sections of Analysis, Design, Construction and Implementation. This format is derived from Rapid Application Development (RAD) methodology. Without going into detail about design methodologies, the sections may be summed up as follows.
</para>
<itemizedlist>
<listitem><para>The Analysis section gives a high-level overview of what is to be accomplished in each chapter. It will introduce the tasks that need to be completed and why they are important to the overall system.</para></listitem>
<listitem><para>The Design section defines the source code packages, files and configuration necessary to address the requirements set forth in the Analysis section. Much of the theory of why certain system files exist and what their purpose is can be found here.</para></listitem>
<listitem><para>The Construction section is where all the hands on action takes place. This section goes into detail about building source code and configuring the system files.</para></listitem>
<listitem><para>The Implementation section will test the proper operation of the project at the end of each chapter. Often there are a few shell commands to perform and samples of expected screen outputs are given.</para></listitem>
</itemizedlist>
<para>
Readers interested in learning more about RAD may want to consult a textbook covering systems analysis and design, search Google for the phrase "rapid application development" or visit the following University of California, Davis website on the subject: <ulink url="http://sysdev.ucdavis.edu/WEBADM/document/rad-stages.htm">http://sysdev.ucdavis.edu/WEBADM/document/rad-stages.htm</ulink>.
</para>
</sect1>
<sect1 id="feedback">
<title>Feedback</title>
<para>
Please send comments and constructive criticism to the following email address: <ulink url="mailto:dhorton@megsinet.net"><email>dhorton@megsinet.net</email></ulink>.
</para>
</sect1>
</preface>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<preface id="legal">
<title>Legal Information</title>
<sect1 id="copyright">
<title>Copyright and License</title>
<para>
This document, <emphasis>Pocket Linux Guide</emphasis>, is copyrighted (c) 2003 by <emphasis>David Horton</emphasis>. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is available at <ulink url="http://www.gnu.org/copyleft/fdl.html">http://www.gnu.org/copyleft/fdl.html</ulink>.
</para>
<para>
Linux is a registered trademark of Linus Torvalds.
</para>
</sect1>
<sect1 id="disclaimer">
<title>Disclaimer</title>
<para>
No liability for the contents of this document can be accepted. Use the concepts, examples and information at your own risk. There may be errors and inaccuracies, that could be damaging to your system. Proceed with caution, and although this is highly unlikely, the author(s) do not take any responsibility.
</para>
<para>
All copyrights are held by their by their respective owners, unless specifically noted otherwise. Use of a term in this document should not be regarded as affecting the validity of any trademark or service mark. Naming of particular products or brands should not be seen as endorsements.
</para>
</sect1>
</preface>

View File

@ -0,0 +1,348 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<chapter id="phase1">
<title>A Simple Prototype</title>
<sect1>
<title>Analysis</title>
<para>Since this is the first phase of the project it will be kept very
simple. The goal here is not to create the ultimate GNU/Linux system on
the first try. Instead, we will be building a very minimal, working system
to be used as a building block in subsequent phases of the project.
Keeping this in mind, we can list a few goals for phase one.</para>
<itemizedlist>
<listitem>
<para>Keep it simple to avoid stressing out.</para>
</listitem>
<listitem>
<para>Build something that works for instant gratification.</para>
</listitem>
<listitem>
<para>Make something that it is useful in later phases of the project.</para>
</listitem>
</itemizedlist>
</sect1>
<sect1>
<title>Design</title>
<sect2>
<title>Simplification</title>
<para>Take a moment to skim through the Bootdisk-HOWTO or the
From-PowerUp-to-BASH-Prompt-HOWTO. (<ulink
url="http://www.tldp.org/docs.html#howto">http://www.tldp.org/docs.html#howto</ulink>)
Both of these documents offer an excellent view of what it takes to get
a GNU/Linux system up and running. There is also a lot of information to
digest. Remember that one of our goals is, &#34;keep it simple to avoid
stressing out,&#34; so we want to ignore everything but the absolutely
critical pieces of a boot / root diskset.</para>
<para>Basically it boils down to the following required items:</para>
<itemizedlist>
<listitem>
<para>A boot loader</para>
</listitem>
<listitem>
<para>The Linux kernel</para>
</listitem>
<listitem>
<para>A shell</para>
</listitem>
<listitem>
<para>Some /dev files</para>
</listitem>
</itemizedlist>
<para>We don&#39;t even need an init daemon. The kernel can be told to
run the shell directly by passing it an option through the boot loader.</para>
<para>For easy construction we will build a two-disk boot / root set
rather than trying to get everything onto a single diskette. The boot
loader and kernel will go on the boot disk and the shell will reside on
the root disk. Both disks will need device files to function properly.</para>
</sect2>
<sect2>
<title>Boot Disk</title>
<para>For the boot disk we&#39;ll want to use a kernel that does not
require modules for the hardware we need to access. Mainly, it should
have compiled-in support for the floppy drive, ram disk and a text-based
console. If such a kernel is not available, it will need to be built
from source code using the Kernel-HOWTO as a guide. Once the kernel is
ready we can copy it to a diskette that has been prepared with a
filesystem (a.k.a. formatted). The diskette will need a few /dev files
and a lilo.conf file in order to get LILO installed. The Bootdisk-HOWTO
and the lilo.conf(5) manpage will be helpful in designing the lilo.conf
file.</para>
</sect2>
<sect2>
<title>Root Disk</title>
<para>For the root disk we will need a floppy that has been prepared
with a filesystem. We will also need a BASH shell that is statically
linked so we can avoid the additional complexities of shared libraries.
The configure program in the BASH source code recognizes the
&#34;--enable-static-link&#34; option for this feature. We will also be
using the &#34;--enable-minimal-config&#34; option to keep the BASH
binary down to a manageable size. Additional requirements for the root
disk are a /dev directory and a device file for the console. The console
device is required for BASH to be able to communicate with the keyboard
and video display.</para>
</sect2>
<sect2>
<title>CPU Compatibility</title>
<para>There is one other, less obvious requirement to keep in mind and
that is CPU compatibility. Each generation of CPU features a more
complex architechture than its predecessor. Late generation chips have
additional registers and instructions when compared to an older 486 or
386. So a kernel optimized for a new, fast 6x86 machine will not run on
an older boxes. (See the README file in the Linux kernel source code for
details.) A BASH shell built for a 6x86 will probably not run on an
older processor either. To avoid this problem, we can choose the 386 as
a lowest common denominator CPU and build all the code for that
architecture.</para>
</sect2>
</sect1>
<sect1>
<title>Construction</title>
<para>In this section, we will be building the actual boot disk and root
disk floppies. Lines starting with <prompt>bash#</prompt> indicate a shell
command.</para>
<sect2>
<title>Prepare the boot disk floppy</title>
<para>Insert a blank diskette labeled &#34;boot disk&#34;.</para>
<para><programlisting><prompt>bash#</prompt> mke2fs -m0 /dev/fd0
<prompt>bash#</prompt> mount /dev/fd0 /mnt</programlisting></para>
</sect2>
<sect2>
<title>Build the kernel</title>
<para><programlisting><prompt>bash#</prompt> cd /usr/src/linux
<prompt>bash#</prompt> make menuconfig</programlisting></para>
<para>Be sure to configure support for the following:</para>
<itemizedlist>
<listitem>
<para>386 processor</para>
</listitem>
<listitem>
<para>floppy disk</para>
</listitem>
<listitem>
<para>RAM disk</para>
</listitem>
<listitem>
<para>Text console</para>
</listitem>
</itemizedlist>
<para><programlisting><prompt>bash#</prompt> make dep
<prompt>bash#</prompt> make clean
<prompt>bash#</prompt> make bzImage</programlisting></para>
</sect2>
<sect2>
<title>Copy the kernel to diskette</title>
<para><programlisting><prompt>bash#</prompt> mkdir /mnt/boot
<prompt>bash#</prompt> cp /usr/src/linux/arch/i386/boot/bzImage /mnt/boot/vmlinuz</programlisting></para>
</sect2>
<sect2>
<title>Copy the LILO boot loader</title>
<para><programlisting><prompt>bash#</prompt> cp /boot/boot.b /mnt/boot/boot.b</programlisting></para>
</sect2>
<sect2>
<title>Create device files that LILO needs</title>
<para><programlisting><prompt>bash#</prompt> mkdir /mnt/dev
<prompt>bash#</prompt> cd /mnt/dev
<prompt>bash#</prompt> mknod fd0 b 2 0
<prompt>bash#</prompt> mknod console c 5 1</programlisting></para>
</sect2>
<sect2>
<title>Write a simple lilo.conf</title>
<para><programlisting><prompt>bash#</prompt> mkdir /mnt/etc
<prompt>bash#</prompt> cd /mnt/etc</programlisting></para>
<para>Use an editor like vi, emacs or pico to create the following
<filename>lilo.conf</filename> file:</para>
<para><programlisting># /etc/lilo.conf - boot loader configuration file
#
boot=/dev/fd0
compact
prompt
read-only
vga=normal
image=/boot/vmlinuz
label=bootdisk
append=&#34;load_ramdisk=1 prompt_ramdisk=1&#34;
root=/dev/fd0
#
# end of /etc/lilo.conf</programlisting></para>
</sect2>
<sect2>
<title>Install the LILO boot loader</title>
<para><programlisting><prompt>bash#</prompt> lilo -r /mnt</programlisting></para>
</sect2>
<sect2>
<title>Unmount the boot disk</title>
<para><programlisting><prompt>bash#</prompt> cd /
<prompt>bash#</prompt> umount /mnt
<prompt>bash#</prompt> sync</programlisting></para>
</sect2>
<sect2>
<title>Prepare the root disk floppy</title>
<para>Insert a blank diskette labeled &#34;root disk&#34;.</para>
<para><programlisting><prompt>bash#</prompt> mke2fs -m0 /dev/fd0
<prompt>bash#</prompt> mount /dev/fd0 /mnt</programlisting></para>
</sect2>
<sect2>
<title>Build BASH</title>
<para>Get the bash-2.05 source code package from <ulink
url="ftp://ftp.gnu.org/gnu/bash/">ftp://ftp.gnu.org/gnu/bash/</ulink>
and untar it into the /usr/src directory.</para>
<para><programlisting><prompt>bash#</prompt> cd /usr/src/bash-2.05a
<prompt>bash#</prompt> ./configure --enable-static-link \
--enable-minimal-config --host=i386-pc-linux-gnu
<prompt>bash#</prompt> make
<prompt>bash#</prompt> strip bash</programlisting></para>
</sect2>
<sect2>
<title>Copy BASH to the root disk</title>
<para><programlisting><prompt>bash#</prompt> mkdir /mnt/bin
<prompt>bash#</prompt> cp bash /mnt/bin/bash
<prompt>bash#</prompt> ln -s bash /mnt/bin/sh</programlisting></para>
</sect2>
<sect2>
<title>Create device files that BASH needs</title>
<para><programlisting><prompt>bash#</prompt> mkdir /mnt/dev
<prompt>bash#</prompt> mknod /mnt/dev/console c 5 1</programlisting></para>
</sect2>
<sect2>
<title>Unmount the root disk</title>
<para><programlisting><prompt>bash#</prompt> cd /
<prompt>bash#</prompt> umount /mnt
<prompt>bash#</prompt> sync</programlisting></para>
</sect2>
</sect1>
<sect1>
<title>Implementation</title>
<sect2>
<title>System startup</title>
<para>Follow these steps to boot the system:</para>
<itemizedlist>
<listitem>
<para>Restart the PC with the boot disk in the floppy drive.</para>
</listitem>
<listitem>
<para>When the LILO prompt appears, type &#34;<userinput>bootdisk
init=/bin/sh</userinput>&#34; and press <keycap>Enter</keycap>.</para>
</listitem>
<listitem>
<para>Insert the root disk when prompted.</para>
</listitem>
</itemizedlist>
<para>If all goes well the screen should look something like the example
shown below.</para>
<para><screen>boot: bootdisk init=/bin/sh
Loading bootdisk
Uncompressing Linux... Ok, booting kernel.
..
.. [various kernel messages]
..
VFS: Insert root floppy disk to be loaded into RAM disk and press ENTER
RAMDISK: ext2 filesystem found at block 0
RAMDISK: Loading 1440 blocks [1 disk] into ram disk... done.
VFS: Mounted root (ext2 filesystem) readonly.
Freeing unused kernel memory: 178k freed
# _</screen></para>
</sect2>
<sect2>
<title>Testing what works</title>
<para>Try out a few of BASH&#39;s built-in commands to see if things are
working properly.</para>
<para><programlisting><prompt>bash#</prompt> echo &#34;Hello World&#34;
<prompt>bash#</prompt> cd /
<prompt>bash#</prompt> pwd
<prompt>bash#</prompt> echo *</programlisting></para>
</sect2>
<sect2>
<title>Noting what does not work</title>
<para>Try out a few other familiar commands.</para>
<para><programlisting><prompt>bash#</prompt> ls /var
<prompt>bash#</prompt> mkdir /var/tmp</programlisting></para>
<para>Notice that only commands internal to BASH actually work and that
external commands like &#39;ls&#39; and &#39;mkdir&#39; do not work at
all. This shortcoming is something that can be addressed in a future
phase of the project. For now we should just enjoy the fact that our
prototype boot / root diskset works and that it was not all that hard to
build.</para>
</sect2>
<sect2>
<title>System shutdown</title>
<para>Remove the diskette from fd0 and restart the system using
<keycap>CTRL</keycap>-<keycap>ALT</keycap>-<keycap>DELETE</keycap>.</para>
</sect2>
</sect1>
</chapter>

View File

@ -0,0 +1,202 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<chapter id="phase2">
<title>Saving Space</title>
<sect1>
<title>Analysis</title>
<para>One of the drawbacks in the previous phase of the project was that
the diskset was not all that useful. The only commands that worked were
the ones built into the BASH shell. We could improve our root disk by
installing commands like cat, ls, mv, rm and so on. Unfortunately, we are
short on space. The current root disk has no shared libraries so each
binary would have to be statically linked just like the BASH shell. A lot
of big binaries together with a static shell will rapidly exceed the tiny
1.44M of available disk space. So our main goal in this phase should be to
maximize space savings on the root disk and pave the way for expanded
functionality in the next phase.</para>
</sect1>
<sect1>
<title>Design</title>
<para>Take another look at the Bootdisk-HOWTO and notice how many
utilities can be squeezed onto on 1.44M floppy. There are three things
that make this possible. One is the use of shared libraries. The second is
stripped binaries. And the third is the use of a compressed filesystem. We
can use all of these techniques to save space on our root disk.</para>
<sect2>
<title>Shared Libraries</title>
<para>First, in order to use shared libraries we will need to rebuild
the BASH shell. This time we will configure it without using the
&#34;--enable-static-link&#34; option. Once BASH is rebuilt we need to
figure out which libraries it is linked with and be sure to include them
on the root disk. The &#34;ldd&#34; command makes this job easy. By
typing &#34;ldd bash&#34; on the command-line we can see a list of all
the shared libraries that BASH uses. As long as all these libraries are
copied to the root disk, the new BASH build should work fine.</para>
</sect2>
<sect2>
<title>Stripped Binaries</title>
<para>Next, we should strip any binaries that get copied to the root
disk. The manpage for strip does not give much description of what it
does other than to say, &#34;strip discards all symbols from the object
files.&#34; A vast majority of these symbols are for debugging. While
these debugging symbols are very helpful to programmers working to
improve the code, they do not do much for the average end-user other
than take up more disk space. Since space is at a premium on a floppy
disk, we should definitely strip all of the binaries.</para>
</sect2>
<sect2>
<title>Compressed Root Filesystem</title>
<para>Finally, we can tackle the problem of how to build a compressed
root filesystem. The Bootdisk-HOWTO suggests three ways of constructing
a compressed root filesystem using either a ramdisk, a spare hard drive
partition or a loopback device. This project will concentrate on using
the ramdisk approach. It seems logical that if the root filesystem is
going to be run from a ramdisk, it may as well be built on a ramdisk.
All we have to do is create a second extended filesystem on a ramdisk
device, mount it and copy files to it. (Note: For this to work, we need
to make sure the kernel is configured with ramdisk support and a default
size of 4,096K. If this is not the case we will know right away, because
the filesystem creation and mounting of the ramdisk will fail.) Once the
filesystem is populated with all the files that the root disk needs, we
simply unmount it, compress it and write it out to floppy.</para>
</sect2>
</sect1>
<sect1>
<title>Construction</title>
<para>This section is written using ramdisk seven (/dev/ram7) to build the
root image. There is nothing particularly special about ramdisk seven and
it is possible to use any of the other available ramdisks provided they
are not already in use.</para>
<sect2>
<title>Create a ramdisk</title>
<para><programlisting><prompt>bash#</prompt> dd if=/dev/zero of=/dev/ram7 bs=1k count=4096
<prompt>bash#</prompt> mke2fs -m0 /dev/ram7
<prompt>bash#</prompt> mount /dev/ram7 /mnt</programlisting></para>
</sect2>
<sect2>
<title>Rebuild the BASH shell</title>
<para><programlisting><prompt>bash#</prompt> cd /usr/src/bash-2.05a
<prompt>bash#</prompt> make distclean
<prompt>bash#</prompt> ./configure --enable-minimal-config --host=i386-pc-linux-gnu
<prompt>bash#</prompt> make
<prompt>bash#</prompt> strip bash</programlisting></para>
</sect2>
<sect2>
<title>Determine which libraries are required</title>
<para><programlisting><prompt>bash#</prompt> ldd bash</programlisting></para>
<para>Note the output from the ldd command. It will most likely show
that these library files are required for BASH: <filename>/lib/libdl.so.2</filename>,
<filename>/lib/libc.so.6</filename> &#38; <filename>/lib/ld-linux.so.2</filename></para>
</sect2>
<sect2>
<title>Copy BASH and its libraries to the ramdisk</title>
<para><programlisting><prompt>bash#</prompt> mkdir /mnt/bin
<prompt>bash#</prompt> cp bash /mnt/bin
<prompt>bash#</prompt> ln -s bash /mnt/bin/sh
<prompt>bash#</prompt> mkdir /mnt/lib
<prompt>bash#</prompt> cp /lib/libdl.so.2 /mnt/lib
<prompt>bash#</prompt> cp /lib/libc.so.6 /mnt/lib
<prompt>bash#</prompt> cp /lib/ld-linux.so.2 /mnt/lib</programlisting></para>
</sect2>
<sect2>
<title>Create a console device</title>
<para><programlisting><prompt>bash#</prompt> mkdir /mnt/dev
<prompt>bash#</prompt> mknod /mnt/dev/console c 5 1</programlisting></para>
</sect2>
<sect2>
<title>Compress the ramdisk image</title>
<para><programlisting><prompt>bash#</prompt> umount /dev/ram7
<prompt>bash#</prompt> dd if=/dev/ram7 of=~/phase2-image bs=1k
<prompt>bash#</prompt> gzip -9 ~/phase2-image</programlisting></para>
</sect2>
<sect2>
<title>Copy the compressed image to diskette</title>
<para>Insert the floppy labeled &#34;root disk&#34; into drive fd0.</para>
<para><programlisting><prompt>bash#</prompt> dd if=~/phase2-image.gz of=/dev/fd0 bs=1k</programlisting></para>
</sect2>
</sect1>
<sect1>
<title>Implementation</title>
<sect2>
<title>System startup</title>
<para>Follow these steps to boot:</para>
<itemizedlist>
<listitem>
<para>Restart the PC using the lilo boot disk from the previous
chapter.</para>
</listitem>
<listitem>
<para>At the LILO prompt, type &#34;<userinput>bootdisk init=/bin/sh</userinput>&#34;
and press <keycap>Enter</keycap>.</para>
</listitem>
<listitem>
<para>Insert the new, compressed root disk when prompted.</para>
</listitem>
</itemizedlist>
<para>The screen output should be similar to the following example:</para>
<para><screen>boot: bootdisk init=/bin/sh
Loading bootdisk
Uncompressing Linux... Ok, booting kernel.
..
.. [various kernel messages]
..
VFS: Insert root floppy to be loaded into RAM disk and press ENTER
RAMDISK: Compressed image found at block 0
VFS: Mounted root (ext2 filesystem) read-write.
Freeing unused kernel memory: 178k freed
# _</screen></para>
</sect2>
<sect2>
<title>Verify results</title>
<para>If the implementation was successful, this new root disk should
behave exactly like the root disk from the previous chapter. The key
difference is that this compressed root disk has much more room to grow
and we will put this extra space to good use in the next phase of the
project.</para>
</sect2>
<sect2>
<title>System shutdown</title>
<para>Remove the diskette from fd0 and restart the system using
<keycap>CTRL</keycap>-<keycap>ALT</keycap>-<keycap>DELETE</keycap>.</para>
</sect2>
</sect1>
</chapter>

View File

@ -0,0 +1,305 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<chapter id="phase3">
<title>Some Basic Utilities</title>
<sect1>
<title>Analysis</title>
<para>In the previous phase of the project it might seem like we did not
accomplish very much. A lot of energy was expended redesigning the root
disk, but the functionality is basically the same as in the initial
prototype phase. The root disk still does not do very much. But we did
make significant improvements when it comes to space savings. In this
phase we will put that extra space to good use and start cramming the root
disk with as many utilities as it can hold.</para>
<para>The root disk in first two phases only had shell built-in commands
like echo and pwd. For this phase, it would be nice to have some of the
commonly used external commands like cat, ls, mkdir, rm and such on the
root disk. Keeping this in mind we can define the goals for this phase as
follows:</para>
<itemizedlist>
<listitem>
<para>Retain all of the functionality from the previous phase.</para>
</listitem>
<listitem>
<para>Add some of the commonly used external commands.</para>
</listitem>
</itemizedlist>
</sect1>
<sect1>
<title>Design</title>
<sect2>
<title>Determining Required Commands</title>
<para>The first question that might come to mind is, &#34;How do we know
which commands are needed?&#34; It is possible to just start with cat
and ls then install other commands as we discover a need for them. But
this is terribly inefficient. We need a plan or a blueprint to work
from. For this we can turn to the Filesystem Hierarchy Standard (FHS)
available from <ulink url="http://www.pathname.com/fhs/">http://www.pathname.com/fhs/</ulink>.
The FHS dictates which commands should be present on a GNU/Linux system
and where they should be placed in the directory structure.</para>
</sect2>
<sect2>
<title>Locating Source Code</title>
<para>The next logical question is, &#34;Now that we know what we need,
where do we get the source code?&#34; The answer to this question can be
found by searching the Internet. There are several good &#39;net
resources out there that can aid us in our quest for source code. One
good place to start looking is the Linux Software Map (LSM) on Ibiblio.
Ibiblio&#39;s LSM search page can be found by navigating to <ulink
url="http://www.ibiblio.org/pub/linux">http://www.ibiblio.org/pub/linux</ulink>.
By using the names of commands as keywords, we should be able to come up
with the name and location of the corresponding source code package.</para>
</sect2>
<sect2>
<title>Leveraging FHS</title>
<para>So let&#39;s look at the FHS requirements for the /bin directory.
The first few commands in the list are cat, chgrp, chmod &#38; chown.
Using these as keywords in an LSM search we discover that we need
GNU&#39;s textutils package for cat and GNU&#39;s fileutils package for
chmod, chgrp &#38; chown. In fact quite a few of the commands in /bin
come from GNU&#39;s fileutils. So a good way to tackle the problem of
finding source code might be to group the commands together by package.</para>
<itemizedlist>
<listitem>
<para>The BASH shell -- echo, false, pwd, sh, true</para>
</listitem>
<listitem>
<para>GNU textutils -- cat</para>
</listitem>
<listitem>
<para>GNU fileutils -- chgrp, chmod, chown, cp, dd, df, ln, ls,
mkdir, mknod, mv, rm, rmdir, sync</para>
</listitem>
<listitem>
<para>GNU sh-utils -- date, hostname, stty, su, uname</para>
</listitem>
</itemizedlist>
<para>These four packages do not contain all of the commands in the /bin
directory, but they do represent of over 70% of them. That should be
enough to accomplish our goal of adding some of the commonly used
external commands. We can worry about the remaining commands in later
phases of the project.</para>
</sect2>
</sect1>
<sect1>
<title>Construction</title>
<para>Rather than copying files directly to the ramdisk, we can make
things easier by setting up a staging area. The staging area will give us
room to work without worrying about the space constraints of the ramdisk.
It will also provide a way to save our work and make it easier to enhance
the rootdisk in later phases of the project.</para>
<para>The staging procedure will work like this:</para>
<orderedlist>
<listitem>
<para>Create a directory structure as defined in the FHS.</para>
</listitem>
<listitem>
<para>Copy in the files from phase 2&#39;s root disk.</para>
</listitem>
<listitem>
<para>Build the four new packages from source code.</para>
</listitem>
<listitem>
<para>Install files into the correct FHS directories.</para>
</listitem>
<listitem>
<para>Strip the binaries to save space.</para>
</listitem>
<listitem>
<para>Check library dependencies.</para>
</listitem>
<listitem>
<para>Copy to the whole directory structure to the ramdisk.</para>
</listitem>
<listitem>
<para>Compress the ramdisk and write it out to floppy.</para>
</listitem>
</orderedlist>
<sect2>
<title>Create a staging area</title>
<para><programlisting>bash# mkdir ~/staging
bash# cd ~/staging
bash# mkdir bin boot dev etc home lib mnt opt proc root sbin tmp usr var
bash# mkdir var/log var/run</programlisting></para>
</sect2>
<sect2>
<title>Copy contents of phase 2 rootdisk</title>
<para><programlisting>bash# dd if=~/phase2-image.gz | gunzip -c &#62; /dev/ram7
bash# mount /dev/ram7 /mnt
bash# cp -dpR /mnt/* ~/staging
bash# umount /dev/ram7
bash# rmdir ~/staging/lost+found</programlisting></para>
</sect2>
<sect2>
<title>Install &#34;cat&#34; from GNU Textutils</title>
<para><programlisting>bash# cd /usr/src/textutils-2.1
bash# ./configure --host=i386-pc-linux-gnu
bash# make
bash# cd src
bash# cp cat ~/staging/bin</programlisting></para>
</sect2>
<sect2>
<title>Install binaries from GNU fileutils</title>
<para><programlisting>bash# cd /usr/src/fileutils-4.1
bash# ./configure --host=i386-pc-linux-gnu
bash# make
bash# cd src
bash# cp chgrp chmod chown cp dd df ln ls ~/staging/bin
bash# cp mkdir mkfifo mknod mv rm rmdir sync ~/staging/bin</programlisting></para>
</sect2>
<sect2>
<title>Install binaries from sh-utils</title>
<para><programlisting>bash# cd /usr/src/sh-utils-2.0
bash# ./configure --host=i386-pc-linux-gnu
bash# make
bash# cd src
bash# cp date hostname stty su uname ~/staging/bin</programlisting></para>
</sect2>
<sect2>
<title>Strip Binaries</title>
<para><programlisting>bash# strip ~/staging/bin/*</programlisting></para>
</sect2>
<sect2>
<title>Copy additional libraries</title>
<para><programlisting>bash# ldd ~/staging/bin/cat
bash# ldd ~/staging/bin/ls
bash# ls ~/staging/lib
bash# cp /lib/librt.so.1 ~/staging/lib
bash# cp /lib/libpthread.so.0 ~/staging/lib</programlisting></para>
</sect2>
<sect2>
<title>Create a compressed root disk image</title>
<para><programlisting>bash# cd /
bash# dd if=/dev/zero of=/dev/ram7 bs=1k count=4096
bash# mke2fs -m0 /dev/ram7
bash# mount /dev/ram7 /mnt
bash# cp -dpR ~/staging/* /mnt
bash# umount /dev/ram7
bash# dd if=/dev/ram7 of=~/phase3-image bs=1k
bash# gzip -9 ~/phase3-image</programlisting></para>
</sect2>
<sect2>
<title>Write the root disk image to floppy</title>
<para>Insert the diskette labled &#34;root disk&#34; into drive fd0.</para>
<para><programlisting>bash# dd if=~/phase3-image.gz of=/dev/fd0</programlisting></para>
</sect2>
</sect1>
<sect1>
<title>Implementation</title>
<para>We will need to have a read-write filesystem in order for some of
the commands to work. The kernel&#39;s normal behavior is to mount root as
read-only, but we can change this using a kernel option. By passing LILO
&#34;rw&#34; before &#34;init=/bin/sh&#34; we will get a read-write root
filesystem.</para>
<sect2>
<title>Sytem startup</title>
<para>Follow these steps to get the system running.</para>
<itemizedlist>
<listitem>
<para>Boot the PC from using the LILO boot disk.</para>
</listitem>
<listitem>
<para>At the LILO prompt, type &#34;<userinput>bootdisk rw
init=/bin/sh</userinput>&#34; and press <keycap>Enter</keycap>.</para>
</listitem>
<listitem>
<para>Insert the recently created root disk when prompted.</para>
</listitem>
</itemizedlist>