Linux Recovery and Boot Disk Creation


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:

    GNU/GRUB Home page
    GNU/GRUB online manual
    GNU/GRUB FAQ

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:

    cd /lib/grub/i386-pc
    dd if=stage1 of=/dev/fd0 bs=512 count=1
    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:

    mke2fs /dev/fd0
    mount -t ext2 /dev/fd0 /mnt/floppy
    grub-install --root-directory=/mnt/floppy fd0
    umount /mnt/floppy

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:

    fdformat /dev/fd0H1440 # Lay tracks on new diskette
    mkfs -t minix /dev/fd0 1440 # Create minix file system on floppy
    mount /dev/fd0 /mnt/floppy # Mount floppy
    cp -p /boot/chain.b /mnt/floppy # Copy chain loader
    cp -p /boot/boot* /mnt/floppy
    lilo -v -C /etc/lilo.floppy # Install lilo and the map onto floppy
    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)

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:

    Boot computer with the floppy in it's drive.

    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:

    Toms.net Linux on 1 floppy disk
    Rescue images (ibiblio.org)

    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.



{ 0 komentar... read them below or add one }

Post a Comment