background image

grub> kernel (fd0)/boot/vmlinuz init=/bin/sh root=/dev/fd0 load_ramdisk=1 prompt_ramdisk=1

   [Linux−bzImage, setup=0xc00, size=0xce29b]

grub> boot

Linux version 2.4.26

..

.. [various kernel messages]

..

VFS: Insert root floppy disk to be loaded into RAM disk and press ENTER

RAMDISK: Compressed image found at block 0

VFS: Mounted root (ext2 filesystem) readonly.

Freeing unused kernel memory: 178k freed

# _

3.4.2. Verify results

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.

3.4.3. System shutdown

Remove the diskette from fd0 and restart the system using CTRLALTDELETE.

Pocket Linux Guide

Chapter 3. Saving Space

15

Summary of Contents for Pocket Linux Guide

Page 1: ...nding 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 erro...

Page 2: ...e 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 kernel 8 2 3 6 Copy the kernel to diske...

Page 3: ...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 compres...

Page 4: ...tall 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 script 32 6 3 7 Create halt reboot s...

Page 5: ...l 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...

Page 6: ...zation 54 A 4 4 Test audio output 54 A 4 5 Play a sample file 54 A 4 6 System shutdown 55 Appendix B GNU Free Documentation License 56 B 1 PREAMBLE 56 B 2 APPLICABILITY AND DEFINITIONS 56 B 3 VERBATIM...

Page 7: ...k of Linus Torvalds 2 Disclaimer This documentation is provided as is with no warranty of any kind either expressed or implied including but not limited to the implied warranties of merchantability an...

Page 8: ...odologies the sections may be summed up as follows 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...

Page 9: ...s Additional projects that may be of interest to Pocket Linux Guide readers 5 Feedback For technical questions about Pocket Linux please use the mailing list or the troubleshooting forum on the resour...

Page 10: ...port and encourage people who wish to explore Linux by building a GNU Linux system from nothing but source code Pocket Linux is not intended to be a full featured system but rather to give the reader...

Page 11: ...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 encoura...

Page 12: ...o we want to ignore everything but the absolutely critical pieces of a boot root diskset Basically it boils down to the following required items A boot loader The Linux kernel A shell Some dev files W...

Page 13: ...ee 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...

Page 14: ...boot grub 2 3 4 Finish bootloader installation Once the bootloader s files are copied to the boot disk we can enter the grub shell to finish the installation bash usr src grub 0 95 grub grub grub root...

Page 15: ...nd untar it into the usr src directory Build BASH for an i386 CPU with the following commands bash cd usr src bash 3 0 bash export CC gcc mcpu i386 bash configure enable static link enable minimal con...

Page 16: ...o 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...

Page 17: ...2 4 4 System shutdown Remove the diskette from fd0 and restart the system using CTRL ALT DELETE Pocket Linux Guide Chapter 2 A Simple Prototype 11...

Page 18: ...nd 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 3 2 2 Stripped Binaries Next we shou...

Page 19: ...Create a ramdisk bash dd if dev zero of dev ram7 bs 1k count 4096 bash mke2fs m0 dev ram7 4096 bash mount dev ram7 mnt 3 3 2 Rebuild the BASH shell bash cd usr src bash 3 0 bash make distclean bash ex...

Page 20: ...console c 5 1 3 3 6 Compress the ramdisk image bash cd bash umount dev ram7 bash dd if dev ram7 of phase2 image bs 1k count 4096 bash gzip 9 phase2 image 3 3 7 Copy the compressed image to diskette In...

Page 21: ...ext2 filesystem readonly Freeing unused kernel memory 178k freed _ 3 4 2 Verify results If the implementation was successful this new root disk should behave exactly like the root disk from the previo...

Page 22: ...www pathname com fhs The FHS dictates which commands should be present on a Linux system and where they should be placed in the directory structure 4 2 2 Locating Source Code The next logical question...

Page 23: ...struction 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 constrain...

Page 24: ...ls command then copy any missing libraries to the staging area bash cp lib librt so 1 staging lib bash cp lib libpthread so 0 staging lib bash cp lib libcrypt so 1 staging lib 4 3 5 Strip binaries an...

