Previous Next Contents

8. Samples

8.1 Disk Directory Listings

This lists the contents of directories from my root and utility diskettes. These lists are provided as an example only of the files included to create a working system. I have added some explanatory notes where it seemed useful.

Root Disk ls-lR Directory Listing

total 18
drwxr-xr-x   2 root     root         1024 Jul 29 21:16 bin/
drwxr-xr-x   2 root     root         9216 Jul 28 16:21 dev/
drwxr-xr-x   3 root     root         1024 Jul 29 20:25 etc/
drwxr-xr-x   2 root     root         1024 Jul 28 19:53 lib/
drwxr-xr-x   2 root     root         1024 Jul 24 22:47 mnt/
drwxr-xr-x   2 root     root         1024 Jul 24 22:47 proc/
drwxr-xr-x   2 root     root         1024 Jul 28 19:07 sbin/
drwxr-xr-x   2 root     root         1024 Jul 29 20:57 tmp/
drwxr-xr-x   4 root     root         1024 Jul 29 21:35 usr/
drwxr-xr-x   3 root     root         1024 Jul 28 19:52 var/

bin:
total 713
-rwxr-xr-x   1 root     bin          7737 Jul 24 22:16 cat*
-rwxr-xr-x   1 root     bin          9232 Jul 24 22:48 chmod*
-rwxr-xr-x   1 root     bin          8156 Jul 24 22:48 chown*
-rwxr-xr-x   1 root     bin         19652 Jul 24 22:48 cp*
-rwxr-xr-x   1 root     root         8313 Jul 29 21:16 cut*
-rwxr-xr-x   1 root     bin         12136 Jul 24 22:48 dd*
-rwxr-xr-x   1 root     bin          9308 Jul 24 22:48 df*
-rwxr-xr-x   1 root     root         9036 Jul 29 20:24 dircolors*
-rwxr-xr-x   1 root     bin          9064 Jul 24 22:48 du*
-rwxr-x---   1 root     bin         69252 Jul 24 22:51 e2fsck*
-rwxr-xr-x   1 root     bin          5361 Jul 24 22:48 echo*
-rwxr-xr-x   1 root     bin          5696 Jul 24 22:16 hostname*
-rwxr-xr-x   1 root     bin          6596 Jul 24 22:49 kill*
-rwxr-xr-x   1 root     bin         10644 Jul 24 22:17 ln*
-rwxr-xr-x   1 root     bin         13508 Jul 24 22:17 login*
-rwxr-xr-x   1 root     bin         26976 Jul 24 22:17 ls*
-rwxr-xr-x   1 root     bin          7416 Jul 24 22:49 mkdir*
-rwxr-x---   1 root     bin         34596 Jul 24 22:51 mke2fs*
-rwxr-xr-x   1 root     bin          6712 Jul 24 22:49 mknod*
-rwxr-xr-x   1 root     bin         20304 Jul 24 22:17 more*
-rwxr-xr-x   1 root     bin         24704 Jul 24 22:17 mount*
-rwxr-xr-x   1 root     bin         12464 Jul 24 22:17 mv*
-rwxr-xr-x   1 root     bin         20829 Jul 24 22:50 ps*
-rwxr-xr-x   1 root     bin          9424 Jul 24 22:50 rm*
-rwxr-xr-x   1 root     bin          4344 Jul 24 22:50 rmdir*
-rwxr-xr-x   1 root     root       299649 Jul 27 14:12 sh*
-rwxr-xr-x   1 root     bin          9853 Jul 24 22:17 su*
-rwxr-xr-x   1 root     bin           380 Jul 27 14:12 sync*
-rwxr-xr-x   1 root     bin         13620 Jul 24 22:17 umount*
-rwxr-xr-x   1 root     root         5013 Jul 29 20:03 uname*

