-
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.
-
Grub CD
I tried to make a Grub cd using nti cd maker. I chose data cd and to make it bootable. On the disk I have /iso/boot/grub/stage2_eltorito in a folder. When I tried to boot with this disk I get Starting PC Dos... MSCDEX V 2.25 and a dos prompt A:\>. Dir gives me a windows floppy directory. I can't see Grub at all. What went wrong ?
Acer Aspire 5610z,Vista HP, No problems with Vista... so far, but I'm learning Linux, just in case.
Acer Aspire 5315-2153, $348 Walmart Special,Mandriva Linux 2008.1 Spring Edition.
-
dwr50,
Welcome to Justlinux.
I don't known about your nti cd maker software. It is probably a Windows/Dos boot loader and you have only made a directory with the stage2_eltorito in directory /boot/grub.
You should do it with a Linux and use the terminal command "makisofs" which is available in nearly every Live CD.
The steps of making a bootable CD is fully described in Chapter 3.4 of the Grub Manual. I hope you do not mind reading the link instead of me repeating it here, as nothing is as good as the original. You are only 5 terminal commands away.
The mkisofs command in Linux makes an iso file out of any directory specified by you. Grub will be loaded if you include stage2_eltorito in the designated directory. There is nothing to it.
You can use the same procedure to make any bootable CD yourself, say customerised and published your own Live CD, etc.
-
Dos boot & Grub
Originally Posted by saikee
dwr50,
Welcome to Justlinux.
I don't known about your nti cd maker software. It is probably a Windows/Dos boot loader and you have only made a directory with the stage2_eltorito in directory /boot/grub.
You should do it with a Linux and use the terminal command "makisofs" which is available in nearly every Live CD.
The steps of making a bootable CD is fully described in Chapter 3.4 of the Grub Manual. I hope you do not mind reading the link instead of me repeating it here, as nothing is as good as the original. You are only 5 terminal commands away.
The mkisofs command in Linux makes an iso file out of any directory specified by you. Grub will be loaded if you include stage2_eltorito in the designated directory. There is nothing to it.
You can use the same procedure to make any bootable CD yourself, say customerised and published your own Live CD, etc.
I Was trying to make a DOS Boot And Grub Boot Disk that I can use on both my Vista PC and my Linux PC, I guess that when I used Ndi it only made Dos Boot available for booting. If I use Linux mkisofs is there a way to include Dos Boot on the same disk ?
Acer Aspire 5610z,Vista HP, No problems with Vista... so far, but I'm learning Linux, just in case.
Acer Aspire 5315-2153, $348 Walmart Special,Mandriva Linux 2008.1 Spring Edition.
-
It is highly unusual that you should need two boot loaders in the same booting media. You can put a version of Grub called Grub4Dos into a Dos partition.
ou then boot up a Dos and in Dos you fire up Grub4Dos, a Dos program, which terminates the Dos system and load a Grub.
In practice you should be able to fire up any installed operating system with Grub.
If you have installed an operating system that cannot bebooted up in a Grub prompt, available from a floppy, a CD, a USB device etc, I would like to know as I haven't found one yet.
Last edited by saikee; 12-15-2007 at 08:01 PM.
-
Hi guys,
I just tried to make a floppy and a cd with this method above.
I have kubuntu hardy installed in dual boot with windows xp. Kubuntu is on one hd and windows in on another. Grub is booting both with the menu.
problem:
With the floppy and the cd i made (copying the menu.lst of my kubuntu on both media), i can boot kubuntu without problem but when i tried to boot windows xp it says "error 15"
-
nightowl,
Welcome to Justlinux!
Tp solve your problem we need to have
(1) A print out of your menu.lst
(2) The output of "fdisk -l" in root terimnal in Kubuntu.
You can cut and paste the screen here.
-
As for my example, it is on a pc i will not be in front before 1 or 2 days.
But i just tried the same method on another one:
- i formatted a floppy with ext3 first (i say that in case it is important)
-i followed the tutorial, then after having finished, i just copied my kubuntu menu.lst on the floppy.
-when i try to boot this time i have 2 errors:
trying to boot win xp returns: error 13, invalid or unsupported executable format
trying to boot kubuntu returns: error 15, file not found.
here is the menu.lst, the very same being on the floppy:
Code:
# menu.lst - See: grub(8), info grub, update-grub(8)
# grub-install(8), grub-floppy(8),
# grub-md5-crypt, /usr/share/doc/grub
# and /usr/share/doc/grub-doc/.
## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not use 'savedefault' or your
# array will desync and will not let you boot your system.
default 0
## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout 15
## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
#hiddenmenu
# Pretty colours
#color cyan/blue white/blue
## password ['--md5'] passwd
# If used in the first section of a menu file, disable all interactive editing
# control (menu entry editor and command-line) and entries protected by the
# command 'lock'
# e.g. password topsecret
# password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
# password topsecret
#
# examples
#
# title Windows 95/98/NT/2000
# root (hd0,0)
# makeactive
# chainloader +1
#
# title Linux
# root (hd0,1)
# kernel /vmlinuz root=/dev/hda2 ro
#
#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST
### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below
## DO NOT UNCOMMENT THEM, Just edit them to your needs
## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
## kopt_2_6_8=root=/dev/hdc1 ro
## kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=UUID=29107684-a08e-453a-bde8-d53e8b29fe64 ro
## Setup crashdump menu entries
## e.g. crashdump=1
# crashdump=0
## default grub root device
## e.g. groot=(hd0,0)
# groot=(hd0,0)
## should update-grub create alternative automagic boot options
## e.g. alternative=true
## alternative=false
# alternative=true
## should update-grub lock alternative automagic boot options
## e.g. lockalternative=true
## lockalternative=false
# lockalternative=false
## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=quiet splash
## should update-grub lock old automagic boot options
## e.g. lockold=false
## lockold=true
# lockold=false
## Xen hypervisor options to use with the default Xen boot option
# xenhopt=
## Xen Linux kernel options to use with the default Xen boot option
# xenkopt=console=tty0
## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
## altoptions=(recovery) single
# altoptions=(recovery mode) single
## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
## howmany=7
# howmany=all
## should update-grub create memtest86 boot option
## e.g. memtest86=true
## memtest86=false
# memtest86=true
## should update-grub adjust the value of the default booted system
## can be true or false
# updatedefaultentry=false
## should update-grub add savedefault to the default options
## can be true or false
# savedefault=false
## ## End Default Options ##
title Ubuntu 8.04, kernel 2.6.24-16-generic
root (hd0,0)
kernel /boot/vmlinuz-2.6.24-16-generic root=UUID=29107684-a08e-453a-bde8-d53e8b29fe64 ro quiet splash
initrd /boot/initrd.img-2.6.24-16-generic
quiet
title Ubuntu 8.04, kernel 2.6.24-16-generic (recovery mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.24-16-generic root=UUID=29107684-a08e-453a-bde8-d53e8b29fe64 ro single
initrd /boot/initrd.img-2.6.24-16-generic
title Ubuntu 8.04, memtest86+
root (hd0,0)
kernel /boot/memtest86+.bin
quiet
### END DEBIAN AUTOMAGIC KERNELS LIST
title Windows XP professionel
map (hd0) (hd3)
map (hd3) (hd0)
root (hd3,0)
makeactive
chainloader +1
And here is my fdisk -l command:
Code:
sudo fdisk -l
Disque /dev/sda: 74.3 Go, 74355769344 octets
255 heads, 63 sectors/track, 9039 cylinders
Units = cylindres of 16065 * 512 = 8225280 bytes
Identifiant disque: 0x61b861b8
Périphérique Amorce Début Fin Blocs Id Système
/dev/sda1 * 1 2805 22531131 7 HPFS/NTFS
Disque /dev/sdb: 250.0 Go, 250059350016 octets
255 heads, 63 sectors/track, 30401 cylinders
Units = cylindres of 16065 * 512 = 8225280 bytes
Identifiant disque: 0x000f3653
Périphérique Amorce Début Fin Blocs Id Système
/dev/sdb1 * 1 4377 35158221 83 Linux
/dev/sdb2 4378 13252 71288437+ 5 Extended
/dev/sdb3 13253 15164 15358140 b W95 FAT32
/dev/sdb4 15165 30401 122391202+ 83 Linux
/dev/sdb5 4378 12887 68356543+ 83 Linux
/dev/sdb6 12888 13252 2931831 82 Linux swap / Solaris
Disque /dev/sdc: 164.6 Go, 164696555520 octets
255 heads, 63 sectors/track, 20023 cylinders
Units = cylindres of 16065 * 512 = 8225280 bytes
Identifiant disque: 0x49f949f8
Périphérique Amorce Début Fin Blocs Id Système
/dev/sdc1 1 4569 36700461 83 Linux
/dev/sdc2 4570 10943 51199155 f W95 Etendu (LBA)
/dev/sdc3 * 10944 20023 72935100 7 HPFS/NTFS
/dev/sdc5 4570 10943 51199123+ 7 HPFS/NTFS
Disque /dev/sdd: 164.6 Go, 164696555520 octets
255 heads, 63 sectors/track, 20023 cylinders
Units = cylindres of 16065 * 512 = 8225280 bytes
Identifiant disque: 0x7bf2fca1
Périphérique Amorce Début Fin Blocs Id Système
/dev/sdd1 * 1 9887 79417296 b W95 FAT32
/dev/sdd2 9888 20023 81417420 83 Linux
Disque /dev/sde: 2048 Mo, 2048901120 octets
64 heads, 63 sectors/track, 992 cylinders
Units = cylindres of 4032 * 512 = 2064384 bytes
Identifiant disque: 0x9fe29fe2
Périphérique Amorce Début Fin Blocs Id Système
/dev/sde1 * 1 992 1999840+ 6 FAT16
-
nightowl,
The information appears to show that you have 4 hard disks
sda - 1 partition in NTFS filing system (likely to be your Xp)
sdb - 5 partition excluding the extended partition sdb2 which contain a Linux in sdb5 and sdb6, sdb1 also a Linux and sdb3 in Fat32 possibly for data
sdc - 3 partitions excluding the extended partition sdc2, 1st one Linux, sdc3 and sdc5 are NTFS partitions
sdd - 2 partitions, one Win95 of type Fat32 (possibly Dos) with a Linux in sdd2
and a flash drive of 2Gb as it is too small for a hard disk plus fat16 is the standard filing system for USB pen drive with 2Gb or less capacity.
-------------------------------------------------------------
The menu.lst
Code:
title Ubuntu 8.04, kernel 2.6.24-16-generic
root (hd0,0)
kernel /boot/vmlinuz-2.6.24-16-generic root=UUID=29107684-a08e-453a-bde8-d53e8b29fe64 ro quiet splash
initrd /boot/initrd.img-2.6.24-16-generic
quiet
tells us your kubuntu was booted from the 1st partition of the 1st boot disk (hd0,0).
Your Xp was booted by these commands
Code:
title Windows XP professionel
map (hd0) (hd3)
map (hd3) (hd0)
root (hd3,0)
makeactive
chainloader +1
This means the Xp was at the 1st partition of the 4th disk known to Grub as (hd3,0).
Your problem is a common dilemma of every PC user going for multi-boot.
Basically the mobo has a hard disk detction sequence pre-fixed by manufacturer telling the hardware the order the Bios must check the hard disk controllers (IDE, Sata, SCSCI controllers etc). Thus by hooking the various hard disks to the connection points in the mobo the sda, sdb, sdc and sdd will be decided by the mobo. The USB ports are always detected after internal hard disks and that is why the device sde was given to the 2Gb USB flash drive.
However every Bios nowaday allows its user to select any of the hard disks to become the first boot disk and this can get the disk order re-assigned, without the user knowing it, even though the sda to sde device names remain unchanged. Thus the evidence would suggest your sda was the 4th boot disk (hd3) and possibly sdb or sdc was nominated by you as the first boot disk (hd0). As XP has to be re-map as (hd0) while booting. That tells us Xp was originally installed as the 1st boot disk but the first boot disk was later re-assigned.
When you boot the system with a floppy the Bios has no chance to reach the hard disk booting order specified by you in the Bios setting because the floppy device was booted first. Therefore the original disk order pre-fixed by the mobo manufacturer might have prevailed.
This means temporarily by using the floppy to boot you might have the hard disks order re-arranged back to the factory default order.
Thus when you boot the Xubuntu it possibly go into sda1 and could not find the Linux files because it is a NTFS partition.
When you try to boot Xp Grub goes into the 1st partition of the 4th disk (hd3,0) and possibly found sdd1. Error 13 will be reported if there is no boot loader found there. The command "chainloader +1" is to instruct Grub to pass its control to the boot loader residing at the +1 position of that partition specified by the "root" command. Grub is honest if it can't pass the control it reports such format is not supported because it doesn't know what to do next.
The above is just the explanation. The following is the cure.
------------------------------------------------------------------
You need to establish the disk order again. This is very easy with Grub. At the booting screen press the "c" key to drop into a Grub prompt. Type these command to ask Grub to tell you the order of the 4 disks
Code:
geometry (hd0)
geometry (hd1)
geometry (hd2)
geometry (hd3)
If (hd0) shows up only one partition with Type 7 indicating ntfs filing type then Xp can be boot manually by these commands in Grub prompt
Code:
root (hd0,0)
chainloader +1
boot
How to find out which disk or partition has Xubuntu. That is easy as well. Ask Grub by this command
Code:
find /boot/grub/menu.lst
Grub will report back with the answer like "(hd1,0)" meaning it find it in that partition.
Your Xubuntu if in (hd1,0) then these commands in Grub prompt will fire it up
Code:
root (hd1,0)
configfile /boot/grub/menu.lst
Once you know how to boot the systems manually you can amend the menu.lst using the same commands except
(1) You add the "title" statement to tell yourself the name of the OS
(2) You can omit the "boot" statement. It is only manadatory in manual booting.
Now you know why a Grub floppy is the most lethal weapon in the booting business. You can boot virtually any installed operating system in a PC with a humble floppy.
Last edited by saikee; 01-06-2009 at 08:05 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|