Page 25: ...GRUB version 0 95 grub kernel fd0 boot vmlinuz rw init bin sh root dev fd0 load_ramdisk 1 prompt_ramdisk 1 Linux bzImage setup 0xc00 size 0xce29b grub boot Linux version 2 4 26 various kernel message...

Page 26: ...4 4 3 System shutdown Remove the diskette from fd0 and restart the system using CTRL ALT DELETE Pocket Linux Guide Chapter 4 Some Basic Utilities 20...

Page 27: ...ther filesystems to mount besides root Taking into account all of the above information the goals for this phase are defined as follows A way to check filesystem integrity The ability to mount filesys...

Page 28: ...s An easy way to do this would be to write a short two line script that calls fsck and then mount But what if the filesystems are not clean The system should definitely not try to mount a corrupted fi...

Page 29: ...writable 2 Remount as read write again this time using the f option so that an entry is written into etc mtab but is not actually mounted a second time 3 5 2 4 3 Device files The only thing left to d...

Page 30: ...o need to copy anything new 5 3 4 Strip binaries to save space bash strip staging bin bash strip staging sbin 5 3 5 Create additional device files bash mknod staging dev ram0 b 1 0 bash mknod staging...

Page 31: ...e4 image 5 3 9 Write the root disk image to floppy Insert the diskette labeled root disk into drive fd0 bash dd if phase4 image gz of dev fd0 bs 1k 5 4 Implementation 5 4 1 System startup Start the sy...

Page 32: ...le below bash PATH sbin bin etc init d export PATH bash cat etc mtab bash local_fs dev ram0 clean 74 1024 files 3178 4096 blocks Remounting as read write Mounting local filesystems bash cat etc mtab d...

Page 33: ...Remove the diskette from fd0 and restart the system using CTRL ALT DELETE Pocket Linux Guide Chapter 5 Checking and Mounting Disks 27...

Page 34: ...above list into consideration the goals for this phase are defined as follows Kernel loads without manual intervention Automated system start up sequence Graceful shutdown capability 6 2 Design 6 2 1...

Page 35: ...e popular GNU Linux distributions use System V style init scripts Since we are using a sysvinit daemon it makes sense to use System V style scripts as well The following documents all touch upon the S...

Page 36: ...cd usr src sysvinit 2 85 src bash make CC gcc mcpu i386 bash cp halt init shutdown staging sbin bash ln s halt staging sbin reboot bash ln s init staging sbin telinit bash mknod staging dev initctl p...

Page 37: ...tart fi done fi end of etc init d rc Make the file executable bash chmod x staging etc init d rc 6 3 5 Modify etc init d local_fs script A case statement is added to allow the script to either mount o...

Page 38: ...hostname bin sh hostname set the system name to the name stored in etc hostname PATH sbin bin export PATH echo Setting hostname if f etc hostname then hostname cat etc hostname else hostname gnu linux...

Page 39: ...bash ln s init d local_fs K10local_fs bash ln s init d reboot K90reboot 6 3 9 Create the root disk image bash cd bash dd if dev zero of dev ram7 bs 1k count 4096 bash mke2fs m0 dev ram7 4096 bash mou...

Page 40: ...tartup scripts Use the mount command to check that local filesystems are mounted as read write The output should look like the example below bash mount dev root on type ext2 rw proc on proc type proc...

Page 41: ...name 2 When the user name is entered control is handed off to the login program 3 The login program asks for a password and verifies the credentials using etc passwd etc group and possibly etc shadow...

Page 42: ...s bookstores or directly from O Reilly Publishing at http www oreilly com 7 2 4 Dependencies Running ldd on the login program from util linux will reveal that it is linked to the libraries libcrypt so...

Page 43: ...to run it Ownership of 0 0 root user root group and permissions of rwsr x octal 4750 would be a good fit for su The same logic can be applied to other directories and files in the root filesystem usi...

Page 44: ...using the example below or design a customized message Connected to l at b bps Be sure that l is a lowercase letter L and not the number one 7 3 4 2 etc passwd Use a text editor to create a minimal pa...

