LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 07-15-2010, 01:56 AM   #1
cr4321
Member
 
Registered: Aug 2009
Posts: 41

Rep: Reputation: 15
Post Create independent Grub2 boot loader menu in USB stick.


Hi guys,

I am looking for a step by step approach - the "do-it-yourself" kind to achieve what I mentioned in the subject. I've a little knowledge of programming - so, will need hand-holding, to carry out terminal commands! Since I am at the lower end of the learning curve, explanations will be essential to grasp and understand what I am doing. I am sure, this will help a lot of late starters like me!

Let me elaborate on what I am planning on, and my requirements.

I have 2 old disks now. In each, I have windows in the Primary drive. I have installed Ubuntu, Fedora, Mint, Suse, etc. etc. versions in the residing in the extended partitions. (Crazy, but, this is just a hobby to me. I like to check and try out various distros' as they come, and maybe I plan to add one more disk!) Both of them have their own boot menus and I have to change the boot options in the BIOS every time to switch.

When I read references to Grub2, chain loading etc. I understood enough to know that I can accomplish this with a simpler option. Only my knowledge is too limited to implement it!

My wish list is to have Grub2 installed in any USB. So, when I boot through the USB, I should have the complete menu to boot onto any OS in the whole System - from the USB. Also, when I install a new flavour, or remove an old one, an update-grub should update new menu!

On the other hand, the boot loaders in the individual disks also should not be disturbed, so that I can boot into any disk by the BIOS method.

I am willing to experiment, and maybe even document it for others, if only a few of you can spare some of your time. I am sure, you can guide me, but you will need some patience! If you have any questions, please shoot.

Thanks in advance - and I do find these forums very informative.

cr4321
 
Old 07-15-2010, 10:05 AM   #2
skykooler
Member
 
Registered: Feb 2010
Distribution: Ubuntu
Posts: 84

Rep: Reputation: 17
First, open a terminal (in any linux distro, I am using Ubuntu) and type
Code:
sudo fdisk -l
Enter your administrator password. This will print out a list of your disks and partitions, something like
Code:
Device    Start     End       Blocks    Id System
/dev/sda1 * 2048    109563299 54780626  7  NTFS
/dev/sda2 109563300 151187714 20812207+ 83 Linux
/dev/sdb1 151187715 156296384 2554335   82 Linux swap
Find the one which is the same size as your USB drive (subtract Start from End). It will probably be formatted as FAT. Next, type
Code:
sudo mkdir /mnt/root
This creates a folder in which you will mount your drive. Then type
Code:
sudo mount -t ext3 /dev/sdxy /mnt/root
where x and y are the same as the USB filesystem. Next, type
Code:
sudo mount -t proc none /mnt/root/proc
sudo mount -o bind /dev /mnt/root/dev
This allows GRUB to discover your drives. Finally, type
Code:
sudo grub-install "(hdx,z)"
Z is y-1. Grub uses a slightly different numbering system for drives. This should install GRUB to your USB drive!
 
Old 07-15-2010, 10:45 AM   #3
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 112Reputation: 112
Using a USB flash drive to house Grub is a bad idea.

Reason:

If you install a Linux in an internal hard disk and boot from it that disk is the 1st boot disk and all the intructions in the boot loader and Linux register it being installed from the position of 1st boot disk.

If you boot from a USB device you tell the Bios that is your new 1st boot disk and so the internal hard disk has to be relegated to the 2nd disk position and this can cause booting problem.

Cure:


Put Grub in a floppy or CD (with or without the booting menu.)

If a floppy or a CD is booted the original 1st boot disk is still valid and not altered.

Advice:


Forget about the booting menu. Just a Grub prompt will do. This mean just install Grub1 or Grub2 on its own. Check out just booting tips in my signature for putting Grub in various devices. No installed operating system in a PC cannot be booted manually by a Grub prompt.

Last edited by saikee; 07-15-2010 at 10:47 AM.
 
Old 07-15-2010, 12:24 PM   #4
cr4321
Member
 
Registered: Aug 2009
Posts: 41

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by skykooler View Post
Code:
sudo fdisk -l
I got the USB as "sdc1"
Code:
sudo mkdir /mnt/root
This creates a folder in which you will mount your drive. Then type
Code:
sudo mount -t ext3 /dev/sdxy /mnt/root
This is the message I got :
mount: /dev/sdc1 already mounted or /mnt/root busy
mount: according to mtab, /dev/sdc1 is mounted on /media/usb0
Code:
sudo mount -t proc none /mnt/root/proc
sudo mount -o bind /dev /mnt/root/dev
For the above two commands the message was :
cr@cr-ub10:~$ sudo mount -t proc none /mnt/root/proc
mount: mount point /mnt/root/proc does not exist

cr@cr-ub10:~$ sudo mount -o bind /dev /mnt/root/dev
mount: mount point /mnt/root/dev does not exist

Due to the above messages, I have not gone further and committed myself. Is this the right message?

A question : If I mount the drive within the hard disk, will it not give an error message when this drive is not present (when I want to boot disks independently?

Meanwhile there is another post with some more links - let me also read that till I get your response.

Code:
sudo grub-install "(hdx,z)"
Z is y-1. Grub uses a slightly different numbering system for drives. This should install GRUB to your USB drive!
(This part is not committed yet. Please confirm if it is ok to go ahead?)
 
Old 07-15-2010, 12:58 PM   #5
cr4321
Member
 
Registered: Aug 2009
Posts: 41

Original Poster
Rep: Reputation: 15
Saikee,

Ok, I am now on hold till I have further confirmation...

You said it is a "bad idea" due to the reasons given. Is there any way to overcome that problem? I read about issuing commands to "re-map" the 1st and 2nd disks "on-the-fly". Or is it not applicable here?

I am going thru the links you posted on your signature, and even on second reading, it all seems to be a bit "beyond me" - since my basics are rather fudgy!

Any way, I will await clarity before I proceed further.

Thanks a ton, for raising a alert - since I do not want to ruin the current setup!

cr4321
 
Old 07-15-2010, 01:02 PM   #6
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 112Reputation: 112
cr4321,

Yes you can use "drivemap" in Grub2 or "map" in Grub1 to change the disk order. It is a bit of inconvenience which is avoidable if you put Grub in a CD or a floppy.

Once booted up, say from a CD, you can ask Grub to boot any disk, USB device, flash drive etc.

In your following skykooler the error
Code:
mount: according to mtab, /dev/sdc1 is mounted on /media/usb0
means your sdc1 partition is already mounted as /media/usb0. Therefore to proceed you do the following
Code:
sudo su
mkdir /media/usb0/proc
mkdir /media/usb0/dev
mount -t proc none /media/usb0/proc
mount -o bind /dev /media/usb0/dev
grub-install /media/usb0
I normally only use just the last two commands to put Grub2 in a partition as I like using just the Grub prompt on its own.

Last edited by saikee; 07-15-2010 at 01:12 PM.
 
Old 07-15-2010, 01:21 PM   #7
cr4321
Member
 
Registered: Aug 2009
Posts: 41

Original Poster
Rep: Reputation: 15
Smile

Saikee,

Please confirm if I can try out the commands as you said. Is there a risk that I will spoil the current setup?

At least if it will not disturb the disks (minus the usb) - then it is okay for me.

Also, I am not clear about the "mapping" - I read about it but lack exact meaning - or how to do it in the current situation!

Thanks... I will await your input..
 
Old 07-15-2010, 01:30 PM   #8
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 112Reputation: 112
To put Grub2 in a partition all you need is to mount that partition and do a "grub-install". The extra bits are to ensure the dev names etc are available during the grub-install.

The "map" command must be used in pair for exchange the order of two disks.

In Grub1 the disk (hd0) and (hd1) will be swapped after these two statements
Code:
map (hd0) (hd1)
map (hd1) (hd0)
If Grub2 is used replace "map" with "drivemap".

Lilo also provide something similar.

The disk order is given from the Bios information. Grub just acts a a middleman to swap the two disk order. After the Linux has been powered down the original disk order prevails.

Last edited by saikee; 07-15-2010 at 01:32 PM.
 
Old 07-15-2010, 01:38 PM   #9
cr4321
Member
 
Registered: Aug 2009
Posts: 41

Original Poster
Rep: Reputation: 15
This is what I get. Can't understand the "error" - since it has already created the 2 directories on the USB.
(I am using Grub2 (Ubuntu 10.04)

cr@cr-ub10:~$ sudo su
[sudo] password for cr:
root@cr-ub10:/home/cr# mkdir /media/usb0/proc
root@cr-ub10:/home/cr# mkdir /media/usb0/dev
root@cr-ub10:/home/cr# mount -t proc none /media/usb0/proc
root@cr-ub10:/home/cr# mount -o bind /dev /media/usb0/dev
root@cr-ub10:/home/cr# grub-install /media/usb0
/usr/sbin/grub-probe: error: /media/usb0 is not a block device.
/usr/sbin/grub-setup: error: cannot seek `/media/usb0'.

Can you tell me how to overcome the error?

Thanks...
 
Old 07-15-2010, 01:49 PM   #10
cr4321
Member
 
Registered: Aug 2009
Posts: 41

Original Poster
Rep: Reputation: 15
This is what I get. Can't understand the "error" - since it has already created the 2 directories on the USB.
(I am using Grub2 (Ubuntu 10.04). I do not have a floppy drive, and I do not know how to install grub in a CD!

cr@cr-ub10:~$ sudo su
[sudo] password for cr:
root@cr-ub10:/home/cr# mkdir /media/usb0/proc
root@cr-ub10:/home/cr# mkdir /media/usb0/dev
root@cr-ub10:/home/cr# mount -t proc none /media/usb0/proc
root@cr-ub10:/home/cr# mount -o bind /dev /media/usb0/dev
root@cr-ub10:/home/cr# grub-install /media/usb0
/usr/sbin/grub-probe: error: /media/usb0 is not a block device.
/usr/sbin/grub-setup: error: cannot seek `/media/usb0'.

Can you tell me how to overcome the error?

Thanks...
 
Old 07-15-2010, 02:21 PM   #11
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 112Reputation: 112
To make a Grub2 CD just follow the Task K2 of "just booting tips" in my signature.

I copied skykooler's commands quickly. Come to think of it the correct syntax should be
Code:
grub-install --root-directory=/media/usb0 /dev/sdc
You specify /dev/sdc1 should be the home of Grub2 and its boot loader is to be booted from the MBR of the USB drive itself so it has to be /dev/sdc.

The kubuntu forum site has a very detailed Grub2 Guide which is among the best to be found.

Last edited by saikee; 07-15-2010 at 02:23 PM.
 
1 members found this post helpful.
Old 07-15-2010, 08:54 PM   #12
cr4321
Member
 
Registered: Aug 2009
Posts: 41

Original Poster
Rep: Reputation: 15
Wow, that was finally accomplished. ahem. Thanks again.
Now I have 3 new directories in the USB - /boot, /dev and /proc

The message was :

[code]
root@cr-ub10:/home/cr#
root@cr-ub10:/home/cr# grub-install --root-directory=/media/usb0 /dev/sdc
Installation finished. No error reported.
root@cr-ub10:/home/cr#
[code]

Just now I rebooted the machine with the USB. I think, I got the same menu as before. (it did not seem as if it booted thru the USB and even if it did, it did not show up the boot menus of the 2nd disk. I will recheck that, but would like your comments too.

Meanwhile, I am reading your link about booting from cd. 1st line creates a rescue image. What does the 2nd line mean? - wodim?

[code]
grub-mkrescue --image-type=cdrom /tmp/grub-rescue.iso
wodim /tmp/grub-rescue.iso
[code]

Last edited by cr4321; 07-15-2010 at 08:56 PM.
 
Old 07-16-2010, 01:51 AM   #13
cr4321
Member
 
Registered: Aug 2009
Posts: 41

Original Poster
Rep: Reputation: 15
Hello,

Everything seemed all right as below :

root@cr-ub10:/home/cr# grub-install --root-directory=/media/usb0 /dev/sdc
Installation finished. No error reported.

But want to re-confirm that it is not booting from USB...
 
Old 07-16-2010, 02:42 AM   #14
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 112Reputation: 112
I think the two lines combined create an iso image for Grub2 to be burnt into a CD. I have done it couple of time and can confirm that it works.

You can use any Grub to boot any device. Here is how you do

At the Grub2 booting screen do not boot any system but just press the "c" key to drop into a Grub prompt. Issue command
[code[ls[/code]which will list out all the partitions in the PC. These are just (hd0,1), (hd0,2)...(hd1,1), (hd1,2)..
By examining the number of partitions in each disk you should have an idea which is which.

As you have sdc as a flash drive and created sdc1 there so mostly this would be (hd2,1) assuming you have not instruct the Bios to boot flash drive first and there are sda and sdb disks in the PC. You can then try the Grub2 you have just installed in sdc by command
Code:
set root=(hd2)
chainloader +1
boot
you should now see Grub2 that you have installed. It could be just a Grub prompt.

Equally when you are in sdc Grub2 prompt you can jump back to the original disk (hd0) by commands
Code:
set root=(hd0)
chainloader +1
boot
My point is once you have Grub2 you can go into any device, check its directory, boot up whatever system inside, etc, etc....
 
Old 07-16-2010, 09:19 AM   #15
cr4321
Member
 
Registered: Aug 2009
Posts: 41

Original Poster
Rep: Reputation: 15
Saikee,

Thanks for all the guidance so far, but I think I missed something somewhere ... or there is some other problem that I can't identify. I checked all over that I have carried out the instructions right. The current situation is :

1) USB
a) It is not booting from USB - in spite of BIOS settings.
b) from grub prompt "ls" shows only (hd0) and (hd1) drives.
c) set root=(hd2) - does not show any error.
d) "chainloader +1" and "boot" command give error "h2 cannot get C/H/S values.
(missing to give the drivemap command at some point ?)

d) set root=(hd0) + chainloader +1 + boot - leads to disk1 menu
e) set root=(hd1) + chainloader +1 + boot - leads to windows on disk i
f) (maybe because there is no grub in disk2 ?)

2) As for the CD - I tried
mkrescue ...... (it shows error - "unknown command - mkrescue"
(doubt - even tab did not show that command)

I am somewhere near, I know - just requires that one last push!!!

Do give me some hints at they occur to you. Thanks for all your help so far.
 
  


Reply

Tags
grub2, menu, multiboot, usb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to boot from an USB stick without BIOS support using Grub2? vimico Linux - Laptop and Netbook 11 02-25-2012 05:19 PM
how to create usb recovery boot stick? gunzzz5930 Slackware 3 05-18-2010 08:54 PM
GRUB2 - FreeBSD-8.0 does not show up in triple boot menu, dual boot menu it does.. wiliweld *BSD 7 05-03-2010 01:05 PM
Grub2 (1.96) loopback problem on usb-stick ganimo Linux - General 4 10-01-2009 07:26 AM
boot loader on a usb stick gothicbob Linux - Newbie 4 08-19-2007 11:03 AM


All times are GMT -5. The time now is 01:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration