1. Home
  2. Tutorials
  3. Boot Disk
Yolinux.com Tutorial

Linux Recovery and Boot Disk Creation

This tutorial covers the creation and usage of boot floppies for system recovery.

Three recovery methods are discussed:

  1. Creation / usage of a floppy with GRUB boot loader. Grub configured on floppy to point to Linux kernel on hard drive.
  2. Creation / usage of a floppy with LILO on the Master Boot Record (MBR) to point to the Linux kernel on an existing hard drive for boot. This is typically done when the MBR is corrupted, overwritten by the installation of another operating system or as an alternative to configuring the hard drive MBR for dual boot.
  3. Creation / usage of a recovery floppy which contains a small Linux kernel on the floppy with the proper drivers to boot the system to perform recovery operations. While this is more complex, it does not require a working Linux OS on the harddrive. Given that Linux can mount a Windows partition, it is also a viable method for recovering data from a MS/Windows drive.

Related topics in this tutorial:

Also see the YoLinux Tutorial: Linux Init Process / Boot Procedure

 

 

1) Creation of a floppy with GRUB on MBR:

GRUB: GRand Unified Bootloader

The GRUB bootloader is first run when the computer initially boots. After it runs, it passes control to the operating system kernel. GRUB is typically installed on the MBR of the hard drive but can also be installed on a floppy to rescue the system if the MBR is overwritten or corrupted.

Note: Grub "Legacy" refers to the 0.9x versions of Grub.

  • Grub 0.95 (Red Hat Enterprise 4, Fedora Core 3, CentOS4) is configured with /etc/grub.conf (soft link to /boot/grub/grub.conf or /boot/grub/menu.1st)
  • Grub 0.97 (Ubuntu 6.11) is configured with a multiple configuration files including:
    • /boot/grub/menu.lst: Typical Grub directives (was grub.conf)
    • /boot/grub/device.map: List devices e.g. (hd0) /dev/sda
    • /boot/grub/default: Set with the command "grub-set-default". Typical value is "0" to boot the first kernel listed. Example: grub-set-default 0
    • /boot/grub/stage1: Embedded in MBR (boot sector partition) thus is 512 bytes. Encodes location of stage 2.
    • /boot/grub/stage2: Put on a filesystem, this is the core image of GRUB.
    • ...

Links:

GRUB: Legacy (0.95)

GRUB is an operating system independant boot loader and shell. GRUB uses a device naming system which is different and independant of the one used by Linux. For example (hd0,0), the designation "hd0" refers to the first hard drive. The second designation refers the the partition number. Each begin counting from "0". Some systems like BSD may include more designations. Note that GRUB does not distinguish EIDE from SCSI.
Linux device name GRUB name Linux filesystem
(Examples)
/dev/hda1 (EIDE)
or
/dev/sda1 (SCSI)
(hd0,0) /boot
/dev/hda2
or
/dev/sda2
(hd0,1) /
/dev/hdb1
or
/dev/sdb1
(hd1,0) /home
/dev/fd0 (fd0,0) /mnt/floppy

Sample config file: /etc/grub.conf (Linked to actual file: /boot/grub/grub.conf).

default=0
timeout=10
splashimage=(hd1,0)/grub/splash.xpm.gz     - Image to be displayed: /boot/grub/splash.xpm.gz which is on the 2nd hard drive, 1st partition.
title Red Hat Linux (2.4.9-21)
        root (hd1,0)                       - Root of GRUB reference. Same as /boot. See above table.
        kernel /vmlinuz-2.4.9-21 ro root=/dev/sdb6  - Note that the command cat /proc/cmdline should be the same as "ro root=/dev/sdb6"
        initrd /initrd-2.4.9-21.img        - Referenced from GRUB root reference. Hence file: /boot/initrd-2.4.9-21.img
                
Note: All GRUB paths are referenced from /boot, as defined by the "root" statement.

Create GRUB boot floppy:

[root prompt]#  fdformat /dev/fd0H1440
[root prompt]#  mke2fs /dev/fd0
[root prompt]#  mount -t ext2 /dev/fd0 /mnt/floppy
[root prompt]#  grub-install --root-directory=/mnt/floppy '(fd0)'
[root prompt]#  cp /boot/grub/grub.conf /mnt/floppy/boot/grub/grub.conf
[root prompt]#  umount /mnt/floppy

