How to put Grub into floppy, pen drive, hard disk or CD/DVD


Results 1 to 9 of 9

Thread: How to put Grub into floppy, pen drive, hard disk or CD/DVD

Threaded View

  1. #1
    Join Date
    Jun 2004
    Location
    Newcastle upon Tyne
    Posts
    2,978

    How to put Grub into floppy, pen drive, hard disk or CD/DVD

    To put Grub into a bootable media is very simple. The basic steps are

    • Boot up a Linux in a hard disk or a Live CD that has Grub
    • Use Linux to "find" the directory that stores Grub's stage1 file
    • Format if necessary the proposed booting media (floppy or hard disk partition)
    • Mount the proposed booting device
    • Make a directory /boot/grub in the proposed booting media
    • Copy Grub's stage1 and stage2 files into the proposed bootable media
    • Use a Grub shell to put Grub into the MBR of the proposed media


    The Grub implementation here is unconventional in that Grub is not attached to an operating system and would only boots up to a Grub prompt. The operating system must be booted manually, unless of course a menu.lst is written to automatic the booting process. The advantage of a Grub prompt is that AFAIK every installed operating system in a PC can be booted by it. The method of booting a Linux system up manually is described here. Booting MS systems manually (BSD, Solaris and chainloadable Linux also applicable) is showed in this thread.

    A Grub prompt can be used to boot up any installed operating system and restore Grub in a Linux uses it as the boot loader. It is also a great diagnostic tool as I explain later.

    The commands below are executed from an installed Ubuntu 7.10. Text in blue are commands I entered at the terminal.

    To put Grub into a CD/DVD - A CD/DVD is booted by a special Grub file called stage2_eltorito.

    Code:
    saikee@saikee-desktop:~$ su
    Password: 
    
    root@saikee# find / -name stage1
    /boot/grub/stage1
    /usr/lib/grub/x86_64-pc/stage1
    root@saikee# mkdir rub
    root@saikee# cd rub
    root@saikee/rub# mkdir iso
    root@saikee/rub# mkdir -p iso/boot/grub
    root@saikee/rub# cp /usr/lib/grub/x86_64-pc/stage2_eltorito iso/boot/grub
    root@saikee/rub# mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot \
              -boot-load-size 4 -boot-info-table -o grub.iso iso
    Setting input-charset to 'UTF-8' from locale.
    Size of boot image is 4 sectors -> No emulation
    Total translation table size: 2048
    Total rockridge attributes bytes: 840
    Total directory bytes: 4096
    Path table size(bytes): 34
    Max brk space used 0
    233 extents written (0 MB)
    root@saikee/rub# ls
    grub.iso  iso
    root@saikee/rub# k3b grub.iso 
    In the above two directories were reported to have stage1 inside. Ican choose either. /usr/lib/grub/x86_64-pc was selected because this is the normal storage location of Grub system files. The commands in orange were copied from the Chapter 3.4 of the Grub manual with the underlined section adjusted to suit my case here. The operation involved copying just one file of stage2_eltorito into the directory /boot/grub and using Linux's command mkisofs to make an iso file called grub.iso which I listed out after it has been formed. The grub.iso with stage2_eltorito inisde is just 450k byte large and can be a huge waste for a 700Mb CD. It is even more wasteful to burn it on a DVD, unless the media is a rewriteable. However the resulting CD or DVD can be used to boot any operating system in a PC.

    If you use a Live CD you may have to install the K3B package which I used here to burn the iso into a bootable CD.



    To put Grub into a partition - which can be inside a pen drive, an internal hard disk or an external USB hard disk.

    A partition here is sde1 and is the 1st partition of the 5th disk in my case. The partition number and the disk order can be found by "fdisk -l" in Linux and then verified by the "geometry (hdi)" command in a Grub shell, where (hdi) is the i+1 disk because Grub counts from 0.

    Grub can only be installed into a partition with a filing system that Grub can read. Thus Grub cannot be installed in a NTFS partition but alright in fat16 and fa32 partitions. Like a Linux Grub can boot from either a primary or a logical partition.
    Code:
    root@saikee/rub# mkdir /mnt/sde1
    root@saikee/rub# mount /dev/sde1 /mnt/sde1
    root@saikee/rub# mkdir /mnt/sde1/boot
    root@saikee/rub# mkdir /mnt/sde1/boot/grub
    root@saikee/rub# cp /usr/lib/grub/x86_64-pc/stage1 /mnt/sde1/boot/grub
    root@saikee/rub# cp /usr/lib/grub/x86_64-pc/stage2 /mnt/sde1/boot/grub
    root@saikee/rub# grub
    Probing devices to guess BIOS drives. This may take a long time.
           [ Minimal BASH-like line editing is supported.   For
             the   first   word,  TAB  lists  possible  command
             completions.  Anywhere else TAB lists the possible
             completions of a device/filename. ]
    grub> geometry (hd4)
    geometry (hd4)
    drive 0x84: C/H/S = 1019/62/62, The number of sectors = 3918848, /dev/sde
       Partition num: 0,  Filesystem type is fat, partition type 0xc
    grub> root (hd4,0)
    root (hd4,0)
    grub> setup (hd4)
    setup (hd4)
     Checking if "/boot/grub/stage1" exists... yes
     Checking if "/boot/grub/stage2" exists... yes
     Checking if "/boot/grub/fat_stage1_5" exists... no
     Running "install /boot/grub/stage1 (hd4) /boot/grub/stage2 p /boot/grub/menu.lst "... succeeded
    Done.
    grub> quit
    quit
    root@saikee/rub#

    To put Grub into a floppy - A floppy is often named as device (fd0) in Linux.
    Code:
    root@saikee# mkdir /mnt/fd0
    mkdir: cannot create directory `/mnt/fd0': File exists
    root@saikee# mount /dev/fd0 /mnt/fd0
    root@saikee# mkdir /mnt/fd0/boot
    root@saikee# mkdir /mnt/fd0/boot/grub
    root@saikee# cp /usr/lib/grub/x86_64-pc/stage1 /mnt/fd0/boot/grub
    root@saikee# cp /usr/lib/grub/x86_64-pc/stage2 /mnt/fd0/boot/grub
    root@saikee# ls /mnt/fd0/boot/grub
    stage1  stage2
    root@saikee# grub
    Probing devices to guess BIOS drives. This may take a long time.
           [ Minimal BASH-like line editing is supported.   For
             the   first   word,  TAB  lists  possible  command
             completions.  Anywhere else TAB lists the possible
             completions of a device/filename. ]
    
    grub> root (fd0)
    root (fd0)
    grub> setup (fd0)
    setup (fd0)
     Checking if "/boot/grub/stage1" exists... yes
     Checking if "/boot/grub/stage2" exists... yes
     Checking if "/boot/grub/fat_stage1_5" exists... no
     Running "install /boot/grub/stage1 (fd0) /boot/grub/stage2 p /boot/grub/menu.lst "... succeeded
    Done.
    grub> quit
    quit
    root@saikee#
    A Grub on a floppy or a CD has a very important feature that is different from the same Grub on a pen drive or a hard disk. This is because a pen drive or a hard disk has to obey Bios boot disk order whereas Grub in a floppy or CD does not.

    Suppose a user has a Pata, a Sata and a USB pen drive and instructs the Bios to boot the USB device first. The Grub on the pen drive sees the pen drive, Pata and Sata as 1st, 2nd and 3rd disk respectively or (hd0), (hd1) and (hd2).

    The floppy or CD Grub fires up without the Bios reaching the boot disk order stage and so the detection of 1st, 2nd and 3rd disks is purely according to the hardware in-build instructions. Normally (hd0) will be given to the Pata, Sata gets the (hd1) and the external USB device will be detected last and assigned (hd2). Thus using a Grub floppy or CD one get the true hardware detection of the hard disk. From this point onward the information obtainable from Grub is the true hardware information on the hard disk not influenced by a Linux kernel. or Bios setup.
    Last edited by saikee; 11-11-2007 at 12:12 PM.
    Linux user started Jun 2004 - No. 361921
    Using a Linux live CD to clone XP
    To install Linux and keep Windows MBR untouched
    Adding extra Linux & Doing it in a lazy way
    A Grub menu booting 100+ systems & A "Howto" to install and boot 145 systems
    Just cloning tips Just booting tips A collection of booting tips

    Judge asked Linux "You are being charged murdering Windoze by stabbing its heart with a weapon, what was it?" Replied Linux "A Live CD"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •