README.howto

1) INTRODUCTION. The "cramdisk-2.0.tgz" distribution contains
scripts that can read and write a floppy cramdisk that contains a
compressed Linux kernel and a compressed filesystem.  You can
modify the cramdisk by reading the cramdisk from the floppy,
putting it onto a partition, modifying it, and then writing it
back to the floppy.  A "zImage" file (the kernel image) is
required.  All commands are compiled in ELF format so are
compatible with recent releases of Linux.

2) RETRIEVE KERNEL. You can retrieve the kernel image file like this:

   Put cramdisk floppy in A: (/dev/fd0).
then
   for the "ppa" floppy:  dd if=/dev/fd0 of=zImage bs=1 count=334733
   for the "net" floppy:  dd if=/dev/fd0 of=zImage bs=1 count=386393

after that, follow the instructions in the cramdisk-2.0.tgz
distribution (given below).  Place the "zImage" file according
to its location defined in "writefsz" (now set for the current
directory ".", but originally /usr/src/linux/arch/i386/boot/zImage).
The size of the ramdisk on the floppy varies (1800 blocks for "ppa",
1660 for "net"), but you can change this with "makefsz" (see
below) as long as the compressed ramdisk fits on the floppy.

The kernel supplied with this distribution is v2.0.23. The "net"
disk includes drivers for ppp, 3c509, NE2000, and the "ppa" disk
includes the driver for parallel port ZIP drives.  Both disks also
contain math emulation code and will boot OK on a 386.

If you need to remake the kernel, do a "make config" in the
kernel source directory and make sure to turn on "Ram disk
support".  The ".config" files used to make the "cramdisk.net"
and "cramdisk.ppa" kernels are included in this distribution as
"config.cram.net" and "config.cram.ppa".  To use one of them, copy
it to /usr/src/linux/.config and "make config", modifying any of
the options you like. Do not turn on "Initial RAM disk (initrd)
support" unless you need it specifically for your purposes.  Then
do the standard "make dep; make clean", and "make boot", which
makes "zImage" and places it in /usr/src/linux/arch/i386/boot.
Just keep track of the size of zImage because there's not much
space on the cramdisk (but enough for a few additions to the
kernel, e.g. math emulation, etc). Last, copy zImage to the
current directory (for me it's /usr/src/cramdisk-2.0).

3) RETRIEVE FILE SYSTEM. Here's how to recover the cramdisk file
system:

  First, you need a free partition (/dev/hda?, ?=number of the
partition you want to use) big enough to hold the file system
image on the ramdisk (4MB is OK).

    readfsz - | gzip -d > /dev/hda?

then mount the partition under linux with:

   mount /dev/hda? /mnt  

and modify the partition as you like.  


4) MAKE BOOT [optional]. Rather than remaking the cramdisk floppy
each time to check its operation, it is sometimes easier to boot
the partition you have created that contains the cramdisk's
filesystem.  To do this, make a boot floppy:

   dd if=zImage of=/dev/fd0 
   rdev /dev/fd0 /dev/hda? 
   rdev -R /dev/fd0 0

  This puts the kernel on a floppy and sets the root file system
for the boot kernel to be the cramdisk partition. When you boot
this partition, it will run exactly like the one you will place
on the floppy.  However you if you boot the partition, you should
reboot your standard Linux system and mount the cramdisk
partition and "rm" any files from the cramdisk partition's "/tmp"
directory before you run "makefsz" to copy it.

   mount /dev/hda? /mnt
   rm -r /mnt/tmp/*

5) FILE SYSTEM NOTES. Note (with the "file" command) that many
binary executables on the cramdisk are compressed with the "tzx"
program and run with the "untzx" program.  This command
compressed binary commands with "gzip" and when you run them it
unzips them.  But also note that "tzx" cannot be run on "suid"
(set UID=root) programs.  The files compressed with tzx don't
save much space on the floppy, because the whole ramdisk is
compressed anyhow. But they do save space in the ramdisk in
memory, since they stay compressed until you actually need them
uncompressed.  The "untzx" command runs automatically when you
run any "tzx"ed command, and "untzx" erases the old expanded copy
when you run the next "tzx"ed command. The expanded binaries
reside in /tmp/tzx. The "tzx" command used to compress the
binaries is not on the cramdisk image but can be found in the
tzx100.tgz distribution included in the cramdisk-2.0 distribution.

The filesystem on the cramdisk is quite full, i.e. when
uncompressed, it fills the space allocated to it in a 4MB memory
with about 100KB to spare. This has little relation to its size
inside the compressed ramdisk.   The floppy will hold a
filesystem as large as 4MB when compressed by the "makefsz"
command, but of course such a file system would not leave enough
free RAM to run any processes in a 4 MB machine (but you can do
much more in 8 MB).  A filesystem of 1660 K (as in the example
given) has a size of about 825 KB, so it only fills about half
the floppy disk.  

You can tell how large the compressed filesystem will be with the
command:  

    umount /dev/hda?
    makefsz /dev/hda? z 1660    (where z will be an image of the cramdisk)
    ls -s z                     (give size of z in 1K blocks)

    (in this case "writefsz z" would write the filesystem to the floppy)

    Note that the "makefsz" command remakes the partition's file
system with a total size equal to the number that you specify (in
this case 1660).  The size of (zImage + z) must be less than or
equal to the size of the floppy disk (normally 1474560 bytes).

  Since the compressed size of the filesystem included in this
distribution is about 825 blocks, the total cramdisk size on the
floppy is about 1200 blocks, which leaves 240 KB for other
commands you might want to add.  You probably won't be able to
fit them into a working cramdisk if you have only 4MB RAM in your
machine, but if you have 8MB there's room in RAM memory for
several large programs (e.g. ncftp, vi, tar, etc.), as long as
they'll fit on the cramdisk (and you make the filesystem the
right size). 

6) MAKE CRAMDISK.  After you've finished modifying the file
system, then:

   Put in a new floppy in drive A: (/dev/fd0).

    put in a new floppy
    dd if=zImage of=/dev/fd0 bs=20b                 (stores the kernel)
    umount /mnt
    makefsz /dev/hda? - 1660 330 | writefsz -       (stores the ramdisk)
    then boot the floppy and test
                                                     
Note that in this example the 1660 is the size of the ramdisk in
1K blocks; you can change this number if you like, and it defaults
to 4096 if you leave it out. The 330 is the number of inodes
which if specified helps to reduce the space taken by the file
system (this number may also be left out, in which case the
number of inodes is automatically set). Also note that the
"writefsz" command requires the kernel image file "zImage" (or
maybe "/usr/src/linux/arch/i386/boot/zImage") to figure out the
kernel's size (actually it doesn't need a working zImage, just a
file with the name "zImage" equal in size to the kernel on the
floppy).

In writefsz, the location of the file system on the floppy and
the boot behavior is determined by the ramdisk word in the kernel
(to see it, use "rdev -r /dev/fd0").  The lower 11 bits describe
the number of 1K blocks offset from the start of the floppy to
start loading the file system.  Bit 14 set =1 indicates a ramdisk
will be loaded, and bit 15 indicates you want a prompt so you can
switch floppy disks.  (See ramdisk.txt, copied from
/usr/src/linux/Documentation.)

So for example, using 400 K, load=1 and prompt=1, 
we get 2^14 + 2^15 + 400 = 49552.

You don't need to calculate this yourself, as writefsz calculates 
the correct number for "rdev -r" and writes it automatically.

The commands used to make cramdisk.ppa:

cp vmlinuz-2.0.23.ppa zImage
dd if=zImage of=/dev/fd0 bs=20b
makefsz /dev/hda2 - 1800 330 | writefsz -

7) SLACKWARE CRAMDISK.

You can make a cramdisk from Slackware 3.1 boot- and rootdisks by
selecting the appropriate kernel image from "bootdsks.144" and
compressed file system image from "rootdsks".  Write them to the
floppy using the method described above:

   cp bare.i zImage                     (copy kernel to "zImage" for writefsz)
   dd if=zImage of=/dev/fd0 bs=20b	(copy kernel to floppy)
   writefsz color.gz			(copy filesystem "color.gz" to floppy)

Happy cramdisk'ing...

Rob
