8.3. Construction
8.3.1. Write a "more" script
Create the following script with a text editor and save it as
~/staging/bin/more.sh
#!/bin/sh
#
# more.sh - emulates the basic functions of the "more" binary without
# requiring ncurses or termcap libraries.
#
# Assume input is coming from STDIN unless a valid file is given as
# a command-line argument.
if [ -f $1 ]; then
INPUT="$1"
else
INPUT="/dev/stdin"
fi
#
# Set IFS to newline only. See BASH(1) manpage for details on IFS.
IFS=$'\n'
#
# If terminal dimensions are not already set as shell variables, take
# a guess of 80x25.
if [ "$COLUMNS" = "" ]; then
let COLUMNS=80;
fi
if [ "$LINES" = "" ]; then
let LINES=25;
fi
#
# Initialize line counter variable
let LINE_COUNTER=$LINES
#
# Read the input file one line at a time and display on STDOUT until
# the page fills up. Display "Press <Enter>" message on STDERR and wait
# for keypress from STDERR. Continue until the end of the input file.
# Any input line greater than $COLUMNS characters in length is wrapped
# and counts as multiple lines.
#
while read -n $COLUMNS LINE_BUFFER; do
echo "$LINE_BUFFER"
let LINE_COUNTER=$LINE_COUNTER-1
if [ $LINE_COUNTER -le 1 ]; then
echo "Press <ENTER> for next page or <CTRL>+C to quit.">/dev/stderr
read</dev/stderr
let LINE_COUNTER=$LINES
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/dev/stdin
bash# ln -s fd/1 ~/staging/dev/stdout
bash# ln -s fd/2 ~/staging/dev/stderr
bash# mknod -m644 ~/staging/dev/zero c 1 5 |
8.3.3. Install ps
Get the latest procps source package from http://procps.sourceforge.net/
bash# cd /usr/src/procps-3.2.3
bash# make SHARED=0 CC="gcc -mcpu=i386"
bash# cd ps
bash# cp ps ~/staging/bin |
8.3.4. Install sed
Download GNU's sed from ftp://ftp.gnu.org/gnu/sed/
bash# cd /usr/src/sed-4.1.2
bash# export CC="gcc -mcpu=i386"
bash# ./configure --host=i386-pc-linux-gnu
bash# make
bash# cd sed
bash# cp sed ~/staging/bin |
8.3.5. Install ed
The ed package also comes from GNU at ftp://ftp.gnu.org/gnu/ed/
bash# cd /usr/src/ed-0.2
bash# ./configure --host=i386-pc-linux-gnu
bash# make
bash# cp ed ~/staging/bin |
8.3.6. Strip binaries to save space
bash# strip ~/staging/bin/* |
8.3.7. Ensure proper permissions
bash# chown 0:0 ~/staging/bin/*
bash# chmod -R 755 ~/staging/bin
bash# chmod 4750 ~/staging/bin/su |
8.3.8. 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# 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 diskette
Insert the diskette labeled "root disk" into drive fd0.
bash# dd if=~/phase7-image.gz of=/dev/fd0 bs=1k |