dev:
total 0
lrwxrwxrwx   1 root     root           10 Jul 24 22:34 cdrom -> /dev/sbpcd
crw--w--w-   1 root     tty        4,   0 Jul 24 21:49 console
brw-rw----   1 root     floppy     2,   0 Apr 28  1995 fd0
lrwxrwxrwx   1 root     root            4 Jul 24 22:34 ftape -> rft0
crw-rw-rw-   1 root     sys       10,   2 Jul 18  1994 inportbm
crw-rw----   1 root     kmem       1,   2 Jul 28 16:21 kmem
crw-rw----   1 root     kmem       1,   1 Jul 18  1994 mem
lrwxrwxrwx   1 root     root            4 Jul 24 22:34 modem -> cua0
lrwxrwxrwx   1 root     root            4 Jul 24 22:34 mouse -> cua1
crw-rw-rw-   1 root     sys        1,   3 Jul 18  1994 null
brw-rw----   1 root     disk       1,   1 Jul 18  1994 ram
crw-rw----   1 root     disk      27,   0 Jul 18  1994 rft0
brw-rw----   1 root     disk      25,   0 Jul 19  1994 sbpcd
***  I have only included devices for the SCSI partitions I use.
***  If you use IDE, then use /dev/hdxx instead.
brw-rw----   1 root     disk       8,   0 Apr 29  1995 sda
brw-rw----   1 root     disk       8,   6 Apr 29  1995 sda6
brw-rw----   1 root     disk       8,   7 Apr 29  1995 sda7
brw-rw----   1 root     disk       8,   8 Apr 29  1995 sda8
lrwxrwxrwx   1 root     root            7 Jul 28 12:56 systty -> console
***  this link from systty to console is required
crw-rw-rw-   1 root     tty        5,   0 Jul 18  1994 tty
crw--w--w-   1 root     tty        4,   0 Jul 18  1994 tty0
crw--w----   1 root     tty        4,   1 Jul 24 22:33 tty1
crw--w----   1 root     tty        4,   2 Jul 24 22:34 tty2
crw--w--w-   1 root     root       4,   3 Jul 24 21:49 tty3
crw--w--w-   1 root     root       4,   4 Jul 24 21:49 tty4
crw--w--w-   1 root     root       4,   5 Jul 24 21:49 tty5
crw--w--w-   1 root     root       4,   6 Jul 24 21:49 tty6
crw-rw-rw-   1 root     tty        4,   7 Jul 18  1994 tty7
crw-rw-rw-   1 root     tty        4,   8 Jul 18  1994 tty8
crw-rw-rw-   1 root     tty        4,   9 Jul 19  1994 tty9
crw-rw-rw-   1 root     sys        1,   5 Jul 18  1994 zero

etc:
total 20
-rw-r--r--   1 root     root         2167 Jul 29 20:25 DIR_COLORS
-rw-r--r--   1 root     root           20 Jul 28 12:37 HOSTNAME
-rw-r--r--   1 root     root          109 Jul 24 22:57 fstab
-rw-r--r--   1 root     root          271 Jul 24 22:21 group
-rw-r--r--   1 root     root         2353 Jul 24 22:27 inittab
-rw-r--r--   1 root     root            0 Jul 29 21:02 issue
-rw-r--r--   1 root     root         2881 Jul 28 19:38 ld.so.cache
***  Lots of things get upset at boot time if ld.so.cache is missing, but
***  make sure that ldconfig is included and run from rc.x to
***  update it.
-rw-r--r--   1 root     root           12 Jul 24 22:22 motd
-rw-r--r--   1 root     root          606 Jul 28 19:25 passwd
-rw-r--r--   1 root     root         1065 Jul 24 22:21 profile
drwxr-xr-x   2 root     root         1024 Jul 29 21:01 rc.d/
-rw-r--r--   1 root     root           18 Jul 24 22:21 shells
-rw-r--r--   1 root     root          774 Jul 28 13:43 termcap
-rw-r--r--   1 root     root          126 Jul 28 13:44 ttys
-rw-r--r--   1 root     root            0 Jul 24 22:47 utmp

etc/rc.d:
total 5
*** I didn't bother with shutdown scripts - everthing runs on a 
*** ramdisk, so there's not much point shutting it down.
-rwxr-xr-x   1 root     root         1158 Jul 24 22:23 rc.K*
-rwxr-xr-x   1 root     root         1151 Jul 28 19:08 rc.M*
-rwxr-xr-x   1 root     root          507 Jul 29 20:25 rc.S*

lib:
total 588
*** I have an ELF system, so I include the ELF loader ld-linux.so. if
*** you are still on a.out, then you need ld.so. Use the file command to
*** see which libraries you should include.
lrwxrwxrwx   1 root     root           17 Jul 24 23:36 ld-linux.so.1 -> ld-linux.so.1.7.3*
-rwxr-xr-x   1 root     root        20722 Aug 15  1995 ld-linux.so.1.7.3*
lrwxrwxrwx   1 root     root           13 Jul 24 23:36 libc.so.5 -> libc.so.5.0.9*
-rwxr-xr-x   1 root     root       562683 May 19  1995 libc.so.5.0.9*
***  Must include libtermcap
lrwxrwxrwx   1 root     root           19 Jul 28 19:53 libtermcap.so.2 -> libtermcap.so.2.0.0*
-rwxr-xr-x   1 root     root        11360 May 19  1995 libtermcap.so.2.0.0*

mnt:
total 0

proc:
total 0

sbin:
total 191
***  I use Slackware, which uses agetty. Many systems use getty. 
***  Check your /etc/inittab to see which it uses. Note that you
***  need (a)getty and login to be able to start doing much.
-rwxr-xr-x   1 root     bin         11309 Jul 24 22:54 agetty*
-rwxr-xr-x   1 root     bin          5204 Jul 24 22:19 halt*
***  Must have this to boot
-rwxr-xr-x   1 root     bin         20592 Jul 24 22:19 init*
-rwxr-xr-x   1 root     root        86020 Jul 28 19:07 ldconfig*
-rwxr-xr-x   1 root     bin          5329 Jul 27 14:10 mkswap*
-rwxr-xr-x   1 root     root         5204 Jul 24 22:20 reboot*
-rwxr-xr-x   1 root     bin         12340 Jul 24 22:20 shutdown*
-rwxr-xr-x   1 root     root         5029 Jul 24 22:20 swapoff*
-rwxr-xr-x   1 root     bin          5029 Jul 24 22:20 swapon*
-rwxr-xr-x   1 root     root        20592 Jul 27 18:18 telinit*
-rwxr-xr-x   1 root     root         7077 Jul 24 22:20 update*

tmp:
total 0

usr:
total 2
drwxr-xr-x   2 root     root         1024 Jul 29 21:00 adm/
drwxr-xr-x   2 root     root         1024 Jul 29 21:16 lib/

usr/adm:
total 0

usr/lib:
total 0

var:
total 1
***  Several things complained until I included this and 
***  the /etc/rc.S code to initialise /var/run/utmp, but this
***  won't necessarily apply to your system.
drwxr-xr-x   2 root     root         1024 Jul 28 19:52 run/

var/run:
total 0

Utility Disk ls-lR Directory Listing

total 579
-rwxr-xr-x   1 root     root        42333 Jul 28 19:05 cpio*
-rwxr-xr-x   1 root     root       103560 Jul 29 21:31 elvis*
-rwxr-xr-x   1 root     root        56401 Jul 28 19:06 find*
-rw-r--r--   1 root     root       128254 Jul 28 19:03 ftape.o
-rwxr-xr-x   1 root     root        64161 Jul 29 20:47 grep*
-rwxr-xr-x   1 root     root        45309 Jul 29 20:48 gzip*
-rwxr-xr-x   1 root     root        23560 Jul 28 19:04 insmod*
-rwxr-xr-x   1 root     root          118 Jul 28 19:04 lsmod*
lrwxrwxrwx   1 root     root            5 Jul 28 19:04 mt -> mt-st*
-rwxr-xr-x   1 root     root         9573 Jul 28 19:03 mt-st*
lrwxrwxrwx   1 root     root            6 Jul 28 19:05 rmmod -> insmod*
-rwxr-xr-x   1 root     root       104085 Jul 28 19:05 tar*
lrwxrwxrwx   1 root     root            5 Jul 29 21:35 vi -> elvis*

8.2 Shell Scripts to Build Diskettes

These shell scripts are provided as examples only. I use them on my system to create rescue diskettes. You may find it convenient to use them, but if so, read the instructions carefully - for example, if you specify the wrong swap device, you will find your root filesystem has been throroughly and permanently erased.... so just be darn sure you have it correctly configured before you use it!

The upside of the scripts are that they provide a quick way to get a rescue set together, by doing the following:

There are two shell scripts:

Both are currently configured to run in the parent directory of boot_disk and util_disk, each of which contains everything to be copied to it's diskette. Note that these shell scripts will *NOT* automatically set up and copy all the files for you - you work out which files are needed, set up the directories and copy the files to those directories. The shell scripts are samples which will copy the contents of those directories. Note that they are primitive shell scripts and are not meant for the novice user.