The small reduced kernel /boot/vmlinuz-...BOOT and support files in /boot can be loaded on the floppy to create other boot options.

GRUB: Legacy (0.97)

Method 1:

Creating a GRUB boot floppy:
  1. cd /lib/grub/i386-pc
  2. dd if=stage1 of=/dev/fd0 bs=512 count=1
  3. dd if=stage2 of=/dev/fd0 bs=512 seek=1

This will write files stage1 and stage2 to the first and second block of the floppy disk.

Method 2:

  1. mke2fs /dev/fd0
  2. mount -t ext2 /dev/fd0 /mnt/floppy
  3. grub-install --root-directory=/mnt/floppy fd0
  4. umount /mnt/floppy

2) Creation of a floppy with LILO on MBR:

Lilo is the "Boot Loader" for Linux which typically resides on the MBR of your hard drive. This may easily get wiped out on a multiboot system where a re-loading of the Windows operating system will reload the MBR. If the MBR is overwritten and LILO removed, there will be no way of booting to Linux. Thus it is wise to have a floppy with LILO residing on the MBR of the floppy which can point the system to boot off of the Linux kernel residing on your hard drive. Here is how it is created:

  1. fdformat /dev/fd0H1440 # Lay tracks on new diskette
  2. mkfs -t minix /dev/fd0 1440 # Create minix file system on floppy
  3. mount /dev/fd0 /mnt/floppy # Mount floppy
  4. cp -p /boot/chain.b /mnt/floppy # Copy chain loader
  5. cp -p /boot/boot* /mnt/floppy
  6. lilo -v -C /etc/lilo.floppy # Install lilo and the map onto floppy
  7. umount /mnt/floppy

Note that LILO sets the MBR to the settings as defined by the configuration file /etc/lilo.floppy.

Sample file: /etc/lilo.floppy

boot=/dev/fd0                - Floppy drive (Location of Lilo boot sector)
map=/mnt/floppy/map          - Locations on hard drive where the kernel can be found for boot
prompt                       - Show prompt: LILO boot:
linear - Specific to SCSI configurations timeout=50 - Give the user time to decide (number of tenths of seconds) if there are multiple choices image=/boot/vmlinuz-2.2.17-14 - Boot this Linux kernel. This depends on your release of the operating system. label=hd_linux - Label displayed to user which identifies this kernel root=/dev/sdb6 - System instructed to boot from this drive. Unique to your system. Example: /dev/hda4 Installation dependent. initrd=/boot/initrd-2.2.17-14.img - This is specific to systems using SCSI hard drives. This line is omitted for IDE. read-only - Mount partition read-only at first to run fsck

Note:

  • Actual kernel name and version will depend on your Linux release.
  • Most of the information for /etc/lilo.floppy should be copied from /etc/lilo.conf
  • Actual names for the files to be used may be seen in the directory /boot
  • The file initrd-2.2.17-14.img is required by systems using modular SCSI support.
    It is generated using the command: mkinitrd /boot/initrd-2.2.17-14.img 2.2.17-14
    and should also be copied to the floppy.

MBR restoration:

Once the system has rebooted using LILO on the MBR of the floppy to point to the kernel on your hard drive, the system will boot as before.

The last step. As root execute the command: /sbin/lilo -v
This will re-install LILO on the MBR of your hard drive using the configuration file /dev/lilo.conf.

Sample file /etc/lilo.conf:
(This should already reside on your system. Generated by a Linux installation)

boot=/dev/sda                              - Location of Lilo boot sector. (i.e.: /dev/hda for first EIDE drive)
map=/boot/map
install=/boot/boot.b
prompt
linear
default=linux
timeout=50

image=/boot/vmlinuz-2.2.17-14
      label=linux
      root=/dev/sdb6
      initrd=/boot/initrd-2.2.17-14.img     - This is specific to systems using SCSI hard drives. This line is omitted for IDE.
      read-only

other=/dev/sda1
      label=win98
      