Page 45: ...should be accessible to administrators only Other files like dev null should have full privileges granted to everyone bash chmod 660 staging dev fd0 dev ram0 bash chmod 666 staging dev null bash chmo...

Page 46: ...Connected to tty1 at 38400 bps gnu linux login 7 4 2 Add a new user to the system Log in as root Create a new unprivileged user and new group by appending a line to the etc passwd and etc group files...

Page 47: ...ds and verify that they do not work bash ls root bash sbin shutdown h now bash su 7 4 4 System shutdown Switch back to tty1 where root is logged in bash shutdown h now Pocket Linux Guide Chapter 7 Ena...

Page 48: ...hould fit onto the tiny root filesystem So in order to finish up this phase of the project we need to accomplish the following goals Add the more ps and sed commands Install the optional ed editor 8 2...

Page 49: ...rsion we can go to the Freshmeat website at http freshmeat net and search for procps in projects Both sed and ed packages feature GNU s familiar configure script and are therefore very easy to build T...

Page 50: ...INES fi done INPUT end of more sh Create a symbolic link for more bash ln s more sh staging bin more 8 3 2 Create additional device files bash ln s proc self fd staging dev fd bash ln s fd 0 staging d...

Page 51: ...unt 4096 bash mke2fs m0 dev ram7 4096 bash mount dev ram7 mnt bash cp dpR staging mnt bash umount dev ram7 bash dd if dev ram7 of phase7 image bs 1k bash gzip 9 phase7 image 8 3 9 Copy the image to di...

Page 52: ...h sed e s Legacy Old School etc passwd Verify that sed did not make the changes permanent bash cat etc passwd 8 4 5 Test the ed editor Use ed to change properties on the daemon user bash ed p ed r etc...

Page 53: ...projects with ease and confidence 9 2 Planning Next Steps The Pocket Linux system is nearly overflowing so there really is no more room to expand the current root diskette to support any additional co...

Page 54: ...ystem into a pocket sized mp3 player A few things are listed below Add support for audio hardware Create space for the mp3blaster program Provide a convenient way to access audio files A 2 Design A 2...

Page 55: ...e contents of the ramdisk are dumped to an image file using dd 3 The image file is compressed with gzip 4 The compressed image file is written to floppy with dd 5 If that is how the compressed image m...

Page 56: ...y 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 termin...

Page 57: ...arch i386 boot bzImage mnt boot vmlinuz A 3 1 3 Unmount the boot disk bash cd bash umount mnt A 3 2 Create an enhanced root disk A 3 2 1 Create additional device files A 3 2 1 1 IDE CD ROM bash mknod...

Page 58: ...ho 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 ENTER read REPLY echo Clearing dev ram1 dd if dev zero...

Page 59: ...rama mp3blaster bash cd usr src mp3blaster 3 2 0 bash configure bash make bash cp src mp3blaster usr staging bin A 3 3 3 Copy additional libraries and terminfo Use ldd to find out which libraries are...

Page 60: ...nd press Enter 4 A 4 2 Verify that the usr diskette loaded properly bash mount bash ls lR usr A 4 3 Check the audio device initialization bash dmesg more If everything worked there should be a line or...

Page 61: ...A 4 6 System shutdown Bring the system down gracefully with the shutdown command Pocket Linux Guide Appendix A Hosting Applications 55...

Page 62: ...is License applies to any manual or other work in any medium that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License Such a notice grants a w...

Page 63: ...es only The Title Page means for a printed book the title page itself plus such following pages as are needed to hold legibly the material this License requires to appear in the title page For works i...

Page 64: ...that edition to the public It is requested but not required that you contact the authors of the Document well before redistributing any large number of copies to give them a chance to provide you with...

Page 65: ...ate some or all of these sections as invariant To do this add their titles to the list of Invariant Sections in the Modified Version s license notice These titles must be distinct from any other secti...

Page 66: ...used to limit the legal rights of the compilation s users beyond what the individual works permit When the Document is included in an aggregate this License does not apply to the other works in the a...

Page 67: ...nse you may choose any version ever published not as a draft by the Free Software Foundation B 12 ADDENDUM How to use this License for your documents To use this License in a document you have written...

Reviews: