LILO, Linux Crash Rescue HOW-TO
 Al Dev (Alavoor Vasudevan)        [email protected]
 v6.0, 25 Dec 2000

 This document discusses methods to recover from Linux system failures.
 Various reasons for linux system failures can be - LILO is destroyed,
 or linux fails to boot, or Master Boot Record (MBR) is damaged or
 linux fails to boot when another operating system like Windows NT is
 installed which erases LILO or MBR.
 ______________________________________________________________________

 Table of Contents


 1. Introduction

    1.1 Quick Steps to recovery
    1.2 Precautionary measures
    1.3 Removing LILO
    1.4 Common mistakes

 2. Related URLs

 3. Other Formats of this Document

 4. Copyright



 ______________________________________________________________________

 1.  Introduction

 You cannot avoid accidents and if it happens to linux systems then it
 may damage the master boot record (MBR) or LILO (Linux boot Loader).
 There may be cases where linux will not boot due to hard disk
 failures. The LILO may also fail if you accidentally re-partition the
 hard disk or you install another additional operating system like
 Windows 98/NT on the linux computer.

 This document gives you some ideas, tips and quick guide to recover
 fast without wading through hundreds of pages of documentation on LILO
 or Linux.

 1.1.  Quick Steps to recovery

 Follow these steps to recover from LILO or system failures.


 1. SCENE 1: If your system does not boot -

    Get the tomsrtbt floppy  <http://www.toms.net/rb> Boot with
    tomsrtbt floppy Use fdisk to find the partitions. Try to recognise
    the root partition by doing this -

    ___________________________________________________________________
    bash# fdisk /dev/hda
    bash# mkdir /test
    bash# mount /dev/hda1 /test
    bash# ls /test
    You should see root-partition list like this -
    bin   fd    lib   mnt  proc  sbin  usr
    boot  dev   etc   home  lost+found  opt  root  tmp   var
    ___________________________________________________________________


 If this is not a root partition, then try the next partition
 /dev/hda2.  Next try hda3, hda4, hda5, etc.. untill you find the root
 partition.  Still not found in hda then repeat the above steps for
 other devices like hdb, hdc, hdd etc..  Also the /usr, /var, and /boot
 partition are needed as these are required to create new lilo configu�
 ration.

 In my case the root partition is /dev/hda4 which is used in the
 examples below:

 ______________________________________________________________________
 bash# mkdir /hda4
 bash# mount /dev/hda4 /hda4
 bash# cat /hda4/etc/fstab
         Read the output of fstab and mount partitions as per fstab file, see below -
 bash# mount /dev/hda5 /hda4/boot
 bash# mount /dev/hda6 /hda4/usr
 bash# mount /dev/hda7 /hda4/var
 bash# mount /dev/hda8 /hda4/opt
 bash# mount /dev/hda9 /hda4/root
 bash# mount /dev/hda10 /hda4/home
 ______________________________________________________________________


 In my case, as per fstab file hda5 was boot, hda6 was usr, hda7 was
 var, hda8 was opt, hda9 was root, hda10 was home and hda11 was win�
 dows95 directory.

 Edit /etc/fstab (not /hda4/etc/fstab) and put (sample code given here)
 -

 ______________________________________________________________________
         /dev/hda4  /hda4           ext2 defaults 1 1
         /dev/hda5  /hda4/boot      ext2 defaults 1 1
         /dev/hda6  /hda4/usr       ext2 defaults 1 1
         /dev/hda7  /hda4/var       ext2 defaults 1 1
         /dev/hda8  /hda4/opt       ext2 defaults 1 1
         /dev/hda9  /hda4/root      ext2 defaults 1 1
         /dev/hda10 /hda4/home      ext2 defaults 1 1
         /dev/hda11 /hda4/win95part vfat defaults 1 1

 On my computer hda4 contains the linux root partition, hda5 had boot partition and
 hda11 has windows 95 vfat system.

 bash# mkdir /hda4/win95part
 bash# mount /hda4/win95part
         And repair the system using fsck or e2fsck commands.
 bash# man fsck
 bash# man e2fsck
 ______________________________________________________________________



 2. SCENE 2: If LILO is not working..

    Follow scene 1 above, if that fails then follow these steps. Now
    you should have already mounted /hda4 and have created /etc/fstab
    file.



    ___________________________________________________________________
    bash# mount -a
    bash# chroot /hda4 /sbin/lilo -q
    bash# man chroot
    bash# chroot /hda4 /sbin/lilo
    ___________________________________________________________________


 Alternatively, you can directly use /sbin/lilo instead of chroot. The
 -r option of lilo actually does chroot.  It is very strongly recom�
 mended that you use chroot, instead of lilo -r, as it is more conve�
 nient and can catch errors more easily.

 ______________________________________________________________________
 bash# man lilo
 bash# /sbin/lilo -r /hda4
 ______________________________________________________________________



 3. SCENE 3: If LILO is not working..

    If scene 1 and 2 failes, then if you made the boot disk with
    'mkbootdisk' (during install or by using 'man mkbootdisk'), boot
    with it and repair your partitions.  The mkbootdisk is in
    mkbootdisk*.rpm package, you must install this.


 4. SCENE 4: If 1, 2 and 3 above fails and you do not have boot disk

    If you have another computer running linux, then login as root and
    do -

    ___________________________________________________________________
    bash$ man mkbootdisk
    bash# cp /etc/lilo.conf /etc/lilo-original.conf
    ___________________________________________________________________


 Edit the /etc/lilo.conf and put the root partition name as you
 obtained in 'scene 1' above and insert a blank floppy and give -

 ______________________________________________________________________
 bash# mkbootdisk /dev/fd0
 ______________________________________________________________________


 The mkbootdisk is in mkbootdisk*.rpm package, you must install this.
 Make sure you move the /etc/lilo-original.conf back to
 /etc/lilo.conf!! And then take this floppy and goto scene 3


 5. SCENE 5:  This is the worst scenerio, hopefully you do not come to
    this stage. Scenes from 1 to 4 take care of majority of cases. But
    in case above scenes 1, 2, 3 and 4 all fail then -

    Step 1: Boot tomsrtbt and mount the partitions and backup the root
    partition to another partition having disk space with comamnds -



    ___________________________________________________________________
            Edit /etc/fstab and put (sample code given here, you may have to
            change as per your disk layout) -
                    /dev/hda4  /hda4        ext2 defaults 1 1
                    /dev/hda11 /b1          vfat defaults 1 1
    bash$ mkdir /hda4; mount /hda4
    bash$ mkdir /b1; mount /b1
    bash$ cd /
    bash$ df
            And see that there is enough disk space in /b1 to tar up the root partition
    bash$ tar cvf /b1/root-hda4.tar   /hda4
    ___________________________________________________________________



 Step 2: Insert Linux cdrom, reboot and install the redhat linux on
 /dev/hda4 (but DO NOT install any extra packages, you just need to
 install only the root, boot systems and LILO manager that is, a very
 bare minimum). This will also install the LILO on hard disk.  Boot
 linux now and login as root and do -

 ______________________________________________________________________
 bash$ man mkbootdisk
 bash# cp /etc/lilo.conf /etc/lilo-original.conf
 ______________________________________________________________________


 Note: You MUST remember to copy back lilo-original.conf to lilo.conf!!
 Edit the /etc/lilo.conf and put the root partition name as you
 obtained in 'scene 1' above and insert a blank floppy and give -

 ______________________________________________________________________
 bash# mkbootdisk /dev/fd0
 bash# cp /etc/lilo-original.conf /etc/lilo.conf
 ______________________________________________________________________


 Test this boot floppy to see that this works and then restore back the
 all the files which you backedup using tar on /b1/root-hda4.tar as in
 step 1 above.

 1.2.  Precautionary measures

 You should take the following pre-cautionary measures to tackle the
 problems in future.


 �  You MUST make emergency boot disk from time to time and whenever
    you make changes to the partition. Insert a blank floppy and do
    this -

    ___________________________________________________________________
    bash$ man mkbootdisk
    The mkbootdisk is in mkbootdisk*.rpm package, you must install this.
    bash$ mkbootdisk --help
    bash$ mkbootdisk --device /dev/fd0 2.2.12-20
    ___________________________________________________________________



 �  You must keep the tomsrtbt boot floppy handy. Visit
    <http://www.toms.net/rb>



 �  You must keep the Yard rescue and boot floppy disk handy. Visit
    <http://www.croftj.net/~fawcett/yard>


 �  Backup /root and /boot directories. Boot the Tomsrtbt floppy and
    then

    ___________________________________________________________________
    bash# vi /etc/fstab
    And put these lines -
                    /dev/hda1 /a1 vfat defaults 1 1
                    /dev/hdb1 /b1 vfat defaults 1 1
    In my case hda1 had the linux root partition '/'
    bash# cd /
    bash# tar cvf /b1/linux-root-partition-hda1.tar  a1
    bash# tar cvf /b1/linux-boot-partition-hda1.tar  a1/boot
    ___________________________________________________________________



 1.3.  Removing LILO

 You can replace the boot sector with the DOS boot loader by issuing
 the DOS command at MS DOS prompt:

 ______________________________________________________________________
         FDISK  /MBR
 ______________________________________________________________________


 where MBR stands for "Master Boot Record".

 See also LILO documentation on linux at /usr/doc/lilo* for other
 methods of uninstalling the LILO. And see also 'man lilo'.

 1.4.  Common mistakes

 After making changes to /etc/lilo.conf you MUST run lilo to make
 changes to go in effect. It is a very common mistake committed by
 newusers. Type -

 ______________________________________________________________________
 bash# lilo -v -v -v
 ______________________________________________________________________



 2.  Related URLs

 Visit following locators which are related to LILO, Rescue Linux,
 crash recovery -

 �  Mini Lilo HOWTO at  <http://www.linuxdoc.org/HOWTO/mini/LILO.html>

 �  Bootdisk-HOWTO at  <http://www.metalab.unc.edu/LDP/HOWTO/Bootdisk-
    HOWTO/index.html>


 �  Pre-made boot disks at  <http://www.linuxdoc.org/HOWTO/Bootdisk-
    HOWTO/a1277.html>

 �  Tomsrtbt boot floppy disk  <http://www.toms.net/rb>

 �  Yard rescue and boot floppy disk
    <http://www.croftj.net/~fawcett/yard>

 �  BootPrompt-HOWTO at  <http://www.linuxdoc.org/HOWTO/BootPrompt-
    HOWTO.html>

 �  Multiboot with LILO mini HOWTO at
    <http://www.linuxdoc.org/HOWTO/mini/Multiboot-with-LILO.html>

 �  Linux+WinNT mini HOWTO at
    <http://www.linuxdoc.org/HOWTO/mini/Linux+WinNT.html>


 �  Linux goodies main site  <http://www.aldev.8m.com>

 �  Linux goodies mirror site  <http://aldev.webjump.com>

 �  Vim color text editor for C++, C
    <http://metalab.unc.edu/LDP/HOWTO/Vim-HOWTO.html>

 3.  Other Formats of this Document

 This document is published in 11 different formats namely - DVI,
 Postscript, Latex, Adobe Acrobat PDF, LyX, GNU-info, HTML, RTF(Rich
 Text Format), Plain-text, Unix man pages, single HTML file and SGML.

 �  You can get this HOWTO document as a single file tar ball in HTML,
    DVI, Postscript or SGML formats from -
    <ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO/other-formats/>

 �  Plain text format is in:
    <ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO>

 �  Translations to other languages like French, German, Spanish,
    Chinese, Japanese are in
    <ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO> Any help from you to
    translate to other languages is welcome.

    The document is written using a tool called "SGML-Tools" which can
    be got from - <http://www.sgmltools.org> Compiling the source you
    will get the following commands like

 �  sgml2html LILO-crash-rescue-HOWTO.sgml     (to generate html file)

 �  sgml2rtf  LILO-crash-rescue-HOWTO.sgml     (to generate RTF file)

 �  sgml2latex LILO-crash-rescue-HOWTO.sgml    (to generate latex file)

 LaTeX documents may be converted into PDF files simply by producing a
 Postscript output using sgml2latex ( and dvips) and running the output
 through the Acrobat distill ( <http://www.adobe.com>) command as
 follows:

 ______________________________________________________________________
 bash$ man sgml2latex
 bash$ sgml2latex filename.sgml
 bash$ man dvips
 bash$ dvips -o filename.ps filename.dvi
 bash$ distill filename.ps
 bash$ man ghostscript
 bash$ man ps2pdf
 bash$ ps2pdf input.ps output.pdf
 bash$ acroread output.pdf &
 ______________________________________________________________________


 Or you can use Ghostscript command ps2pdf.  ps2pdf is a work-alike for
 nearly all the functionality of Adobe's Acrobat Distiller product: it
 converts PostScript files to Portable Document Format (PDF) files.
 ps2pdf is implemented as a very small command script (batch file) that
 invokes Ghostscript, selecting a special "output device" called
 pdfwrite. In order to use ps2pdf, the pdfwrite device must be included
 in the makefile when Ghostscript was compiled; see the documentation
 on building Ghostscript for details.

 This howto document is located at -

 �  <http://sunsite.unc.edu/LDP/HOWTO/LILO-crash-rescue-HOWTO.html>

 Also you can find this document at the following mirrors sites -

 �  <http://www.caldera.com/LDP/HOWTO/LILO-crash-rescue-HOWTO.html>

 �  <http://www.WGS.com/LDP/HOWTO/LILO-crash-rescue-HOWTO.html>

 �  <http://www.cc.gatech.edu/linux/LDP/HOWTO/LILO-crash-rescue-
    HOWTO.html>

 �  <http://www.redhat.com/linux-info/ldp/HOWTO/LILO-crash-rescue-
    HOWTO.html>

 �  Other mirror sites near you (network-address-wise) can be found at
    <http://sunsite.unc.edu/LDP/hmirrors.html> select a site and go to
    directory /LDP/HOWTO/LILO-crash-rescue-HOWTO.html


 In order to view the document in dvi format, use the xdvi program. The
 xdvi program is located in tetex-xdvi*.rpm package in Redhat Linux
 which can be located through ControlPanel | Applications | Publishing
 | TeX menu buttons.  To read dvi document give the command -


              xdvi -geometry 80x90 howto.dvi
              man xdvi



 And resize the window with mouse.  To navigate use Arrow keys, Page
 Up, Page Down keys, also you can use 'f', 'd', 'u', 'c', 'l', 'r',
 'p', 'n' letter keys to move up, down, center, next page, previous
 page etc.  To turn off expert menu press 'x'.

 You can read postscript file using the program 'gv' (ghostview) or The
 ghostscript program is in ghostscript*.rpm package and gv program is
 in gv*.rpm package in Redhat Linux which can be located through
 ControlPanel | Applications | Graphics menu buttons. The gv program is
 much more user friendly than ghostscript.  Also ghostscript and gv are
 available on other platforms like OS/2, Windows 95 and NT, you view
 this document even on those platforms.


 �  Get ghostscript for Windows 95, OS/2, and for all OSes from
    <http://www.cs.wisc.edu/~ghost>

 To read postscript document give the command -


                      gv howto.ps
                      ghostscript howto.ps



 You can read HTML format document using Netscape Navigator, Microsoft
 Internet explorer, Redhat Baron Web browser or any of the 10 other web
 browsers.

 You can read the latex, LyX output using LyX a X-Windows front end to
 latex.

 4.  Copyright

 Copyright policy is GNU/GPL as per LDP (Linux Documentation project).
 LDP is a GNU/GPL project.  Additional requests are that you retain the
 author's name, email address and this copyright notice on all the
 copies. If you make any changes or additions to this document then you
 please intimate all the authors of this document.  Brand names
 mentioned in this document are property of their respective owners.