LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Create independent Grub2 boot loader menu in USB stick. (https://www.linuxquestions.org/questions/linux-general-1/create-independent-grub2-boot-loader-menu-in-usb-stick-819912/)

cr4321 07-15-2010 01:56 AM

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

skykooler 07-15-2010 10:05 AM

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!

saikee 07-15-2010 10:45 AM

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.

cr4321 07-15-2010 12:24 PM

Quote:

Originally Posted by skykooler (Post 4034071)
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?)

cr4321 07-15-2010 12:58 PM

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

saikee 07-15-2010 01:02 PM

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.

cr4321 07-15-2010 01:21 PM

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..

saikee 07-15-2010 01:30 PM

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.

cr4321 07-15-2010 01:38 PM

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...

cr4321 07-15-2010 01:49 PM

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...

saikee 07-15-2010 02:21 PM

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.

cr4321 07-15-2010 08:54 PM

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]

cr4321 07-16-2010 01:51 AM

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...

saikee 07-16-2010 02:42 AM

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....

cr4321 07-16-2010 09:19 AM

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.

saikee 07-16-2010 09:37 AM

I used (hd2) in thinking since your USB disk is sdc so there must be sda and sdb. The corresponding names to Grub2 are therefore (hd0), (hd1) and (hd2).

To solve the mystery can you post here the output of
Code:

sudo fdisk -l
Also after (hd1) and (hd0) in Grub2 "ls" command you should get (hd0,1), (hd0,2)....etc. Can you confirm the number of partitions in both (hd0) and (hd1). This information can then correlated with "fdisk-l" in Linux.

It has been known that for some mobo booting from a USB device is only possible if the Bios function "legacy USB support" is switched on. If the mobo does not have this function then it can either able to do it automatically or technically unable to carry out such a task.

The mkrescue is a system command and might require you to be in root.

Thus you can either prefix the command with "sudo", like "sudo mkrescue ...." or you type "su" once, supply your password and then able to work with the system commands untit you exit the terminal.

cr4321 07-16-2010 10:47 PM

Sorry, I did not notice that this has jumped to page-2 - hence the delay!

Now, the output as you requested for sudo fdisk -l :

cr@cr-ub10:~$ sudo fdisk -l
[sudo] password for cr:

Disk /dev/sdb: 40.1 GB, 40060403712 bytes
255 heads, 63 sectors/track, 4870 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00049ce0

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 1046 8401963+ b W95 FAT32
/dev/sdb2 1047 4870 30716249+ f W95 Ext'd (LBA)
/dev/sdb5 1047 2092 8401963+ 83 Linux
/dev/sdb6 2093 3138 8401920 83 Linux
/dev/sdb7 3139 4087 7622811 83 Linux
/dev/sdb8 4088 4609 4192933+ b W95 FAT32
/dev/sdb9 4610 4870 2096451 82 Linux swap / Solaris

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00070b56

Device Boot Start End Blocks Id System
/dev/sda1 * 1 3916 31455238+ c W95 FAT32 (LBA)
/dev/sda2 3917 19457 124833082+ 5 Extended
/dev/sda5 3917 7832 31455238+ b W95 FAT32
/dev/sda6 7833 11748 31455238+ b W95 FAT32
/dev/sda7 11749 15664 31455238+ b W95 FAT32
/dev/sda8 15665 19457 30467241 b W95 FAT32

Disk /dev/sdc: 1027 MB, 1027603456 bytes
255 heads, 63 sectors/track, 124 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x01040a50

Device Boot Start End Blocks Id System
/dev/sdc1 * 1 125 1003487+ c W95 FAT32 (LBA)
Partition 1 has different physical/logical endings:
phys=(123, 254, 63) logical=(124, 237, 47)
cr@cr-ub10:~$

Meanwhile, since it was not booting to USB - I tried out another USB (which I had used for booting SLAX, which I formated - to eliminate the possibility of unbootable USB).

