Linux Bootdisk HOWTO (part 1/2)

Linux Bootdisk HOWTO (part 1/2)

Post by Graham Chapma » Tue, 03 Oct 1995 04:00:00



Archive-name: linux/howto/bootdisk/part1
Last-modified: 2 Oct 95

-----BEGIN PGP SIGNED MESSAGE-----

*** The Linux Bootdisk HOWTO is posted automatically by the Linux
*** HOWTO coordinator, Greg Hankins <gr...@sunsite.unc.edu>.  Please
*** direct any comments or questions about this HOWTO to the author,
*** Graham Chapman <grah...@zeta.org.au>.

- --- BEGIN Linux Bootdisk HOWTO part 1/2 ---

  The Linux Bootdisk HOWTO
  Graham Chapman, grah...@zeta.org.au
  v1.02, 25 June 1995

  This document describes how to create Linux boot, boot/root and util-
  ity maintenance disks. These disks could be used as rescue disks or to
  test new kernels.

  1.  Introduction

  1.1.  Why Build Boot Disks?

  Linux boot disks are useful in a number of situations, such as:

  o  Testing a new kernel.

  o  Recovering from disk or system failure. Such a failure could be
     anything from a lost boot sector to a disk head crash.

  There are several ways of producing boot disks:

  o  Use one from a distribution such as Slackware. This will at least
     allow you to boot.

  o  Use a rescue package to set up disks designed to be used as rescue
     disks.

  o  Learn what is required for each of the various types of disk to
     operate, then build your own.

  I originally chose the last option - learn how it works so that you
  can do it yourself. That way, if something breaks, you can work out
  what to do to fix it. Plus you learn a lot about how Linux works along
  the way. Once I understood how it all worked, then I changed to using
  the Bootkit rescue package to maintain my boot disks.

  Experienced Linux users may find little of use in this document.
  However users new to Linux system administration who wish to protect
  against root disk loss and other mishaps may find it useful.

  A note on versions - this document has been updated to support the
  following packages and versions:

  o  Linux 1.2.0

  o  LILO 0.15

  Copyright (c) Graham Chapman 1995.

  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.

  1.2.  Feedback and Credits

  I welcome any feedback, good or bad, on the content of this document.
  Please let me know if you find any errors or omissions.

  I thank the following people for correcting errors and providing
  useful suggestions for improvement:

          Randolph Bentson
          Grant R. Bowman
          Scott Burkett
          Bruce Elliot
          HARIGUCHI Youichi
          Bjxrn-Helge Mevik
          Dwight Spencer
          Cameron Spitzer
          Johannes Stille

  1.3.  Change History

  v1.02, 25 June 1995

  o  Add: FAQ question on oversize ramdisk filesystems.

  o  Add: if using mkfs, use the -i option.

  o  Add: can use cp as well as dd to copy to raw disk.

  o  Chg: correct explanation of /dev/fd0 vs /dev/fd0H1440.

  o  Chg: use "zImage" terminology to conform to standard usage.

  o  Add: mke2fs -m 0 will provide more usable disk space.

  o  Add: re-run LILO if the kernel has changed.

  o  Add: move rescue packages to new section under "References".

  o  Add: new rescue packages Bootkit and CatRescue.

  o  Add: FAQ question on cannot execute errors.

  o  Add: shell scripts are samples only - I now use Bootkit.

  o  Chg: stop using < and > in command examples - too confusing.

  o  Chg: sample directory listings are now of diskettes, not model.

  o  Chg: use more consistent terminology with ramdisks.

     v1.01, 6 February 1995

  o  Fix: DO NOT cp kernel_filename /dev/fd0 - this will overwrite any
     file system on the diskette.

  o  Fix: Put LILO boot.b and map files on target disk.

  o  Add: -dp flags to cp commands to avoid problems.

  o  Chg: restructure to try to improve readability.

  o  Add: can now use ext2 filesystem on root diskettes.

  o  Chg: can now separate boot and root diskettes.

  o  Add: credits section in Introduction.

  o  Add: FAQ.

  v1.0, 2 January 1995

  o  Converted to conform to HOWTO documentation standards.

  o  Added new section - Change History.

  o  Various minor corrections.

  v0.10, 1 November 1994 Original version, labelled "draft".

  2.  Disks

  2.1.  Summary of Disk Types

  I classify boot-related disks into 4 types. The discussion here and
  throughout this document uses the term "disk" to refer to diskettes
  unless otherwise specified. Most of the discussion could be equally
  well applied to hard disks.

  A summary of disk types and uses is:

     boot
        A disk containing a kernel which can be booted. The disk can
        contain a filesystem and use a boot loader to boot, or it can
        simply contain the kernel only at the start of the disk.  The
        disk can be used to boot the kernel using a root file system on
        another disk. This could be useful if you lost your boot loader
        due to, for example, an incorrect installation attempt.

     root
        A disk with a file system containing everything required to run
        a Linux system. It does not necessarily contain either a kernel
        or a boot loader.

        This disk can be used to run the system independently of any
        other disks, once the kernel has been booted. A special kernel
        feature allows a separate root disk to be mounted after booting,
        with the root disk being automatically copied to a ramdisk.

        You could use this type of disk to check another disk for
        corruption without mounting it, or to restore another disk after
        a disk failure or loss of files.

     boot/root
        A disk which is the same as a root disk, but contains a kernel
        and a boot loader. It can be used to boot from, and to run the
        system. The advantage of this type of disk is that is it compact
        - everything required is on a single disk.  However the
        gradually increasing size of everything means that it won't
        necessarily always be possbile to fit everything on a single
        diskette.

     utility
        A disk which contains a file system, but is not intended to be
        mounted as a root file system. It is an additional data disk.
        You would use this type of disk to carry additional utilities
        where you have too much to fit on your root disk.

        The term "utility" only really applies to diskettes, where you
        would use a utility disk to store additional recovery utility
        software.
  2.2.  Boot

  2.2.1.  Overview

  All PC systems start the boot process by executing code in ROM to load
  the sector from sector 0, cylinder 0 of the boot drive and try and
  execute it. On most bootable disks, sector 0, cylinder 0 contains
  either:

  o  code from a boot loader such as LILO, which locates the kernel,
     loads it and executes it to start the boot proper.

  o  the start of an operating system kernel, such as Linux.

  If a Linux kernel has been written to a diskette as a raw device, then
  the first sector will be the first sector of the Linux kernel itself,
  and this sector will continue the boot process by loading the rest of
  the kernel and running Linux. For a more detailed description of the
  boot sector contents, see the documentation in lilo-01.5 or higher.

  An alternative method of storing a kernel on a boot disk is to create
  a filesystem, not as a root filesystem, but simply as a means of
  installing LILO and thus allowing boot-time command line options to be
  specified. For example, the same kernel could then be used to boot
  using a hard disk root filesystem, or a diskette root filesystem. This
  could be useful if you were trying to rebuild the hard disk
  filesystem, and wanted to repeatedly test results.

  2.2.2.  Setting Pointer to Root

  The kernel must somehow obtain a pointer to the drive and partititon
  to be mounted as the root drive. This can be provided in several ways:

  o  By setting ROOT_DEV = devicename in the Linux kernel makefile and
     rebuilding the kernel (for advice on how to rebuild the kernel,
     read the Linux FAQ and look in /usr/src/linux). Comments in the
     Linux makefile describe the valid values for devicename.

  o  By running the rdev utility:

               rdev filename devicename

  This will set the root device of the kernel contained in filename to
  be devicename. For example:

               rdev zImage /dev/sda1

  This sets the root device in the kernel in zImage to the first parti-
  tion on the first SCSI drive.

  There are some alternative ways of issuing the rdev command. Try:

          rdev -h

  and it will display command usage.

  There is usually no need to configure the root device for boot
  diskette use, because the kernel currently used to boot from probably
  already points to the root drive device. The need can arise, howoever,
  if you obtain a kernel from another machine, for example, from a
  distribution, or if you want to use the kernel to boot a root
  diskette. It is probably a good idea to check the current root drive
  setting, just in case it is wrong. To get rdev to check the current
  root device in a kernel file, enter the command:

               rdev <filename>

  It is possible to change the root device set in a kernel by means
  other than using rdev. For details, see the FAQ at the end of this
  document.

  2.2.3.  Copying Kernel to Boot Diskette

  Once the kernel has been configured then it must be copied to the boot
  diskette.

  The commands described below (and throughout the HOWTO) assume that
  the diskettes have been formatted. If not, then use fdformat to format
  the diskettes before continuing.

  If the disk is not intended to contain a file system, then the kernel
  can be copied using the dd command, as follows:

               dd if=infilename of=devicename

               where   infilename is the name of the kernel
...

read more »

 
 
 

Linux Bootdisk HOWTO (part 1/2)

Post by Graham Chapma » Tue, 03 Oct 1995 04:00:00


Archive-name: linux/howto/bootdisk/part2
Last-modified: 2 Oct 95

-----BEGIN PGP SIGNED MESSAGE-----

*** The Linux Bootdisk HOWTO is posted automatically by the Linux
*** HOWTO coordinator, Greg Hankins <gr...@sunsite.unc.edu>.  Please
*** direct any comments or questions about this HOWTO to the author,
*** Graham Chapman <grah...@zeta.org.au>.

- --- BEGIN Linux Bootdisk HOWTO part 2/2 ---

  4.2.  Shell Scripts to Build Diskettes

  These shell scripts are provided as examples only. I no longer use
  them because I now use and recommend Scott Burkett's Bootkit package
  to manage rescue diskette contents and creation. Bootkit is based on
  these scripts, and does essentially the same thing, but it is much
  tidier, nicer and easier to use. However, the sample shell scripts
  here will still provide working diskettes.

  There are two shell scripts:

  o  mkroot - builds a root or boot/root diskette.

  o  mkutil - builds a utility diskette.

  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.

  4.2.1.  mkroot - Make Root or Boot/Root Diskette

  ______________________________________________________________________
  # mkroot: make a boot/boot disk - creates a boot/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 [nokernel]
  #       if the parameter is omitted, then the kernel and LILO
  #       are copied.

  # Copyright (c) Graham Chapman 1995. 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...
  BOOTDISKDIR=./boot_disk       # name of boot disk directory
  MOUNTPOINT=./mnt              # temporary mount point for diskette
  LILODIR=/sbin                 # directory containing lilo
  LILOBOOT=/boot/boot.b         # lilo boot sector
  LILOMSG=./lilo.msg            # lilo message to display at boot time
  LILOCONFIG=./lilo.conf        # lilo parms for boot/root diskette
  DISKETTEDEV=/dev/fd0          # device name of diskette drive

  echo $0: create boot/root 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

  mount -t ext2 $DISKETTEDEV $MOUNTPOINT
  if [ $? -ne 0 ]
  then
          echo mount failed
          exit
  fi

  # copy the directories containing files
  for i in bin etc lib
  do
          cp -dpr $BOOTDISKDIR/$i $MOUNTPOINT
  done

  # copy dev *without* trying to copy the files in it
  cp -dpR $BOOTDISKDIR/dev $MOUNTPOINT

  # create empty directories required
  mkdir $MOUNTPOINT/proc
  mkdir $MOUNTPOINT/tmp
  mkdir $MOUNTPOINT/mnt
  mkdir $MOUNTPOINT/usr

  # copy the kernel
  if [ "$1" != "nokernel" ]
  then
          echo "Copying kernel"
          cp $BOOTDISKDIR/zImage $MOUNTPOINT
          echo kernel copied

          # setup lilo
          cp $LILOBOOT $MOUNTPOINT
          cp $LILOMSG $MOUNTPOINT
          $LILODIR/lilo -C $LILOCONFIG
          echo LILO installed
  fi

  umount $MOUNTPOINT

  echo Root diskette complete
  ______________________________________________________________________

  4.2.2.  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 1995. 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/bin $MOUNTPOINT

  umount $MOUNTPOINT

  echo Utility diskette complete
  ______________________________________________________________________

  5.  FAQ

  5.1.  Q. How can I make a boot disk with a XXX driver?

  The easiest way is to obtain a Slackware kernel from your nearest
  Slackware mirror site. Slackware kernels are generic kernels which
  atttempt to include drivers for as many devices as possible, so if you
  have a SCSI or IDE controller, chances are that a driver for it is
  included in the Slackware kernel.

  Go to the a1 directory and select either IDE or SCSI kernel depending
  on the type of controller you have. Check the xxxxkern.cfg file for
  the selected kernel to see the drivers which have been included in
  that kernel. If the device you want is in that list, then the
  corresponding kernel should boot your computer. Download the
  xxxxkern.tgz file and copy it to your boot diskette as described above
  in the section on making boot disks.

  You must then check the root device in the kernel, using the rdev
  command:

               rdev zImage

  Rdev will then display the current root device in the kernel. If this
  is not the same as the root device you want, then use rdev to change
  it.  For example, the kernel I tried was set to /dev/sda2, but my root
  scsi partition is /dev/sda8. To use a root diskette, you would have to
  use the command:

               rdev zImage /dev/fd0

  If you want to know how to set up a Slackware root disk as well,
  that's outside the scope of this HOWTO, so I suggest you check the
  Linux Install Guide or get the Slackware distribution. See the section
  in this HOWTO titled "References".

  5.2.  Q. How do I update my boot floppy with a new kernel?

  Just copy the kernel to your boot diskette using the dd command for a
  boot diskette without a filesystem, or the cp command for a boot/root
  disk. Refer to the section in this HOWTO titled "Boot" for details on
  creating a boot disk. The description applies equally to updating a
  kernel on a boot disk.

  5.3.  Q. How do I remove LILO so that I can use DOS to boot again?

  This is not really a Bootdisk topic, but it is asked so often, so: the
  answer is, use the DOS command:

               FDISK /MBR

  MBR stands for Master Boot Record, and it replaces the boot sector
  with a clean DOS one, without affecting the partition table. Some
  purists disagree with this, but even the author of LILO, Werner
  Almesberger, suggests it. It is easy, and it works.

  You can also use the dd command to copy the backup saved by LILO to
  the boot sector - refer to the LILO documentation if you wish to do
  this.

  5.4.  Q. How can I boot if I've lost my kernel AND my boot disk?

  If you don't have a boot disk standing by, then probably the easiest
  method is to obtain a Slackware kernel for your disk controller type
  (IDE or SCSI) as described above for "How do I make a boot disk with a
  XXX driver?". You can then boot your computer using this kernel, then
  repair whatever damage there is.

  The kernel you get may not have the root device set to the disk type
  and partition you want. For example, Slackware's generic scsi kernel
  has the root device set to /dev/sda2, whereas my root Linux partition
  happens to be /dev/sda8. In this case the root device in the kernel
  will have to be changed.

  You can still change the root device and ramdisk settings in the
  kernel even if all you have is a kernel, and some other operating
  system, such as DOS.

  Rdev changes kernel settings by changing the values at fixed offsets
  in the kernel file, so you can do the same if you have a hex editor
  available on whatever systems you do still have running - for example,
  Norton Utilities Disk Editor under DOS.  You then need to check and if
  necessary change the values in the kernel at the following offsets:

       0x01F8  Low byte of RAMDISK size
       0x01F9  High byte of RAMDISK size
       0x01FC  Root minor device
...

read more »