Pocket-Linux-Guide.pdf

(202 KB) Pobierz
Pocket Linux Guide
Pocket Linux Guide
David Horton
Revision History
Revision 3.0 2004−11−02 Revised by: DH
Changed bootloader to GRUB rather than LILO. Updated versions on all source code packages. Made minor
clarifications to some shell commands and scripts.
Revision 2.1 2004−02−18 Revised by: DH
Corrected typos. Changed resource site hosting to SourceForge. Added appendix B to include the GNU Free
Documentation License as part of this document.
Revision 2.0 2003−11−08 Revised by: DH
Updated to use GNU coreutils in place of fileutils, sh−utils and textutils. Updated version numbers on many
source code packages. Introduced Freshmeat as a resource for finding source code. Changed /etc/mtab to a
real file rather than using a symlink to /proc/mounts. Corrected local_fs script errors. Updated email address.
Revision 1.2
2003−05−31
Revised by: DH
Corrected errors in "strip −o library" commands.
Revision 1.1
2003−05−21
Revised by: DH
Bug fixes, typo corrections and improved XML markup.
Revision 1.0
2003−02−17
Revised by: DH
Initial Release, reviewed by LDP.
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.
37379811.002.png
Pocket Linux Guide
Table of Contents
Legal Information. ..............................................................................................................................................1
1. Copyright and License. ........................................................................................................................1
2. Disclaimer. ...........................................................................................................................................1
Introduction. ........................................................................................................................................................2
1. About Pocket Linux. ............................................................................................................................2
2. Prerequisite Skills. ...............................................................................................................................2
3. Project Forma. .....................................................................................................................................2
4. Help & Support. ...................................................................................................................................2
5. Feedback. .............................................................................................................................................3
Chapter 1. Project Initiation. .............................................................................................................................4
1.1. A Brief History of GNU/Linux. ........................................................................................................4
1.2. The Goal of Pocket Linux. ................................................................................................................4
1.3. Working Within The Constraints. .....................................................................................................4
Chapter 2. A Simple Prototype. .........................................................................................................................6
2.1. Analysis. ...........................................................................................................................................6
2.2. Design. ..............................................................................................................................................6
2.2.1. Simplification. .........................................................................................................................6
2.2.2. Boot Disk. ................................................................................................................................6
2.2.3. Root Disk. ................................................................................................................................7
2.2.4. CPU Compatibility. .................................................................................................................7
2.3. Construction. .....................................................................................................................................7
2.3.1. Prepare the boot disk media. ...................................................................................................7
2.3.2. Build the GRUB bootloader. ...................................................................................................7
2.3.3. Copy the bootloader files to diskette. ......................................................................................8
2.3.4. Finish bootloader installation. .................................................................................................8
2.3.5. Build the Linux kerne. ............................................................................................................8
2.3.6. Copy the kernel to diskette. .....................................................................................................9
2.3.7. Unmount the boot disk. ...........................................................................................................9
2.3.8. Prepare the root disk media. ....................................................................................................9
2.3.9. Build BASH. ...........................................................................................................................9
2.3.10. Copy BASH to the root disk. .................................................................................................9
2.3.11. Create device files that BASH needs. ...................................................................................9
2.3.12. Unmount the root disk. ..........................................................................................................9
2.4. Implementation. ..............................................................................................................................10
2.4.1. System startup. ......................................................................................................................10
2.4.2. Testing what works ...............................................................................................................10
2.4.3. Noting what does not work ...................................................................................................10
2.4.4. System shutdown. ..................................................................................................................11
Chapter 3. Saving Space. ..................................................................................................................................12
3.1. Analysis. .........................................................................................................................................12
3.2. Design. ............................................................................................................................................12
3.2.1. Shared Libraries. ...................................................................................................................12
3.2.2. Stripped Binaries. ..................................................................................................................12
3.2.3. Compressed Root Filesystem. ...............................................................................................12
i
37379811.003.png
Pocket Linux Guide
Table of Contents
3.3. Construction. ...................................................................................................................................13
3.3.1. Create a ramdisk. ...................................................................................................................13
3.3.2. Rebuild the BASH shell. .......................................................................................................13
3.3.3. Determine which libraries are required. ................................................................................13
3.3.4. Copy BASH and its libraries to the ramdisk. ........................................................................14
3.3.5. Create a console device. ........................................................................................................14
3.3.6. Compress the ramdisk image. ...............................................................................................14
3.3.7. Copy the compressed image to diskette. ...............................................................................14
3.4. Implementation. ..............................................................................................................................14
3.4.1. System startup. ......................................................................................................................14
3.4.2. Verify results. ........................................................................................................................15
3.4.3. System shutdown. ..................................................................................................................15
Chapter 4. Some Basic Utilities. .......................................................................................................................16
4.1. Analysis. .........................................................................................................................................16
4.2. Design. ............................................................................................................................................16
4.2.1. Determining Required Commands. .......................................................................................16
4.2.2. Locating Source Code. ..........................................................................................................16
4.2.3. Leveraging FHS. ...................................................................................................................16
4.2.4. Downloading Source Code. ...................................................................................................17
4.3. Construction. ...................................................................................................................................17
4.3.1. Create a staging area. .............................................................................................................17
4.3.2. Copy contents of phase 2 rootdisk. .......................................................................................17
4.3.3. Install binaries from GNU coreutils. .....................................................................................18
4.3.4. Copy additional libraries. ......................................................................................................18
4.3.5. Strip binaries and libraries. ....................................................................................................18
4.3.6. Create a compressed root disk image. ...................................................................................18
4.3.7. Write the root disk image to floppy.. .....................................................................................19
4.4. Implementation. ..............................................................................................................................19
4.4.1. Sytem startup. ........................................................................................................................19
4.4.2. Testing new commands. ........................................................................................................19
4.4.3. System shutdown. ..................................................................................................................20
Chapter 5. Checking and Mounting Disks. ....................................................................................................21
5.1. Analysis. .........................................................................................................................................21
5.2. Design. ............................................................................................................................................21
5.2.1. Determining necessary utilities.. ...........................................................................................21
5.2.2. Finding source code.. .............................................................................................................21
5.2.3. Automating fsck and mount. .................................................................................................22
5.2.4. File dependencies. .................................................................................................................22
5.3. Construction. ...................................................................................................................................23
5.3.1. Install utilities from e2fsprogs. ..............................................................................................23
5.3.2. Install utilities from util−linux. .............................................................................................23
5.3.3. Check library requirements. ..................................................................................................24
5.3.4. Strip binaries to save space ...................................................................................................24
5.3.5. Create additional device files. ...............................................................................................24
5.3.6. Create the fstab and mtab files. .............................................................................................24
ii
37379811.004.png
Pocket Linux Guide
Table of Contents
5.3.7. Write a script to check and mount local filesystems. ............................................................24
5.3.8. Create a compressed root disk image. ...................................................................................25
5.3.9. Write the root disk image to floppy.. .....................................................................................25
5.4. Implementation. ..............................................................................................................................25
5.4.1. System startup. ......................................................................................................................25
5.4.2. Test the local_fs scrip. ..........................................................................................................26
5.4.3. Create and mount additional filesystems.. .............................................................................26
5.4.4. System shutdown. ..................................................................................................................27
Chapter 6. Automating Startup & Shutdown. ...............................................................................................28
6.1. Analysis. .........................................................................................................................................28
6.2. Design. ............................................................................................................................................28
6.2.1. Determining necessary utilities. ............................................................................................28
6.2.2. Obtaining source code. ..........................................................................................................29
6.2.3. Checking dependencies. ........................................................................................................29
6.2.4. Designing a simple GRUB configuration file.. .....................................................................29
6.2.5. Outlining start−up scripts. .....................................................................................................29
6.3. Construction. ...................................................................................................................................30
6.3.1. Create a GRUB configuration file. ........................................................................................30
6.3.2. Install sysvinit utilities.. .........................................................................................................30
6.3.3. Create /etc/inittab file. ...........................................................................................................30
6.3.4. Create /etc/init.d/rc script. .....................................................................................................31
6.3.5. Modify /etc/init.d/local_fs script. ..........................................................................................31
6.3.6. Create a hostname scrip. .......................................................................................................32
6.3.7. Create halt & reboot scripts. ..................................................................................................32
6.3.8. Create rcN.d directories and links. ........................................................................................33
6.3.9. Create the root disk image. ....................................................................................................33
6.3.10. Copy the image to diskette. .................................................................................................33
6.4. Implementation. ..............................................................................................................................33
6.4.1. System Startup. ......................................................................................................................34
6.4.2. Verify success of startup scripts. ...........................................................................................34
6.4.3. System shutdown. ..................................................................................................................34
Chapter 7. Enabling Multiple Users. ...............................................................................................................35
7.1. Analysis. .........................................................................................................................................35
7.2. Design. ............................................................................................................................................35
7.2.1. The login process.. .................................................................................................................35
7.2.2. Obtaining source code. ..........................................................................................................35
7.2.3. Creating support files. ...........................................................................................................35
7.2.4. Dependencies. ........................................................................................................................36
7.2.5. Assigning ownership and permissions. .................................................................................36
7.3. Construction. ...................................................................................................................................37
7.3.1. Verify presence of getty and login. .......................................................................................37
7.3.2. Modify inittab for multi−user mode. .....................................................................................37
7.3.3. Create tty devices. .................................................................................................................38
7.3.4. Create support files in /etc. ....................................................................................................38
7.3.5. Copy required libraries. .........................................................................................................39
iii
37379811.005.png
Pocket Linux Guide
Table of Contents
7.3.6. Set directory and file permissions. ........................................................................................39
7.3.7. Create the root disk image. ....................................................................................................40
7.3.8. Copy the image to diskette. ...................................................................................................40
7.4. Implementation. ..............................................................................................................................40
7.4.1. System Startup. ......................................................................................................................40
7.4.2. Add a new user to the system. ...............................................................................................40
7.4.3. Test the new user's ability to use the system. ........................................................................41
7.4.4. System shutdown. ..................................................................................................................41
Chapter 8. Filling in the Gaps. .........................................................................................................................42
8.1. Analysis. .........................................................................................................................................42
8.2. Design. ............................................................................................................................................42
8.2.1. more. ......................................................................................................................................42
8.2.2. More device files. ..................................................................................................................43
8.2.3. ps, sed & ed. ..........................................................................................................................43
8.3. Construction. ...................................................................................................................................43
8.3.1. Write a "more" scrip. ............................................................................................................43
8.3.2. Create additional device files. ...............................................................................................44
8.3.3. Install ps. ...............................................................................................................................44
8.3.4. Install sed. ..............................................................................................................................44
8.3.5. Install ed. ...............................................................................................................................45
8.3.6. Strip binaries to save space ...................................................................................................45
8.3.7. Ensure proper permissions. ...................................................................................................45
8.3.8. Create the root disk image. ....................................................................................................45
8.3.9. Copy the image to diskette. ...................................................................................................45
8.4. Implementation. ..............................................................................................................................45
8.4.1. System startup. ......................................................................................................................45
8.4.2. Test the "more" script. ...........................................................................................................45
8.4.3. Use ps to show running processes. ........................................................................................46
8.4.4. Run a simple sed scrip. .........................................................................................................46
8.4.5. Test the "ed" editor. ...............................................................................................................46
8.4.6. System shutdown. ..................................................................................................................46
Chapter 9. Project Wrap Up. ...........................................................................................................................47
9.1. Celebrating Accomplishments. .......................................................................................................47
9.2. Planning Next Steps. .......................................................................................................................47
Appendix A. Hosting Applications. .................................................................................................................48
A.1. Analysis. .........................................................................................................................................48
A.2. Design. ...........................................................................................................................................48
A.2.1. Support for audio hardware. .................................................................................................48
A.2.2. Creating space for the program. ...........................................................................................49
A.2.3. Accessing audio files. ...........................................................................................................49
A.2.4. Other required files. ..............................................................................................................50
A.2.5. Summary of tasks. ................................................................................................................50
A.3. Construction. ..................................................................................................................................50
A.3.1. Create an enhanced boot disk. ..............................................................................................51
iv
37379811.001.png
Zgłoś jeśli naruszono regulamin