cvs commit: hints uclibc-bootfloppy.txt

timothy at linuxfromscratch.org timothy at linuxfromscratch.org
Wed May 7 09:38:54 PDT 2003


timothy     03/05/07 12:38:54

  Modified:    .        uclibc-bootfloppy.txt
  Log:
  Added gpm instructions. Changes to build environment, root partition, kernel configuration, etc.
  
  Revision  Changes    Path
  1.2       +371 -308  hints/uclibc-bootfloppy.txt
  
  Index: uclibc-bootfloppy.txt
  ===================================================================
  RCS file: /home/cvsroot/hints/uclibc-bootfloppy.txt,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- uclibc-bootfloppy.txt	13 Apr 2003 02:09:22 -0000	1.1
  +++ uclibc-bootfloppy.txt	7 May 2003 16:38:53 -0000	1.2
  @@ -8,7 +8,7 @@
   	lightweight C library. "Quick and dirty" means using an ad-hoc,
   	non-chroot, but safe development environment. 
   
  -VERSION:	0.1
  +VERSION:	0.1.1
   
   CONTENTS
   
  @@ -16,18 +16,26 @@
   What do we need?
   Installing uClibc on the development platform
   Setting up the development environment
  -Creating and mounting the root filesystem
  +Creating the root filesystem
   Installing uClibc for the bootdisk
   Compiling the linux kernel
   Installing busybox
  +Installing gpm
   Other programs
   Creating the bootdisk
  -Credits, bugs and weirdnesses
  -Appendix A -- the loopmnt script
  -Appendix B -- the mkbootdisk script
  +Credits, contributions, bugs and weirdnesses
  +Appendix A -- the mkbootdisk script
   
   PREFACE
   
  +* For the most recent version check out 
  +
  +http://www.renyi.hu/~ekho/lowlife/uclibc-bootfloppy.txt
  +
  +* See changelog at 
  +
  +http://www.renyi.hu/~ekho/lowlife/Changelog
  +
   * Comments, ideas, critics, flames are welcome.
   
   * (If you are an LFS user, you can skip this.) Although this document is
  @@ -56,9 +64,9 @@
   The bootfloppy will be cutting edge: uses uClibc and Busybox which are
   actively developed projects for the embedded platform. Moreover, I used
   a kernel from the 2.4.* branch (but feel free to use other kernel
  -release). It is a good question to ask whether is it useful: many floppy
  +releases). It is a good question to ask whether this is useful: many floppy
   distros use older kernels for reducing resource usage. I can say the
  -following: on the one hand, I can afford using a new kernel as my
  +following: on the one hand, I can afford using a recent kernel as my
   bootfloppy merrily runs on my 486 with 8M RAM; on the other hand, from
   the moment I began to use this up-to-date stuff, the problems with handling
   the terminal buffer and plip timeouts vanished. So unless you are really
  @@ -77,22 +85,20 @@
   ) 
   
   Additional info and downloadable bootdisk image with svnc can be found
  -within my homepage:
  +at my homepage (or at its mirror):
   
   http://www.renyi.hu/~ekho/lowlife/
  -
  -(However, the less downloads of the image the happier I'm as it is
  -LFS... ;)
  -
  -and I mirror it at
  -
   http://www.personal.ceu.hu/students/01/Csaba_Henk/lowlife/
   
  -In this hint the assumption of using an x86 PC (both for making and booting
  -the floppy) and gcc is set. You may try to port it to another architecture / 
  -compiler. Doing it on another architecture should not be hard. Doing it with
  -another compiler depends on how well does uClibc can cooperate with that
  -compiler.  
  +In this hint the assumption of using an x86 PC (both for making and
  +booting the floppy) and gcc is set. You may try to port it to another
  +architecture / compiler. Doing it on another architecture should not
  +be hard. Doing it with another compiler depends on how much does
  +uClibc support that compiler.  
  +
  +If you copy command from this hint to your shell, be careful
  +that line-terminating backslashes (\) will keep their position (no
  +whitespace characters should follow them).
   
   What do we need?
   ----------------
  @@ -113,6 +119,8 @@
    http://www.uclibc.org/downloads/
   busybox
    http://www.busybox.net/downloads/
  +gpm (optional)
  + ftp://arcana.linux.it/pub/gpm
   
   Installing uClibc on the development platform
   ---------------------------------------------
  @@ -125,16 +133,25 @@
   make menuconfig
   
   uClibc now has a configuration interface similar to the linux kernel.
  -The default configuration is quite suitable, probably you need not
  -change anything (especially you need not use full math support).
  -However, taking a look at the options never hurts; you may consider
  -fine-tuning the target processor type. After you exit, 
  +Apply the following setting:
  +
  +Library Installation Options  --->
  +	(/lib) Shared library loader path 
  +
  +Apart from this, the default configuration is quite suitable, probably
  +you need not change anything (especially you need not use full math
  +support). However, taking a look at the options never hurts; you should
  +make sure that the "Linux kernel header location" field is filled in
  +correctly (if the kernel release you use for the floppy is not the some
  +as the one used on the development platform, you should the headers for
  +the release used for the floppy), and you may consider fine-tuning the
  +target processor type. After you exit, 
   
   make &&
   make install
   
   Further on we assume that you installed uClibc into
  -/usr/i386-linux-uclibc/. 
  +/usr/i386-linux-uclibc/ (the default installation location). 
   
   Setting up the development environment
   --------------------------------------
  @@ -170,27 +187,19 @@
   
   1) Ignore it, and execute these tasks as root.  
   
  -2) Make a script named loopmnt for mounting, and one named mkbootdisk for
  -producing the floppy. These scripts must be executable only by root
  -(mode 744). With the help of the sudo utility we let the bootdisk user
  -to use these scripts as well. That is, we put them to a place included
  -in the $PATH variable of the bootdisk user, and then type:
  -
  -cat >> /etc/sudoers << "EOF"
  -bootdisk localhost = NOPASSWD: loopmnt
  -bootdisk localhost = NOPASSWD: mkbootdisk
  -EOF 
  -     
  -A realization of loopmnt can be found in Appendix A, or at
  -
  -http://www.renyi.hu/~ekho/lowlife/loopmnt
  +2) Make a script named mkbootdisk for doing this tasks. This script must
  +be executable only by root (mode 744). With the help of the sudo utility
  +we let the bootdisk user to use this script as well. That is, we put it
  +to $BDISKHOME/bin and then type:
   
  -A realization of mkbootdisk can be found in Appendix B, or at
  +echo "
  +bootdisk ALL = NOPASSWD: $BDISKHOME/bin/mkbootdisk" >> /etc/sudoers
  +     
  +A realization of mkbootdisk can be found in Appendix A, or at
   
   http://www.renyi.hu/~ekho/lowlife/mkbootdisk
   
  -Typing "loopmnt -h" and "mkbootdisk -h" will print a brief information
  -on usage.
  +Typing "mkbootdisk -h" will print a brief information on usage.
   
   We have the desired environment. We go on compiling the programs. Become
   user bootdisk:
  @@ -198,52 +207,27 @@
   su - bootdisk
   
   In the rest of the hint we will act as user bootdisk (except if you
  -don't use the loopmnt and mkbootdisk scripts: then the appropriate
  -actions are to be done as root).
  +don't use the mkbootdisk script: then the appropriate actions are to be
  +done as root).
   
   Some of the commands below assume that the actual source archive is
   decompressed in $HOME (which is the same as the prior $BDISKHOME). 
  +Software installation instructions always start at the point when the
  +source tarball is already decompressed and you entered the source
  +directory.
   
  -Creating and mounting the root filesystem
  +Creating the root filesystem
   -----------------------------------------
   
  -We will create a root filesystem which will be big enough for carrying
  -the programs which are listed in this hint and in the svnc-x_terminal
  -hint. We will also populate the filesystem with basic directories and
  -system files. If you intend to put more stuff to the floppy, you may
  -need to create a bigger filesystem. 
  +We will put the files of the root filesysem of the floppy to a directory
  +named rfloppy. Firstly we create the directory and a basic tree of
  +subdirectories which vaguley resembles the FHS idea:
   
  -For the sake of convenience, create the $HOME/loop directory, or a
  -symlink from your favorite loop mount point (eg., /mnt/loop1) to
  -$HOME/loop. Type the following (if you don't want to use devfs with the
  -floppy -- do this only if you know what you are doing! --, you are
  -advised to use "-N 400" or more instead of "-N 256" below):
  -
  -dd if=/dev/zero of=rfloppy bs=1k count=1400 &&
  -/sbin/mke2fs -m 0 -N 256 rfloppy 
  -
  -Now if you use the loopmnt script, type:
  -
  -sudo loopmnt rfloppy loop 
  -
  -If you don't use it, become root, type:
  -
  -mount $BDISKHOME/rfloppy -o loop $BISKDHOME/loop
  -
  -and then become bootdisk again. Going on: 
  -
  -rmdir loop/lost+found &&
  -mkdir -p loop/{dev,proc,etc/init.d,sbin,bin,lib,mnt,usr,var/log}
  -cat > loop/etc/fstab << "EOF" &&
  -/dev/ram0       /               ext2    defaults 1 0
  -proc          /proc             proc    noauto   0 0
  -EOF
  -echo "root:x:0:0:root:/root:/bin/sh" > loop/etc/passwd &&
  -echo "root:x:0:" > loop/etc/group &&
  -mkdir etc/init.d
  -cat > loop/etc/init.d/rcS << "EOF" &&
  +cd &&
  +mkdir -p rfloppy/{dev,proc,etc/init.d,sbin,bin,lib,mnt,usr,var/log} &&
  +cat > rfloppy/etc/init.d/rcS << "EOF" &&
   #!/bin/sh
  -mount /proc
  +mount proc /proc -t proc
   EOF
   
   The etc/init.d/rcS file will be the startup script for the floppy. Put
  @@ -255,20 +239,20 @@
   
   We copy the necessary libraries of uClibc to the bootdisk.
   
  -cd /usr/i386-linux-uclibc/lib/ &&
  -cp -a ld-uClibc* libc.so.0 libuClibc-* ~/loop/lib &&
  +cp -a /usr/i386-linux-uclibc/lib/{ld-uClibc*,libc.so.0,libuClibc-*} \
  + ~/rfloppy/lib &&
   cd &&
  -mkdir loop/usr/i386-linux-uclibc &&
  -ln -s ../../lib loop/usr/i386-linux-uclibc
  +mkdir rfloppy/usr/i386-linux-uclibc &&
  +ln -s ../../lib rfloppy/usr/i386-linux-uclibc
   
   [Explanation:
   
  -"ln -s ../../lib loop/usr/i386-linux-uclibc" : 
  +"ln -s ../../lib rfloppy/usr/i386-linux-uclibc" : 
   
  -When we build our programs, they will be linked to to the system uClibc
  -libs, which are located in /usr/i386-linux-uclibc/lib. Therefore we must
  -ensure that when we boot the floppy, these programs will find the uClibc
  -libs at /usr/i386-linux-uclibc/lib.] 
  +When we build our programs, they will be linked to the system uClibc
  +libs, which are located in /usr/i386-linux-uclibc/lib. Therefore we
  +must ensure that when we boot the floppy, these programs will find
  +the uClibc libs at /usr/i386-linux-uclibc/lib.] 
   
   Compiling the linux kernel
   ---------------------------
  @@ -276,7 +260,7 @@
   We will compile a network-aware kernel optimized to size. We don't give
   a complete reference, we just highlight some crucial points.If you need
   not network-awareness, you may omit TCP/IP netowrking and network
  -dirvers; but even in this case it is strongly recommended to include
  +drivers; but even in this case it is strongly recommended to include
   "Unix domain sockets". 
   
   In the kernel source tree type:
  @@ -299,21 +283,21 @@
   
   In the "Network device support  --->" menupoint choose those network
   drivers you intend to use. If you want to use plip, choose it as a
  -module, and set:
  +module, and also set:
   
   Parallel port support  --->
   	<*> Parallel port support
   	<M>   PC-style hardware
   
  -This is advised because of the following: as I experienced, if no option
  -is given, the kernel initializes the parallel port (PC-style) IRQ-less!
  -At boot time we won't have the possibility to pass options to the
  -kernel, as we won't use a boot loader. Thus we can set the appropriate
  -IRQ value only if we load the parallel port driver as module. Also, to
  -gain more controll over the NIC drivers, consider building them as
  -modules.
  +This is advised because of the following: as I experienced, if no
  +option is given, the kernel initializes the parallel port (PC-style)
  +IRQ-less!  At boot time we won't have the possibility to pass options
  +to the kernel, as we won't use a boot loader or initrd. Thus we can
  +set the appropriate IRQ value only if we load the parallel port
  +driver as module. Also, to gain more control over the NIC drivers,
  +consider building them as modules.
   
  -If you intend to use the devfs facility (recommended!), choose 
  +In this hint we use the devfs facility, so choose 
   
   File systems  --->
   	[*] /dev file system support
  @@ -334,10 +318,10 @@
   
   commands. Then type
   
  -mkdir $HOME/loop/lib/modules
  +mkdir $HOME/rfloppy/lib/modules
   
   and copy the NIC driver modules from the drivers/net directory to
  -$HOME/loop/lib/modules, and also the other modules you built. Eg., if
  +$HOME/rfloppy/lib/modules, and also the other modules you built. Eg., if
   you use plip, you will need the drivers/parport/parport_pc.o
   module.
    
  @@ -348,13 +332,13 @@
   If you have troubles with configuring the kernel properly, my .config file
   might be of your help:
   
  -http://www.renyi.hu/~ekho/lowlife/linux/.config
  +http://www.renyi.hu/~ekho/lowlife/linux-2.4.19/.config
   
   Installing busybox
   ------------------
   
  -Before making it, adjust the Config.h file according to your needs. If
  -you use devfsd, be sure that the 
  +Before making it, adjust the Config.h file according to your needs. To
  +make busybox work with devfs, be sure that the 
   
   #define BB_FEATURE_DEVFS
   
  @@ -372,25 +356,43 @@
   sed  '/^CROSS/s%\(^.*$\)%\1 i386-uclibc-%' Makefile > Makefile.tmp &&
   mv Makefile.tmp Makefile &&
   make &&
  -make PREFIX=$HOME/loop1 install
  +make PREFIX=$HOME/rfloppy install
   
   If you have troubles with configuring busybox properly, my Config.h file
   might be of your help:
   
  -http://www.renyi.hu/~ekho/lowlife/busybox/Config.h
  +http://www.renyi.hu/~ekho/lowlife/busybox-0.60.5/Config.h
  +
  +Installing gpm
  +--------------
  +
  +Having mouse at the console is not necessary, but very comfortable for a
  +bootfloppy as well. If you want it, install gpm by running the following
  +commands:
  +
  +export LDFLAGS="-lm" &&
  +./configure &&
  +make && 
  +unset LDFLAGS &&
  +strip src/gpm &&
  +mkdir -p $HOME/rfloppy/{usr/sbin,var/run} &&
  +cp src/gpm $HOME/rfloppy/usr/sbin &&
  +cp -a /usr/i386-linux-uclibc/lib/{libm-*,libm.so.0} ~/rfloppy/lib
  +
  +[The /var/run directory is needed for gpm at runtime.]
   
   Other programs
   --------------
   
   Now if there is anything more you want to have on the floppy, compile it
  -and put it to the appropriate place under $HOME/loop. A list of some
  +and put it to the appropriate place under $HOME/rfloppy. A list of some
   possible extensions: 
   
   * devfsd (
   
   http://ftp.kernel.org/pub/linux/daemons/devfsd/
   
  -) is not necessary for the bootfloppy, even if you use devfs. So
  +) is not necessary for the bootfloppy, devfs work fine without it. So
   install it only if you know what you are doing. However, it needs to be
   hacked to get it compiled against uClibc. There is a patch for devfsd at 
   
  @@ -408,10 +410,6 @@
   and the svga vncviewer to the floppy, giving the bootfloppy the
   capabilities of an X terminal.
   
  -* gpm, the console mouse daemon is quite a comfortable utility for a 
  -bootfloppy as well. Its installation is covered by the svnc-x_terminal 
  -hint.
  -
   * You can put tinylogin (
   
   http://tinylogin.busybox.net/
  @@ -440,57 +438,79 @@
   
   Put a floppy to the floppy drive. If you use the mkbootdisk script,
   check whether the device name of the floppy drive is set correctly in
  -the script (it is set to /dev/fd0 and it cannot be changed by an option,
  -and it's deliberately this way), and (supposed you are at $HOME) simply
  -run 
  +the script (it is set to /dev/fd0 and no option can change it, in order
  +to prevent the bootdisk user in being able to muck up the development
  +platform), and whether the $MKE2FSAPP, $RDEVAPP variables in the script
  +store the correct path to the mke2fs, rdev utilities in your system. If
  +everything is fine, simply run 
   
  +cd &&
   sudo mkbootdisk
   
   If you don't use the mkbootdisk script, become root, store the name of
  -your floppy device (typically /dev/fd0) in the variable $DISK, and type the
  -following:
  +your floppy device (typically /dev/fd0) in the variable $DISK. Now its
  +time to find out how big the root filesystem of the floppy should be,
  +and how much inodes should it have. Concerning the size, I think the
  +size of the stuff in the rfloppy directory + 150k is enough; concerning
  +the number of inodes, I think the number of files in rfloppy + 100 is
  +enough. But you should know. Store the chosen filesystem size in the
  +variable $SIZE (the number of kilobytes), and the chosen number of
  +inodes in the variable $INODES. Then type the following:
   
   cd $BDISKHOME &&
  +# We we create and compress the root filesystem of the floppy:
  +dd if=/dev/zero of=rootfs bs=1k count=$SIZE &&
  +yes | mke2fs -m 0 -N $INODES rootfs &&
  +mkdir -p loop &&
  +mount rootfs -o loop loop &&
  +rmdir loop/lost+found &&
  +cp -a rfloppy/* loop &&
  +chown -R 0:0 loop/* &&
  +umount loop &&
  +dd if=rootfs bs=1k | gzip -v9 > rootfs.gz 
  +
  +Now check whether rootfs.gz and your kernel image
  +(linux-2.4.*/arch/i386/boot/bzImage) fit on a floppy together (a floppy
  +is of 1440k usually but it can be formatted to bigger sizes as well). If
  +everything is fine, go on:
  +
   # We copy the kernel to the floppy:
  -records=`dd \
  - if=linux-2.4.*/arch/i386/boot/bzImage of=$DISK bs=1k 2>&1 | grep in | \
  - egrep -o '^[0-9][0-9]*'` &&
  +let KERNELSIZE=`dd bs=1k of=$DISK < linux-2.4.*/arch/i386/boot/bzImage 2>&1 | 
  + sed -n '1s%\([0-9][0-9]*\).*%\1%p'`+1 &&
   # We perform some adjustments on the kernel copied to the floppy:
   rdev $DISK $DISK &&
   rdev -R $DISK 0 &&
  -rdev -r $DISK `expr 16385 + $records` &&
  -# Now we compress the filesystem:
  -mkdir -p loop2 &&
  -cp rfloppy rfloppy2 &&
  -mount rfloppy2 -o loop loop2 &&
  -chown -R 0:0 loop2/* &&
  -umount loop2 &&
  -dd if=rfloppy2 bs=1k | gzip -v9 > rootfs.gz  &&
  +rdev -r $DISK `expr 16384 + $KERNELSIZE` &&
   # Finally we copy the compressed filesystem to its appropriate place \
   # on the floppy:
  -dd if=rootfs.gz of=$DISK bs=1k seek=`expr $records + 1`
  +dd if=rootfs.gz of=$DISK bs=1k seek=$KERNELSIZE
   
   [Explanation -- also for those who wonder how the mkbootdisk script
   works
   
  +"yes | mke2fs -m 0 -N $INODES rootfs":
  +
  +This pipe construct is a common trick for answering stupid questions
  +non-interactively.
  +
   "# We copy the kernel to the floppy" :
   
   In the command after this comment we not only copy the kernel to floppy,
   but we also store the number of transferred kb's in the variable
  -$records.
  +$KERNELSIZE.
   
   "# We perform some adjustments on the kernel copied to the floppy" :
   
   We won't have a bootloader to tell the kernel where to find its root
  -filesystem. The commands after this comment set some specified bits in
  -the kernel, thus hardwiring the location of the root filesystem to it:
  -firstly, we tell the kernel to seek for the filesystem in the floppy,
  -secondly, we tell the kernel that a ramdisk is to be made and the
  -filesystem is to put on it, thirdly, we tell the kernel the location of
  -the filesystem within the floppy. The number 16385 = 2^14 + 1 is used
  -for shifting within the range of bits in the kernel devoted for
  -describing these data. For more information consult with the Bootdisk
  -HOWTO available at tldp.org. 
  +filesystem. The commands after this comment set some specified bits
  +in the kernel, thus hardwiring the location of the root filesystem to
  +it: firstly, we tell the kernel to seek for the filesystem in the
  +floppy, secondly, we tell the kernel that a ramdisk is to be made and
  +the filesystem is to be decompressed to it, thirdly, we tell the
  +kernel the location of the filesystem within the floppy. The number
  +16385 = 2^14 + 1 is used for shifting within the range of bits in the
  +kernel devoted for describing these data. For more information
  +consult with the Bootdisk HOWTO available at tldp.org. 
   
   "# Finally we copy [...]" :
   
  @@ -499,8 +519,8 @@
   
   Now you have the floppy, boot & enjoy! 
   
  -Credits, bugs and weirdnesses
  ------------------------------
  +Credits, contributions, bugs and weirdnesses
  +--------------------------------------------
   
   See it in the svnc-x_terminal hint.
   
  @@ -510,91 +530,54 @@
   
   
   
  -Appendix A -- the loopmnt script
  ---------------------------------
  -
  -%%%<loopmnt>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  -#!/bin/bash
  -
  -# Script for letting the bootdisk creator user do some mounts
  -
  -AUTH=bootdisk 
  -# AUTHGRP=bootdisk 
  -# name/group of user to create the bootdisks -- latter not used actually
  -
  -
  -if [ "$#" = 0 -o "$#" -gt 2 -o "$1" = "-h" -o "$1" = "--help" ]
  -then
  - echo Usage:
  - echo to mount: `basename $0` filesystem mountpoint
  - echo to unmount: `basename $0` mountpoint 
  - exit 1
  -fi
  -
  -# noauth -- exits in case of authoritization problem
  -
  -noauth()
  -{
  -echo You are up to something which is not permitted for you
  -exit 1
  -}
  -
  -
  -
  -if [ "$#" = 2 ]
  -then 
  - fs=$1
  - mountpt=$2
  - [ `ls -l $fs |awk '{print $3}'` = "$AUTH" ] || noauth
  - mount "$fs" -o loop "$mountpt"
  - exit 0
  -elif [ "$#" = 1 ]
  -then 
  - mountpt=$1 
  - umount $mountpt
  - exit 0
  -fi 
  -
  -exit 1
  -%%%</loopmnt>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  -
  -
  -Appendix B -- the mkbootdisk script
  +Appendix A -- the mkbootdisk script
   -----------------------------------
   
  +If you copy and paste the script below to a separate file, be careful
  +that line-terminating backslashes (\) will keep their position in the
  +separate file (no whitespace characters should follow them).
  +
   %%%<mkbootdisk>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   #!/bin/bash
   
   #
   # A script for making the bootdisk creation process easy and safe 
   #
  -#
  +# If you develop your own floppy linux, then it is advised to do it as a 
  +# non-privileged user (in order to not suck if you happen to do
  +# something  stupid :), and use this (root owned and executable) script
  +# via the sudo utility. 
   
   # Below are some values set. Adjust them if necessary.
   
   
  -AUTH=bootdisk  # name of user who is  to use the script
  -# $AUTH is advised to be a nonprivileged user who does the risky job of
  -# maintaining the bootscript stuff; this script is for getting the
  -# privilege-needed steps of bootdisk making done 
  -AUTHGRP=bootdisk
   DISK=/dev/fd0
  -FSFILE=rfloppy
  -FSGZ=/tmp/rootfs.gz.$$
  +DEVICE=$DISK
  +FSDIR=rfloppy
  +FSGZ=/tmp/mkbootdisk-rootfs.gz.$$
   KERNEL=linux-`uname -r`/arch/i386/boot/bzImage
  -TOADD=16385 # Comes from kernel internals, do no change!
  -RDEVAPP=/usr/sbin/rdev
  -MKBOOTREC=$HOME/.mkbootdisk.records
  +TOADD=16384 # Comes from kernel internals, do no change!
  +MKE2FSAPP=/sbin/mke2fs
  +RDEVAPP=/usr/sbin/rdev # The $MKE2FSAPP and $RDEVAPP variables contain \
  +# an absolute path because of the following: \
  +# by my idea this script is used by a non-privileged user (via sudo) \
  +# whose path does not contain the mke2fs, rdev executables 
  +MKBOOTREC=$HOME/.mkbootdisk
  +EXTRA_SIZE=150 # Free space left on root filesystem of floppy
  +EXTRA_INODES=100 # Free inodes left on filesystem of floppy
  +FLOPPYSIZE=1440
  +VERSION="0.1.1"
   
   # Do not edit what follows unless your intention is hacking!
   
  -ClearFSGZ=yes # Any value other than "no" implies the deletion of $FSGZ
  +#ClearFSGZ=yes # Any value other than "no" implies the deletion of $FSGZ
   firstcheck=yes  
   compress=yes # Any value other than "no" defaults to production of a \
   #gzipped rootfs 
  -fscheck=no #The value "yes" defaults to checking the filesystem before \
  -#compression
  -[ -e "$MKBOOTREC" ] && records=`cat "$MKBOOTREC"`
  +KERNELSIZE=x
  +[ -s "$MKBOOTREC" ] && KERNELSIZE=`cat "$MKBOOTREC"`
  +dokernelcopy=no
  +unset tmpfiles # tmpfiles are to be removed after all
   
   #
   # Usage
  @@ -602,34 +585,51 @@
   
   if [ "$1" = "-h" -o "$1" = "--help" ]
   then 
  - echo --------
  - echo Bootdisk creation utility. Usage:
  - echo With -h or --help being the 1st arg, this help is shown
  - echo
  - echo \
  -`basename $0` -k kernelimg -f filesys -r \
  -kernelimg_size [-g gzipped_filesys -n -c] 
  - echo
  - echo Default values are: 
  - echo  \-k $KERNEL 
  - echo  \-f $FSFILE 
  - echo  \-r \`cat \~/`basename "$MKBOOTREC"`\` 
  -  #-l $LOOP #-d $DISK 
  - echo
  - echo Switches:
  - echo \
  - "-n	compression skipped [the compressed filesys is to be given by -g]"
  - echo "-c	check filesys"  
  - echo 
  - echo Further comments:
  - echo "\
  --r size  a kernelimg of the given size (in kb) is supposed to be on the disk," 
    echo "\
  -         kernel copying is skipped"
  - echo "If -g used, gzipped_filesys is kept, otherwise deleted"
  - echo "If kernel is copied, its size is stored in ~/`basename ${MKBOOTREC}`" 
  - echo "(delete that file before using a new kernel image!!)"
  - echo --------
  +--------
  +Bootdisk creation utility, version $VERSION. Usage:
  +With -h or --help being the 1st arg, this help is shown; otherwise
  +
  +`basename $0` -k kernelimg -f filesys_dir -s filesys_size -i filesys_inodes \\
  +-r kernelimg_size -c floppy_size [-g gzipped_filesys -d]
  +
  +where \"kernelimg\" is the linux kernel image to be booted by the floppy,
  +and \"filesys_dir\" contains the files to be put in the root filesystem.
  +
  +Default values are: 
  +-k $KERNEL 
  +-f $FSDIR 
  +-s <size of files in filesys_dir + ${EXTRA_SIZE}k> 
  +-i <number of files in filesys_dir + ${EXTRA_INODES}>
  +-r \`cat ~/`basename "$MKBOOTREC"`\`, or x if ~/`basename \
  +"$MKBOOTREC"` is empty or does not exist 
  +-c $FLOPPYSIZE
  +
  +Explanations of options:
  +-r kernelimg_size	a kernelimg of the given size (in kb) is supposed to be
  + 			on the disk and kernel copying is skipped, unless size 
  +			is x instead of a number
  +-g gzipped_filesys	gzipped_filesys is copied to the disk
  +			(instead of the contents of filesys_dir)
  +-d  			the floppyimage is written to stdout instead of $DISK
  +-c floppy_size 		if the floppy image were bigger than floppy_size 
  +			(in kb), the process is aborted, unless floppy_size is 
  +			x instead of a number
  +
  +Further comments:
  +
  +If kernel is copied, its size is stored in ~/`basename ${MKBOOTREC}` 
  +(delete that file before using a new kernel image, or use -r x !!)
  +
  +Example:
  +* A compressed filesystem is produced from the contents of filesys_dir by
  +	`basename $0` -r 0 -d > rootfs.gz
  +* A floppy can be made using this compressed filesystem by
  +	`basename $0` -g rootfs.gz
  +
  +And please avoid using space cakes in filenames :)
  +--------"
  + exit 1
   fi
   
   
  @@ -637,17 +637,18 @@
   # Getting options
   #
   
  -while getopts "g:k:f:l:r:nh" option
  +while getopts "g:k:f:dr:c:s:i:" option
   do
    case $option in 
     g) FSGZ=$OPTARG
  -     ClearFSGZ=no;;
  +     compress=no;;
     k) KERNEL=$OPTARG;;
  -  f) FSFILE=$OPTARG;;
  -#  d) DISK=$OPTARG;;       Too dangerous to let it set
  -  r) records=$OPTARG;;
  -  n) compress=no;;
  -  c) fscheck=yes;;
  +  f) FSDIR=$OPTARG;;
  +  d) DEVICE="&1";;
  +  r) KERNELSIZE=$OPTARG ;;
  +  c) FLOPPYSIZE=$OPTARG;;
  +  i) INODES=$OPTARG;; 
  +  s) SIZE=$OPTARG;;
     *) exit 1;;
    esac
   done
  @@ -668,8 +669,28 @@
   gzipimp()
   {
    dd if=$1 bs=1k | gzip -v9 > $2
  +# I could not figure out why it is the way to do gzipping, but this is
  +# what is suggested by the clever guys. I'd be happy to be informed
  +# about it...
  +} #Be careful! Changing it might break check()
  +
  +#cleanup -- removes temporary files
  +
  +cleanup()
  +{
  + [ -z "$tmpfiles" ] || echo "Removing temporary files..." >&2 
  + rm -rf $tmpfiles >&2 
   }
   
  +#error -- if something goes wrong... 
  +
  +error()
  +{
  + echo Error: "$1" >&2
  + cleanup
  + exit 1
  +} 
  +
   #
   # Important fnc's
   
  @@ -678,113 +699,151 @@
   
   check()
   {
  - if [ "$compress" != no ]  # checking whether the rootfs is mounted correctly
  + for v in RDEVAPP MKE2FS # Checking whether these apps can be found
  + do
  +  [ -x `eval echo \\$$v` ] ||
  +  error \
  +  "the value of \$$v is wrong -- `eval echo \\$$v` is not an executable"
  + done
  +
  + for v in SIZE INODES # Syntax check of variables
  + do
  +  [ -z `eval echo \\$$v` ] ||
  +  [ `eval echo \\$$v` -ge 0 ] &>/dev/null || 
  +  error "wrong value for option -- \$$v is not non-negative integer"  
  + done
  +
  + for v in FLOPPYSIZE KERNELSIZE
  + do 
  +  [ `eval echo \\$$v` = x ] ||
  +  [ `eval echo \\$$v` -ge 0 ] &>/dev/null ||
  +  error "Wrong value for option -- \$$v is neither x, nor non-negative \
  +integer"
  + done
  +
  + if [ "$compress" != no ]  # checking whether $FSDIR is a directory
    then 
  -  if file -L $FSFILE | grep "ext2 filesystem data" >/dev/null 
  -  then :
  -  else
  -    echo Error: $FSFILE is not an ext2 filesystem
  -   exit 1
  -  fi
  +  [ -d $FSDIR ] ||
  +  error "$FSDIR is not a directory (symlinks are not supported)"
    fi
   
  - if [ -z "$records" ]  #checking whether the kernelimg exists
  + if [ "$KERNELSIZE" = x ]  #checking whether the kernelimg exists
    then 
  -  if file -L $KERNEL |grep 'x86 boot sector' >/dev/null 
  -  then :
  -  else
  -   echo Error: $KERNEL is not a kernelimg. >&2 
  -   exit 1
  -  fi
  - else
  +  file -L $KERNEL |grep 'x86 boot sector' >/dev/null || 
  +  error "$KERNEL is not a kernelimg." 
  + else 
     [ "$firstcheck" = yes ] && 
  -  echo "A kernelimg of size $records is supposed to be on the disk" 
  +  echo "A kernelimg of size $KERNELSIZE is supposed to be on the disk" >&2 
    fi
    
    if [ "$compress" = no ] #checking whether the gzipped fs exists
    then  
  -  if  file -L $FSGZ | grep \
  -  'gzip compressed data, from Unix, max compression'>/dev/null 
  -  then :
  -  else	
  -   echo Error: $FSGZ is not a gzipped file >&2
  -   exit 1
  -  fi
  +  file -L $FSGZ | grep \
  +  'gzip compressed data, from Unix, max compression'>/dev/null || 
  +  error "$FSGZ is not a gzipped file"
  +  [ "$firstcheck" = yes ] && 
  +  echo "An existing compressed filesystem is used as root filesystem,
  +filesystem creation is skipped." >&2 
    fi
   
    firstcheck= 
   }
   
  +# getfsdata -- Finds out size and inode number param's of the filesystem
  +# to be created
   
  +getfsdata()
  +{
  + [ -z "$SIZE" ] &&
  + SIZE=$(expr $EXTRA_SIZE + `du -s $FSDIR | awk '{print $1}'`)
  +
  + [ -z "$INODES" ] &&
  + INODES=$(expr $EXTRA_INODES + `find $FSDIR | wc -l`)
  +}
   
   # compressfs -- Adjusts and compresses the filesystem
  +# (Now also creates the filesys but the name is kept)
   
   compressfs()
   {
    [ "$compress" = no ] && return 0
    compress=no
   
  - tmpfile=/tmp/rfloppy.$$
  - tmpmountpt=/tmp/mountpt.$$
  -
  - cp $FSFILE $tmpfile
  - if [ "$fscheck" = yes ] 
  - then 
  -  fsck $tmpfile &&
  -  echo Filesystem checked
  - fi 
  + tmpfs=/tmp/mkbootdisk-rfloppy.$$
  + tmpmountpt=/tmp/mkbootdisk-mountpt.$$
  + tmpfiles="$tmpfiles $tmpfs $tmpmountpt"
  + 
  + echo \
  + "Creating an ext2 filesystem of size ${SIZE}k and with $INODES inodes" >&2
  + dd if=/dev/zero of=$tmpfs bs=1k count=$SIZE
  + yes | $MKE2FSAPP -m 0 -N $INODES $tmpfs > /dev/null 
    mkdir -p $tmpmountpt
  - mount $tmpfile -o loop $tmpmountpt
  + mount $tmpfs -o loop $tmpmountpt
  + rmdir $tmpmountpt/lost+found 
  + cp -a $FSDIR/* $tmpmountpt
    chown -R 0:0 $tmpmountpt/*
    if umount $tmpmountpt 
    then
  -  echo "Compressing the rootfs..."
  -  gzipimp $tmpfile $FSGZ
  +  echo "Compressing the file system..." >&2
  +  gzipimp $tmpfs $FSGZ
  +   tmpfiles="$tmpfiles $FSGZ" 
    else
  -  echo "Some problem occured with unmounting the rootfs."
  +  error "some problem occured with unmounting the file system."
    fi
  - chown $AUTH:$AUTHGRP $FSGZ
  - rmdir $tmpmountpt
  - rm $tmpfile 
   }
   
  -# kernelcopy -- copies and isntalls the kernelimg to disk
   
  -kernelcopy()
  +# floppysizecheck -- checks whether will be enough space on floppy
  +
  +floppysizecheck()
   {
  - [ -z "$records" ] || return 0
  - 
  - echo Copying the kernelimg...
  - records=`dd if=$KERNEL of=$DISK bs=1k 2>&1 | grep in | egrep -o '^[0-9][0-9]*'`
  - if [ -z "$records" ] 
  - then
  -  echo "Error: it seems that there is some problem with the disk." >&2
  -  exit 1
  - else
  -  echo $records > $MKBOOTREC 
  - fi
  - echo ${records}+1 records in/out
  - 
  - echo Adjusting the kernelimg to mount $FSFILE as rootfs... 
  - $RDEVAPP $DISK $DISK
  - $RDEVAPP -R $DISK 0
  - $RDEVAPP -r $DISK `expr $TOADD + $records`
  + [ $FLOPPYSIZE = x ] && return 0
  + FSGZSIZE=$(( `dd if=$FSGZ of=/dev/null bs=1k 2>&1 |
  +  sed -n '1s%\([0-9][0-9]*\).*%\1%p'` + 1 ))
  + [ $(($KERNELSIZE + $FSGZSIZE)) -gt $FLOPPYSIZE ] &&
  + error "
  +size of kernel: 	       $KERNELSIZE
  +size of compressed filesystem: $FSGZSIZE
  +are altogether:		       $KERNELSIZE + $FSGZSIZE = \
  +$(($KERNELSIZE + $FSGZSIZE))
  +which exceeds your floppy size ($FLOPPYSIZE)"
   }
   
  -# rootfscopy -- copies the rootfs to disk
  +# kernelcopy -- copies and installs the kernelimg to disk
   
  -rootfscopy()
  +kernelcopy()
   {
  - echo Copying the rootfs...
  + [ $KERNELSIZE = x ] || return 0
  + 
  + tmpdiskimg=/tmp/mkbootdisk-diskimg.$$ 
  + KERNELSIZE=$(( `dd if=$KERNEL of=$tmpdiskimg bs=1k 2>&1 |
  + sed -n '1s%\([0-9][0-9]*\).*%\1%p'` + 1 )) 
  + tmpfiles="$tmpfiles $tmpdiskimg"
  +
  + echo Adjusting the kernelimg to mount the file system as rootfs... >&2 
  + $RDEVAPP $tmpdiskimg $DISK # I hope it's OK for values of $DISK other \
  +# than /dev/fd0
  + $RDEVAPP -R $tmpdiskimg 0
  + $RDEVAPP -r $tmpdiskimg `expr $TOADD + $KERNELSIZE`
  + dokernelcopy=yes
  +}
   
  - if dd if=$FSGZ of=$DISK bs=1k seek=`expr $records + 1` 
  - then :
  +diskwrite()
  +{
  + if [ $dokernelcopy = yes ]
  + then 
  +  echo "Creating the diskimage..." >&2
  +  dd if=$FSGZ of=$tmpdiskimg bs=1k seek=$KERNELSIZE 
  +  echo Writing the diskimage to device... >&2
  +  eval "dd if=$tmpdiskimg bs=1k >$DEVICE" 
  + elif [ $dokernelcopy = no ] 
  + then
  +  echo Writing the compressed file system to device... >&2
  +  eval "dd if=$FSGZ bs=1k seek=$KERNELSIZE >$DEVICE"
    else
  -  echo "Error: it seems that there is some problem with the disk." >&2 
  -  exit 1
  - fi
  -  
  - [ "$ClearFSGZ" = no ] || rm $FSGZ 
  +  error 'bogus value for $dokernelcopy' 
  + fi || 
  + error "it seems that there is some problem with the target device."
   }
   
   
  @@ -793,11 +852,15 @@
   #
   
   check
  +getfsdata
   compressfs
   kernelcopy
  +floppysizecheck
   check
  -rootfscopy
  +diskwrite
  +cleanup
   exit 0
   %%%</mkbootdisk>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  +
   
   END of "uClibc-based bootfloppy" hint
  
  
  
-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe hints' in the subject header of the message



More information about the hints mailing list