The scripts both contain configuration variables at the start which allow them to be easily configured to run anywhere. First, set up the model directories and copy all the required files into them. To see what directories and files are needed, have a look at the sample directory listings in the previous sections.

Check the configuration variables in the shell scripts and change them as required before running the scripts.

mkroot - Make Root Diskette


# mkroot: make a root disk - creates a root diskette
#         by building a file system on it, then mounting it and
#         copying required files from a model.
#         Note: the model to copy from from must dirst be set up,
#         then change the configuration variables below to suit
#         your system.
#
# usage: mkroot [ -d swap | ram ]
#       where swap means use $SWAPDEV swap device
#       and ram means use $RAMDISKDEV ramdisk device

# Copyright (c) Graham Chapman 1996. All rights reserved.
# Permission is granted for this material to be freely
# used and distributed, provided the source is acknowledged.
# No warranty of any kind is provided. You use this material
# at your own risk.

# Configuration variables - set these to suit your system
#
####  set the device to use to build the root filesystem on.
####  ramdisk is safer - swap is ok only if you have plenty of
####  free memory. If linux can't swap then things get nasty.
USEDEVICE="ramdisk"             # set to either "ramdisk" or "swap"
RAMDISKDEV="/dev/ram"           # ramdisk device <==== CHANGE if using ramdisk
SWAPDEV="/dev/sda7"             # swap device    <==== CHANGE if using swap
FSBLOCKS=3072                   # desired filesystem size in blocks
#
####  set name or directory where you have set up your rootdisk
####  model
ROOTDISKDIR="./root_disk"       # name of root disk directory
MOUNTPOINT="/mnt"               # temporary mount point for diskette
DISKETTEDEV="/dev/fd0"          # device name of diskette drive
LOGFL="`pwd`/mkroot.log"        # log filename
TEMPROOTFS="/tmp/mkrootfs.gz"   # temp file for compressed filesystem
# End of Configuration variables

# Internal variables
ROOTDISKDEV=

case $USEDEVICE in
swap|ramdisk)   :;;
*)      echo "Invalid setting for USEDEVICE variable"
        exit;;
esac

clear
echo "    ***************** W A R N I N G ******************

Use this script with care. If you don't understand it, then
exit NOW!"

if [ "$USEDEVICE" = "swap" ]
then
        ROOTDISKDEV=$SWAPDEV
        echo -e "\nThis script will temporarily remove the swap file $SWAPDEV"
        echo "and use the space to build a compressed root filesystem from"
        echo "the files in the directory tree below $ROOTDISKDIR. To do this"
        echo "safely you must have 8Mb or more of memory, and you should"
        echo "switch to single user mode via 'init 1'."
        echo -e "\nIf you have used a ramdisk since the last reboot, then"
        echo "reboot NOW before using this script."
        echo -e "\nIf the script fails, you may not have a swap partition. Run 'free'"
        echo "and check the total size to see if it is correct. If the swap"
        echo "partition $SWAPDEV is missing, do the following:"
        echo "  umount $MOUNTPOINT"
        echo "  mkswap $SWAPDEV"
        echo "  swapon $SWAPDEV"
        echo "to restore the swap partition $SWAPDEV."
else
        ROOTDISKDEV=$RAMDISKDEV
        echo -e "\nThis script will use a ramdisk of $FSBLOCKS Kb. To do this safely"
        echo "you must have at least 8Mb of memory. If you have only 8Mb you should"
        echo "ensure nothing else is running on the machine."
        echo -e "\nWhen the script is complete, the ramdisk will still be present, so"
        echo "you should reboot to reclaim the memory allocated to the ramdisk."
fi

echo -e "
Do you want to continue (y/n)? \c"
read ans
if [ "$ans" != "Y" -a $ans != "y" ]
then
        echo "not confirmed - aborting"
        exit 
fi

echo "Starting mkroot at `date`" > $LOGFL

if [ "$USEDEVICE" = "swap" ]
then
        echo "Unmounting swap device $SWAPDEV" | tee -a $LOGFL
        swapoff $SWAPDEV >> $LOGFL 2>&1
fi

echo "Zeroing device $ROOTDISKDEV" | tee -a $LOGFL
dd if=/dev/zero of=$ROOTDISKDEV bs=1024 count=$FSBLOCKS >> $LOGFL 2>&1
if [ $? -ne 0 ]
then
        echo "dd zeroing $ROOTDISKDEV failed" | tee -a $LOGFL
        exit 1