Explanation of files:

/etc/lilo LILO configuration file
/boot/boot.b Boot loader
/boot/map Boot map that contains the location of the kernel
/sbin/lilo Program to install lilo. Installs map.

Usage:

Just boot with the floppy in it's drive. The BIOS settings may have to be changed to allow the computer to boot from the floppy drive by changing the device seek order. The floppy (A:) needs to be ahead of the hard drive (C:). To enter the BIOS configuration utility, reboot the system and press the "DEL" key while booting. (Typically. Your system may be different)

3) Creation of a Recovery Disk:

As root user (on Red Hat), use the command: /sbin/mkbootdisk 2.2.17-14
You may specify the device: /sbin/mkbootdisk --device /dev/fd0 2.2.17-14

This will of course depend on the version of the Linux kernel you are using. To obtain the kernel version see your /etc/lilo.conf file or the name of the kernel modules library directory for the information. ( ls /lib/modules/ Use the directory name of the appropriate kernel. i.e. if the directory name is /lib/modules/2.4.9-34/ then use 2.4.9-34)

Usage:

  1. Boot computer with the floppy in it's drive.

  2. It will boot the kernel from the floppy but then try to use your hard drive. If successful, it will fully boot from your hard drive. It's Painless!!

Rescue Floppy Images:


  • Use the command: fdisk /dev/sda (SCSI) or fdisk /dev/hda (IDE) or whatever your drive is. Try hda3, hda4, hda5, etc.. untill you find your partitions.
    [root /root]# fdisk /dev/sdb
    
    The number of cylinders for this disk is set to 1106.
    There is nothing wrong with that, but this is larger than 1024,
    and could in certain setups cause problems with:
    1) software that runs at boot time (e.g., LILO)
    2) booting and partitioning software from other OSs
       (e.g., DOS FDISK, OS/2 FDISK)
    
    Command (m for help): p
    
    Disk /dev/sdb: 255 heads, 63 sectors, 1106 cylinders
    Units = cylinders of 16065 * 512 bytes
    
       Device Boot    Start       End    Blocks   Id  System
    /dev/sdb1   *         1         3     24066   83  Linux
    /dev/sdb2             4      1106   8859847+   5  Extended
    /dev/sdb5             4        36    265041   82  Linux swap
    /dev/sdb6            37      1106   8594743+  83  Linux
    
    Command (m for help): q
    
    [root /root]# 
        
    The purpose of this is to determine your configuration. Disk partition and mount points are also held in the file: /etc/fstab (file systems table)

  • Mount the partition you wish to operate on:
    • mkdir /mntpoint
    • mount /dev/sdb6 /mntpoint
    • ls /mntpoint - Shows that it works and files are accessible.
    • At this point you can tar files to a tape, run lilo to repair the MBR, perform a disk check (fsck or e2fsck) or repair your system.

Floppy Duplications:

Copying a 3.5 inch floppy (device /dev/fd0) using Linux:

  •     dd if=boot.img of=/dev/fd0 bs=1440k

Recovery using the installation CD:

  • Insert Redhat binary install CD-ROM
  • Boot from CD (You may have to change BIOS settings)
  • At the boot: prompt, type linux rescue. You are then asked to chose an installation method.
  • Instead of install, choose the Upgrade option but don't add any new packages. It will eventually prompt you to make a boot floppy.
  • Boot from the boot floppy and mount your hard drive. i.e.: mount /dev/hda4 /hda4
    You can use fdisk as shown above to investigate your drives and partitions.

Creating a Bootable GRUB Legacy (V 0.57) CD:

This uses the GRUB files "menu.lst" and "stage2_eltorito".

  • mkdir -p iso/boot/grub
  • cp /lib/grub/i386-pc/stage2_eltorito iso/boot/grub
  • cp /lib/grub/i386-pc/menu.1st iso/boot/grub
  • Copy all files, OS files, etc to iso that you wish to put on the CD
  • mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o grub.iso iso
This generates a file grub.iso which can burned to CD or DVD.
See the YoLinux tutorial on how to burn a CD or DVD.

Related Information:

Hard Drive repair and recovery: