Making a Linux Boot Disk
It's easy. Three steps:
1. Insert an MS-DOS formatted floppy into your floppy drive. We'll be
putting
a lot of stuff on it, so make sure it's empty. The box of floppys you
bought
at the office store is fine.
2. Copy a kernel image onto the floppy. Copy a config file onto the
floppy
(details below).
3. Run 'syslinux /dev/fd0' (quotes mine - you don't type them in). Copy
the
filesystem image to the floppy disk. You will need at least 4MB of RAM
on
your computer. Some older laptops don't have this much RAM.
There is a more complicated way. This involves copying the kernel image
to
the floppy, and determining an offset based on the kernel size. Copy a
file
system to the floppy, putting the file system image after the kernel
image
using the offset. Run the program 'rdev' to tell the kernel where the
file
system image is. More details are in the Bootdisk-HOWTO file mentioned below.
Now for the details.
First some files you will need. Here is a linux
kernel image you can use on your boot floppy.
Here is the config file mentioned above.
It is called SYSLINUX.CFG. Here is what I have in the file:
append initrd=FS.gz root=/dev/ram0
That's it. This command tells the kernel (when it boots up and starts
running)
to use the file FS.gz as it's initrd (initial ram disk), which is a
fancy
name for a file system. The file system is a list of files to run and a
place
to put them. Below I'll show you what's needed.
Here is a batch file that I use to
create
a bootable floppy. It's called makedisk.
And here is a batch file I use to make a
file
system image. It's called batch.
The above two batch files have enough comments in them to help you
along,
but not enough to teach shell programming under linux/unix. Sorry.
One more text file - this is the original
bootdisk howto seen in some distrubutions. It may be updated, but
this
is really all you need, and it explains it a lot better than I can.
-------------------------------------------------------------------------------------------
Now for all the details.
The program syslinux creates an image on the boot floppy's bootsector.
This
image looks for three things:
1) A file called 'linux'. It must be called linux. You can call it
'kernel',
but the configuration line for syslinux has limitations. Calling it
linux
makes it simpler. This file (linux) is a bootable kernel image. You can
create
one yourself. The one I supplied above should get you started. You want
it
to be fairly small (mine is about 500KB). If it's too big, you won't be
able
to get much more on the floppy. To get the current (and not-so-current)
kernal
sources go to http://www.kernel.org
2) A config file called 'SYSLINUX.CFG'. This text file tells syslinux
what
to do when starting the boot process. A lot of detail on the SYSLINUX home page.
3) A file system. This is a collection of files that are part of the
operating
system. In the file system I include below, I have the directory
structure,
some library files, a program called busybox, some config files for the
operating
system, and some other misc. files. I created a small, and fairly
simple
file system that let's you learn enough of this to add on to it for
your
own purposes. You can get a copy of it here.
First, however, let's take a look at the details of two batch files
mentioned
above. The first is called batch. This shell script creates a file
system
image.
First create a 4MB file, and fill it with zeros. Zeros are easy to
compress.
You will see why I do this later. Here are the lines of code that do
this
(all copied from the batch file).
# create empty space for filesystem - 4.0MB
echo "Creating Space for File System"
dd if=/dev/zero of=FS bs=1k count=4096
The dd command takes /dev/zero as an input file. The output file is
called
FS. Block size is 1KB, and I want 4096 blocks of 1KB in size.
Now let's create an ext2 file system on this FS file.
# create ext2 file system w/1500 i-nodes
echo "Making new EXT2 File System"
mke2fs -m 0 -N 1500 FS -F -q
The mke2fs command creates the file system on the empty file. The -N
1500
option makes 1500 inodes. More than enough for a small file system. The
-q
option tells the mke2fs program to be quiet as it runs.
Next we want to mount this new file system so we can add stuff to it.
We
need to use the loopback device to do this, which means your current
kernel
must be compiled with the loopback device enabled. Also, /dev/loop0
needs
to be created. More details are in the Bootdisk-HOWTO
file above. If you already have a working Linux distribution you are
using,
you should already have these.
Let's mount the newly created file system:
# now mount it
echo "Mounting File System in /mnt2"
mount -o loop=/dev/loop0 FS /mnt2
The mount point I use is /mnt2. This is just an empty directory. You
probably
don't have it - to make it do the following:
mkdir /mnt2
or you can change the line to use /mnt which you probably already
have.
(A word on mount points - a mount point is an empty directory that will
be
a reference point for a mounted file system. Examples are /cdrom,
/floppy,
/USBCARD, etc. These provide an easy to remember reference to access
the
file system. All distrubitions have /mnt. I use /mnt for something
else,
so I created /mnt2.)
If you now go to the /mnt2 directory, you will be looking at your empty
file
system. Let's add some files:
# Install packages
# get list of packages to install from ./package_list
{
while read files; do
echo "Adding package $files"
cp packages/$files /mnt2
cd /mnt2; tar xfz $files; rm
$files;
cd ~/distro
done
} < package_list
This takes the precompiled packages in the packages/ directory and
copies
them to your new file system. They are in tar/gzip format. The line
'tar
xfz $files' untars and unzips them, and then deletes the original
tar/zipped
file.
The file 'package_list' is a text file of the available packages.
Now let's stuff the /etc directory with some config files
# create the etc/ archive from the local source/etc/ directory
if [ -e packages/etc.tgz ]; then
echo "Removing old etc/
directory"
rm packages/etc.tgz
fi
echo "Creating etc/ archive"
cd source; tar cfz ~/distro/packages/etc.tgz etc/; cd ~/distro;
# and install it
cp packages/etc.tgz /mnt2
cd /mnt2; tar xfz etc.tgz; rm etc.tgz; cd ~/distro
I make a directory called 'etc' where the batch file resides. In this
directory,
I placed several files that the above lines of code take, tar/zip up,
copy
to the new file system, then unzip, and untar. I then remove the
'etc.tgz'
file from the file system.
Our new file system, as you can see, is just a collection of files. We
now
unmount the file system and zip it up.
# now unmount the new FS
echo "Unmounting File System"
# double syncing is a hold-over from the early days of linux
sync; sync;
umount /mnt2
# and zip it up
echo "Ziping up new File System"
gzip -9 FS
# delete old FS.gz from floppy
echo "Removing old File System from floppy"
mdel a:FS.gz
# and move in new one
echo "Installing new File System on floppy"
mcopy FS.gz a:
The mcopy and mdel command is part of the msdos tools (mtools) included
with
most distributions. The gzip -9 command zips up the file called FS (our
file
system) and the '-9' option makes the zip file as small as possible.
After
zipping up the file, the filename is changed to FS.gz. Having the empty
space
filled with zeros from /dev/zero (above) make compressing the file as
small
as possible.
Notice that we just copied the zipped filesystem onto the floppy. We
told
syslinux the file system was called FS.gz in the SYSLINUX.CFG config
file
with the line: 'append initrd=FS.gz root=/dev/ram0'.
This means after the syslinux bootloader starts, and loads the kernal
image
called 'linux' that it will mount a filesystem called 'FS.gz' and use
it
for the operating system. The /dev/ram0 is the device for the ram0
ramdisk.
If you want to see the packages I use for the file system, here they
are.
Right click on the link, save them, and use 'tar tvfz package_name.tgz'
to
view them. You can also uncompress/unzip them and make changes. Use
'tar
xfz package_name.tgz' to install them to your hard drive.
Base.tgz (Base file system - just the
needed
directories)
BusyBox1.01.tgz (Busybox program
-
most of the system binaries need to run the system)
checkit.tgz (error checking program
I
use - not really needed)
fsutils.tgz (some file system
creation
utilities when building a new system)
lib_busybox.tgz (libraries
needed
to run busybox)
bwbasic.tgz (a basic interpreter)
minicom2.1.tgz (a serial
communications
program - bloated)
Lastly, here is an image of the completed
bootdisk.
Right click on the link, save it, and using the dd command in linux
type
the following with a blank floppy in your floppy drive:
dd if=BOOTDISK of=/dev/fd0
If you're using windows/dos, use the dos command 'rawwrite'. Click
here for a current (2007) Windows copy. Original source on freshmeat.net.
Reboot your machine with this floppy in and you will boot up (if your
BIOS
is set correctly) on your new bootdisk.
Any questions? Contact me (Kurt Theis) from the e-mail link on
the Main Page