fi

echo "Creating filesystem on device $ROOTDISKDEV" | tee -a $LOGFL
mke2fs -m0 $ROOTDISKDEV $FSBLOCKS >> $LOGFL 2>&1

echo "Mounting $ROOTDISKDEV filesystem at $MOUNTPOINT" | tee -a $LOGFL
mount -t ext2 $ROOTDISKDEV $MOUNTPOINT >> $LOGFL 2>&1
if [ $? -ne 0 ]
then
        echo "mount failed"
        exit 1
fi

# copy the directories containing files
echo "Copying files from $ROOTDISKDIR to $MOUNTPOINT" | tee -a $LOGFL
currdir=`pwd`
cd $ROOTDISKDIR
find . -print | cpio -dpumv $MOUNTPOINT >> $LOGFL 2>&1
if [ $? -ne 0 ]
then
        echo "cpio step failed."
        cd $currdir
        exit 1
fi
cd $currdir

fssize=`du -sk $MOUNTPOINT|cut -d"      " -f1`
echo "Uncompressed root filesystem size is $fssize Kb" | tee -a $LOGFL
echo "Unmounting filesystem from $ROOTDISKDEV" | tee -a $LOGFL
umount $MOUNTPOINT >> $LOGFL 2>&1

echo "Compressing filesystem from $ROOTDISKDEV into $TEMPROOTFS
        This may take a few minutes..." | tee -a $LOGFL

#       We don't bother with gzip -9 here - takes more than twice as long
#       and saves less than 1% in space on my root disk...
dd if=$ROOTDISKDEV bs=1024 count=$FSBLOCKS 2>>$LOGFL | gzip -c > $TEMPROOTFS

fssize=`du -k $TEMPROOTFS|cut -d"       " -f1`
echo "Compressed root filesystem size is $fssize Kb" | tee -a $LOGFL

echo -e "Insert diskette in $DISKETTEDEV and press any key
        ***  Warning: data on diskette will be overwritten!\c"
read ans

echo "Copying compressed filesystem from $TEMPROOTFS to $DISKETTEDEV" | tee -a $LOGFL
dd if=$TEMPROOTFS of=$DISKETTEDEV >>$LOGFL 2>&1
if [ $? -ne 0 ]
then
        echo "copy step failed."
        exit 1
fi

if [ "$USEDEVICE" = "swap" ]
then
        echo "Reinitialising swap device $SWAPDEV" | tee -a $LOGFL
        mkswap $SWAPDEV >> $LOGFL 2>&1
        echo "Starting swapping to swap device $SWAPDEV" | tee -a $LOGFL
        swapon $SWAPDEV >> $LOGFL 2>&1
fi

echo "Deleting $TEMPROOTFS" | tee -a $LOGFL
rm $TEMPROOTFS

echo "mkroot completed at `date`" >> $LOGFL

echo "Root diskette creation complete - please read log file $LOGFL"

mkutil - Make Utility Diskette


# mkutil: make a utility diskette - creates a utility diskette
#         by building a file system on it, then mounting it and
#         copying required files from a model.
#         Note: the model to copy from from must first be set up,
#         then change the configuration variables below to suit
#         your system.

# Copyright (c) Graham Chapman 1996. All rights reserved.
# Permission is granted for this material to be freely
# used and distributed, provided the source is acknowledged.
# No warranty of any kind is provided. You use this material
# at your own risk.

# Configuration variables...
UTILDISKDIR=./util_disk         # name of directory containing model
MOUNTPOINT=/mnt                 # temporary mount point for diskette
DISKETTEDEV=/dev/fd0            # device name of diskette drive

echo $0: create utility diskette
echo Warning: data on diskette will be overwritten!
echo Insert diskette in $DISKETTEDEV and and press any key...
read anything

mke2fs $DISKETTEDEV
if [ $? -ne 0 ]
then
        echo mke2fs failed
        exit
fi

# Any file system type would do here
mount -t ext2 $DISKETTEDEV $MOUNTPOINT
if [ $? -ne 0 ]
then
        echo mount failed
        exit
fi

# copy the directories containing files
cp -dpr $UTILDISKDIR/* $MOUNTPOINT

umount $MOUNTPOINT

echo Utility diskette complete


Previous Next Contents