Still, it is not booting after grub2 was installed on it.

Moreover, at grub prompt - the command "ls" only shows (hd0) and (hd1) with all their respective partitions.

Thanks s far...

cr4321 07-17-2010 12:36 AM

Finally, for the grub rescue cd part, this was generated and a cd was written.
This was the terminal commands, and the output messages :
Quote:

cr@cr-ub10:~$ grub-mkrescue -h
Usage: /usr/bin/grub-mkrescue [OPTION] SOURCE...
Make GRUB rescue image.

-h, --help print this message and exit
-v, --version print the version information and exit
--modules=MODULES pre-load specified modules MODULES
--output=FILE save output in FILE [required]

/usr/bin/grub-mkrescue generates a bootable rescue image with specified source files or directories.

Report bugs to <bug-grub@gnu.org>.

cr@cr-ub10:~$ sudo grub-mkrescue -v
/usr/bin/grub-mkrescue (GNU GRUB 1.98-1ubuntu6)
---------------------------------------------------------------------------
cr@cr-ub10:~$ grub-mkrescue --output=/tmp/grub-rescue.iso
Enabling BIOS support ...
Unknown file type /tmp/grub-mkrescue.7Ajlcy60JV/.. - ignoring and continuing.
Using SEARCH_F.000;1 for /tmp/grub-mkrescue.7Ajlcy60JV/boot/grub/i386-pc/search_fs_uuid.mod (search_fs_file.mod)
Using MULTIBOO.000;1 for /tmp/grub-mkrescue.7Ajlcy60JV/boot/grub/i386-pc/multiboot.mod (multiboot2.mod)
Using PASSWORD.000;1 for /tmp/grub-mkrescue.7Ajlcy60JV/boot/grub/i386-pc/password_pbkdf2.mod (password.mod)
Using GCRY_SHA.000;1 for /tmp/grub-mkrescue.7Ajlcy60JV/boot/grub/i386-pc/gcry_sha256.mod (gcry_sha512.mod)
Using GCRY_SHA.001;1 for /tmp/grub-mkrescue.7Ajlcy60JV/boot/grub/i386-pc/gcry_sha512.mod (gcry_sha1.mod)

Size of boot image is 48 sectors -> No emulation
Total extents actually written = 640
Total translation table size: 0
Total rockridge attributes bytes: 15574
Total directory bytes: 31200
Path table size(bytes): 64
Max brk space used 23000
640 extents written (1 MiB)
cr@cr-ub10:~$
-----------------------------------------------------------------------------
cr@cr-ub10:~$ wodim /tmp/grub-rescue.iso
wodim: No write mode specified.
wodim: Assuming -tao mode.
wodim: Future versions of wodim may have different drive dependent defaults.
wodim: Operation not permitted. Warning: Cannot raise RLIMIT_MEMLOCK limits.
Device was not specified. Trying to find an appropriate drive...
Looking for a CD-R drive to store 1.25 MiB...
Detected CD-R drive: /dev/sr0
Device type : Removable CD-ROM
Version : 5
Response Format: 2
Capabilities :
Vendor_info : 'HL-DT-ST'
Identification : 'DVD-RAM GH22NP20'
Revision : '1.04'
Device seems to be: Generic mmc2 DVD-R/DVD-RW.
Using generic SCSI-3/mmc DVD-R(W) driver (mmc_mdvd).
Driver flags : SWABAUDIO BURNFREE
Supported modes: PACKET SAO
Speed set to 22160 KB/s
Starting to write CD/DVD at speed 17.0 in real unknown mode for single session.
Last chance to quit, starting real write in 0 seconds. Operation starts.
Track 01: Total bytes read/written: 1310720/1310720 (640 sectors).
cr@cr-ub10:~$
cr@cr-ub10:~$
-----------------------------------------------------------------------------------

saikee 07-17-2010 07:30 AM

Can I summarize your current status as follow?

(1) Putting Grub2 into a USB stick still not working according to my suggested commands.

(2) You now managed to create a Grub2 bootable CD but its result has not been reported.


I have tested the commands myself and it seems if you format the USB stick to a Ext2/3 filing system everything will work out alright.

This could be a bug or error as Grub2 does not have a shell and relies exclusively on Linux for its installation by using a Bash terminal command "grub-install". In that the developers may not have expected the user to put Grub2 directly into a fat32 partition. I therefore got a complaint saying the filing system not recognised. If the partition you want Grub2 inside is a Ext2/3 type then everything will be perfect. I have successfully booted up my USB stick using exactly the following commands

(A) First I umount my USB stick by command
Code:

umount /dev/sdc1
I have arranged to test my USB stick in a PC with 2 existing disks so that my USB stick is sdc1 too.

(B) I use "cfdisk /dev/sdc" to alter the partition type to 83 for Linux, select "write" and "quit" cfdisk. Then I check the disk layout to make sure sdc1 has a partition type 83 by command
Code:

fdisk -l
(C) I format the sdc1 in Ext2 by command
Code:

mkfs.ext2 /dev/sdc1
(D) I then create a mounting point in /mnt, mount the sdc1 and check it is indeed empty but with "lost + found" inside by
Code:

mkdir /mnt/sdc1
mount /dev/sdc1 /mnt/sdc1
ls /mnt/sdc1

(E) I put Grub2 inside sdc1 (I was using Ubuntu 10.04 which has been shipped with Grub2) by
Code:

grub-install --root-directory=/mnt/sdc1 /dev/sdc
No error was reported. The USB stick can be booted if I specify it as the booting device. If I boot a Grub1 from existing hard disk I need to have it inserted so that the Bios can tell the boot loader in the MBR there is a 3rd disk (hd2). Then I can jump from Grub1 (off hd0) to Grub2 in (hd2) by Grub1 command
Code:

root (hd2)
chainloader +1

The above USB Grub2 installation only boot up to a Grub prompt. If I need a menu, which is /boot/grub/grub.cfg (and possibly /boot/grub/device.map too), I need to copy one from a Linux that uses Grub2, in my case Ubuntu 10.04, and put it in sdc1.

The above is the quick way to put Grub2 in a empty ext2 partition in a USB stick that will fire to a Grub2 prompt which can be used to boot up any "installed" operating system in a PC. Its use is identical to Grub1 except somecommands are slightly different.

cr4321 07-17-2010 11:08 AM

Ah, am I glad to see your post!!! (I will try out the USB trick a little later, and I am sure your suggesion could be the solution, since I have tried almost everything else - and somewhere along the way, I think I have made a mess of the MBR of (hd1) - and on booting, now it shows a "read error"!

First - yes, the CD is booting to grub prompt and I have all the grub commands available there.

Is there a way to restore the boot menu of hd1 from the CD?

Meanwhile, I will follow your instruction for the USB - using my live 10.04 Ubuntu cd.

I think I am really testing your patience, and I really appreciate your patience.

Warm regards.

saikee 07-17-2010 12:49 PM

In a normal application your PC only boot up the first hard disk and that should be your (hd0) or sda.

The MBR in the (hd1) is a spare. This is because the boot loader controlling the MBR should be able to boot every partition in every hard disk. The first partition of (hd1) is (hd1,1) in Grub2 term so (hd1) has no usable purpose at all.

Your sdb or (hd1) has Linux inside, right?

My guess is it is in sdb5 which if true can be checked by your newly made bootable CD by command
Code:

set root=(hd1,5)
ls /boot/grub

if it has the Grub2 files inside, like boot.img, core.img and grub.cfg you can fire it up immediately by command
Code:

configfile /boot/grub/grub.cfg
as you have already declare where is its root.

Once Linux in sdb5 has been booted you can choose it to be linked to the following possibilities

(1) Letting the boot up Linux to control the MBR (that is (hd0) or sda you issue this command in a root terminal
Code:

grub-install /dev/sda
(2) Put Grub2 in sda5
Code:

grub-install -force /dev/sdb5
This makes the Linux "chainloadable" in future by commands
Code:

set root=(hd1,5)
chainloader +1
boot

(3) Put Grub2 in (hd1)
Code:

grub-install /dev/sdb
This makes Linux sdb5 bootable if you chainload (hd1) by command
Code:

set root=(hd1)
chainloader +1
boot

Normally you only need Choice (1) but you can have all three if you want them. With a bootable Grub CD you should be able to kiss most of your booting problems good bye.

Don't worry about my patience. Booting is in fact very easy in Linux. You will eventually be able to put 1 and 1 together to get 2.

cr4321 07-17-2010 03:05 PM

Saikee,

Wow, done it! The USB is now booting to Grub - and I managed to chainload into (hd1) and lo I got the menu which I thought, I had washed away along with the MBR!!

So, now I have a USB and CD booting to Grub - A big thanks to you. Now please help me with this :


Quote:

The above USB Grub2 installation only boot up to a Grub prompt. If I need a menu, which is /boot/grub/grub.cfg (and possibly /boot/grub/device.map too), I need to copy one from a Linux that uses Grub2, in my case Ubuntu 10.04, and put it in sdc1.
Now, how do I get Ubuntu 10.04 into the sdc1, so that I can also have a menu option! I have the image file of Ubuntu 10.04. Kindly help me put that into "sdc1" and help create a menu in the USB!

I don't want to spoil your week-end, but doing this, I had a gr8 weekend!

Regards.

Thanks, you been wonderful, and I now have some idea about this .. This is some achievement..

cr4321 07-17-2010 03:12 PM

Please Note :

In the above, I forgot to tell you that my BIOS is not recognizing this USB as a USB. It has gone into the list of Hard Disks!

saikee 07-17-2010 05:18 PM

To copy a Grub2 menu into a USB flash drive sdc1

When you boot up a Linux its Grub2 menu is /boot/grub/grub.cfg. So if you want to copy it into device sdc1 you mount it first and use a file copying command to move it across.

However when a USB device is attached to a modern Linux it will get mounted automatically by the kernel. In your previous post the mounting position has been confirmed to be /media/usb0. Thereafter you can use a terminal to copy the file across like
Code:

sudo cp /boot/grub/grub.cfg /media/usb0/boot/grub/
The terminal method will always work.

This is no different to you open up one file manger (click "place" and "Home folder" and navigate to /boot/grub to drag grub.cfg to another file manager opened to the folder of /media/usb0/boot/grub. The GUI method sometimes refuses to work if you as a user does not own the files.

To put Ubuntu onto sdc1

This is a new request as your current thread relates to putting Grub2 as a stand alone system.

You do not need Ubuntu put inside sdc1 in order to use the Grub2 menu. The steps described above is all you need. Basically Grub2 when boot to a media like sdc1 will check if grub.cfg exists. It it exists it will execute it otherwise it defaults to a Grub prompt. Therefore having a grub.cfg is the same of having it from the hard disk.

When you put Ubuntu into a flash drive you actually install it and there are two methods.

Method 1 - Normal installation

The flash drive is just a hard disk in Linux so you can install Ubuntu just like you did in the hard disk except you now use sdc1 and not sdb5.

This type of installation is about 3 to 5 times larger than the CD image as many files are expanded and various settings are recorded. As a CD is 700Mb so an installed Ubuntu can be around 3.5Gb. This can take a very long time!!!!!!!!

Once installed your Ubuntu is specific to the PC it has been installed with.

Method 2 - Frugal install

In this method you effective just copy the contents of the Ubuntu CD into sdc1. UBuntu in a CD is shipped to boot from a CD and has the boot loader called ioslinux which boot a filing system created in according to ios9660 standard. Isolinux does not boot a hard disk so you need to change to a hard disk boot loader like Grub2. This part you have already done. Once you copy the contents of Ubuntu CD onto the sdc1 you still need to write instruction to boot Ubuntu. The easiest is to follow isolinux's configuration file and convert it to Grub2.

You can post the ioslinux.cfg here for advice.

If you have no CD drive but just an iso from ubuntu then you need to mount the iso file on a loop back device, kind of like a virtual CD, in order to read/write the contents inside an iso file. The mounting instruction is given in most reference on the mount command, man page of mount etc. I have written a thread showing how to combine several iso into a DVD and then on a flash drive. You can see the details of mounting instruction and conversion of ioslinux to Grub commands (mainly for Grub1).

In a Frugal install you use Ubuntu as a Live CD. The expansion of file takes place in the memory and as a rule settings are not saved but the flash drive can be used on any PC.

cr4321 07-18-2010 12:09 AM

Saikee,

Thanks a ton for all you have given. All I need for now is to get the menu into the USB. Once, I do that, (and I have been also reading your other posts) I get the confidence to boot my systems (from grub, or otherwise), and like earlier will not have to re-install everything once I mess up the menu! (It has happened many times in the past!)

Once I am a bit familiar with this, I will go further and experiment and understand things better!

So, for now I will just pause and get the grub config file into the usb following your instructions. I will come again to post the final observations. I feel mighty pleased with my efforts - though in your parlance, I may have not even scratched the surface! Of course, all credit to you - to teach a 60 year old the ABC's of grub!

With best regards. I will be seeking you out again, for sure!

cr4321 07-18-2010 08:56 AM

Saikee,

Used a brute force method to copy the grub.cfg file into the USB. (had to!) and finally have accomplished everything what I had set out to do! That's a great feeling. Thanks all the way to you.

(why had to!)

As I earlier mentioned, in the course of experimenting, I had overwritten/erased the boot menu/mbr of the the disk which had the XP+Linux OS's. (It was giving a read error). So, I did a "FIXMBR" and "FIXBOOT" with the XP recovery. This erased the Grub menu and it directly boots Windows. (In the normal course, I would be actually reinstalling all the OS's and the programs! Now with the additional knowledge, and after copying the grub.cfg file into USB, I am getting the menu alright and also booting into the system. I know I should be doing a "grub update" - but I don't want to risk a mess-up at this stage - so :

(I will be glad to learn the final tip. To safely reverse the boot menu back to the disk!!)

Warmest regards.

saikee 07-18-2010 12:00 PM

You can get back to where you were by

Boot up the Ubuntu and do a grub-install to the first boot disk sda.

In root terminal of booted up Ubuntu from sdb5 this command will link your Ubuntu to the MBR of sda
Code:

grub-install /dev/sda
As you are using Ubuntu so it knows where the root partition is. The destination /dev/sda means you want Grub to control the MBR. After this command on a reboot you should see Grub2 screen of the Ubuntu in sdb5. I assume it has the entry to boot your Windows. If it doesn't these entries in /boot/grub/grub.cfg will fire it up
Code:

menyentry 'Winodws in sda1 known to Grub2 as (hd0,1)' {
set root=(hd0,1)
chainloader +1

You can fire up your Windows manually in a Grub prompt with the above commands just by omitting the first "menuentry" statement and add a "boot" statement after "chainloader +1".

cr4321 07-18-2010 12:48 PM

Saikee,

Quote:

cr@cr-ub10:~$ sudo grub-install /dev/sda
Installation finished. No error reported.
Yes, done - and there is no error - so, this should be the happy ending, or a good begining!!

Thanks a lot, and be seeing you. Greatly appreciate your efforts. It was wonderful.

(A point of interest on the side. Since the USB is recognised as a "Drive" in my BIOS, I tried to install Ubuntu 10.04 into a USB after creating partitions. Surprisingly it works - albeit quite slow!)


All times are GMT -5. The time now is 03:28 AM.