How do I install grub on another disk?

Hi,

I did this about a month ago, and it worked. But I didn’t write a note of
it, and now I’m unable to replicate.

I have an ext4 formatted usb stick with systemrescuecd, per their
instructions
here.

The instructions to install grub are missing. There is a link for further
info that is dead. I did manage to do it a month ago, but now I can’t. Go
figure.

What would be the procedure to install grub to an external disk mounted in
/media/something?

With “grub-install.unsupported” it complains that there is no matching
device, referring to the device.map - but which one, the host machine’s or
the destination disk, that also has a device map?

with grub, then setup it complains that the device is not found. I can only
use (hd0,0) (tab), but then refuses

…]

Tried again, got it!

grub [enter]

setup --stage2=/media/something/boot/grub/stage2 (hd0,0) (hd0,0)

the error was perhaps that media was not mounted. Obvious. Now. :-}

Now I have to test it.

…]

No, I did something wrong, doesn’t boot. I tell the laptop to boot from the
stick, and jumps to the HD grub menu instead.

Last time I did this from the laptop… No, on the laptop the same command
fails with “Error 17: Cannot mount selected partition”.

So I’m doing it wrong.

How should I do it?


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

Did you write the mbr to your usb device (after changing the menu.lst and device.map files to look at it)?
(I did all using the Yast Boot Loader)

On my laptop, to avoid booting the internal HDD, F12 has to be pressed and usb device selected.

The following was the setup for an HDD in a usb external enclosure. Any help?

/boot/grub/device.map
=====================

(hd0)    /dev/disk/by-id/ata-WDC_WD5000AAKS-00A7B2_WD-WCASY5960444


/etc/grub.conf
==============

setup --stage2=/boot/grub/stage2 --force-lba (hd0,1) (hd0,1)
quit


/boot/grub/menu.1st
===================

# Modified by YaST2. Last modification on Tue Aug 31 08:41:15 CEST 2010
# THIS FILE WILL BE PARTIALLY OVERWRITTEN by perl-Bootloader
# Configure custom boot parameters for updated kernels in /etc/sysconfig/bootloader

default 0
timeout 2
##YaST - generic_mbr
gfxmenu (hd0,1)/boot/message
##YaST - activate

###Don't change this comment - YaST2 identifier: Original name: linux###
title Desktop -- openSUSE 11.3 - 2.6.34-12
    root (hd0,1)
    kernel /boot/vmlinuz-2.6.34-12-desktop root=/dev/disk/by-id/ata-WDC_WD5000AAKS-00A7B2_WD-WCASY5960444-part2 resume=/dev/disk/by-id/ata-WDC_WD5000AAKS-00A7B2_WD-WCASY5960444-part1 splash=silent quiet showopts nomodeset vga=0x346
    initrd /boot/initrd-2.6.34-12-desktop

###Don't change this comment - YaST2 identifier: Original name: failsafe###
title Failsafe -- openSUSE 11.3 - 2.6.34-12
    root (hd0,1)
    kernel /boot/vmlinuz-2.6.34-12-desktop root=/dev/disk/by-id/ata-WDC_WD5000AAKS-00A7B2_WD-WCASY5960444-part2 showopts apm=off noresume edd=off powersaved=off nohz=off highres=off processor.max_cstate=1 x11failsafe vga=791 nomodeset
    initrd /boot/initrd-2.6.34-12-desktop

On 2012-03-29 08:06, keellambert wrote:
>
> Did you write the mbr to your usb device (after changing the menu.lst
> and device.map files to look at it)?
> (I did all using the Yast Boot Loader)

It must be done from the CLI, not yast. Yast would setup my main boot, not
the alternate boot.

What exact CLI do I use? That’s the question.

> On my laptop, to avoid booting the internal HDD, F12 has to be pressed
> and usb device selected.

Done, and boots the HD. USB ignored.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

With no experience, this is how it worked for me,

  1. the files /boot/grub/device.map, /etc/grub.conf and /boot/grub/menu.1st
    were changed on the target (usb drive) system as shown above

  2. yast boot loader was opened and the entries changed in it to reflect the
    above

  3. the mbr was then written to the ‘/’ directory

yast took the information from the above and wrote the correct information into
the correct drive (my assumption: the required info was taken from the
device.map entry)

I must admit, I made backup files of the mbr and the above files from my main
drive before starting this operation but found they were not required as they
were left untouched

Note: openSUSE 11.3 - 2.6.34-12 used was, so no guarantee this method still
works

my usb drive boots ok on other PCs but the bios has to be changed for the boot
order

On 2012-03-29 16:46, keellambert wrote:

> yast took the information from the above and wrote the correct
> information into
> the correct drive (my assumption: the required info was taken from the
> device.map entry)

If you do it with yast you risk that next time yast will try to do the same
on grub updates, so you have to leave yast in the state it was before.

It has to be done without yast.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

yast did ask me before the mrb write, “was I sure I wanted to create another system disk”

I’m doing something similar whenever I install a fresh openSUSE on a new PC: I boot from a Live CD, create the new /boot partition on the target HD and then use the grub binaries to install grub in this partition and in the mbr of the target HD. This is how I do it:

  • Use “grub --batch --device-map=/mnt/new_root/boot/grub/device.map <<< quit” to write a device.map
  • Write /mnt/new_root/etc/grub.conf:

root (hd0,0)
setup --stage2=/boot/grub/stage2 --force-lba (hd0,0)
setup --stage2=/boot/grub/stage2 --force-lba (hd0)
quit

  • grub-install is implicitely called, probably when kernel-default gets installed. It will run grub.conf

When you run the grub binary from an existing system, I think it needs the device.map file to translate your (hd0,0) to /dev/sdxxx paths. You can probably use --device-map=/media/something/boot/grub/device.map to write and use a device.map separate from your system’s one. On the grub command prompt, you set your working root with “root (hdx,y)” (look up the x,y pair which corresponds to your usb stick in the new device.map file), then you call “setup --stage2=$PATH” from the grub command prompt, where the PATH must be relative to the “root (hdx,y)” which you set before, so it’s likely “/boot/grub/stage2” and not “/media/something/boot/grub/stage2”.
Caution: I assumed your usbstick has partitions, otherwise (hdx,y) doesn’t make sense, and you can only do (hdx). Also the mapping of (hdx,y)<–>/dev/sdxy as given in device.map might change when you unplug and re-plug the usb stick. If one forgets this in an unfortunate moment, one might end up writing grub data onto the wrong device.

I’m not sure about most of what I’ve written here. The wisdom above was taught to me right now by my own install script which is some years old.
– Yarny

On 2012-03-29 23:16, keellambert wrote:
>
> yast did ask me before the mrb write, “was I sure I wanted to create
> another system disk”

I do not get that prompt. I tried, it wrote something somewhere, but the
usb stick still doesn’t boot.

At least the openSUSE in the laptop boots normally, there was no damage
with the testing.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

On 2012-03-30 12:16, Yarny wrote:
>
> I’m doing something similar whenever I install a fresh openSUSE on a new
> PC: I boot from a Live CD, create the new /boot partition on the target
> HD and then use the grub binaries to install grub in this partition and
> in the mbr of the target HD. This is how I do it:
>
> - Use “grub --batch --device-map=/mnt/new_root/boot/grub/device.map
> <<< quit” to write a device.map
> - Write /mnt/new_root/etc/grub.conf:

This is already done, because I copied the entire /boot from the working stick.

> Code:
> --------------------
>
> root (hd0,0)
> setup --stage2=/boot/grub/stage2 --force-lba (hd0,0)
> setup --stage2=/boot/grub/stage2 --force-lba (hd0)
> quit
>
> --------------------
>
> - grub-install is implicitely called, probably when kernel-default
> gets installed. It will run grub.conf

This I have doubts. The root command will set the root to the root of the
desktop, not of the stick. I tried:


grub> root (hd1,0)

Error 21: Selected disk does not exist

grub>

and



grub> cat (hd0,
Possible partitions are:
Partition num: 0,  Filesystem type unknown, partition type 0x7
Partition num: 1,  Filesystem type unknown, partition type 0x7
Partition num: 2,  Filesystem type unknown, partition type 0x7
Partition num: 4,  Filesystem type unknown, partition type 0x82
Partition num: 5,  Filesystem type is ext2fs, partition type 0x83
Partition num: 6,  Filesystem type is reiserfs, partition type 0x83
Partition num: 7,  Filesystem type is reiserfs, partition type 0x83
Partition num: 8,  Filesystem type is ext2fs, partition type 0x83

which refer to the partitions on the hard disk, not on the stick. I need to
install grub on the stick.

Probably I have to modify the devicemap of the laptop. But I do that:


(hd1)   /dev/disk/by-id/usb-General_USB_Flash_Disk_0000000000001B69-0
(hd0)   /dev/disk/by-id/ata-ST9500325AS_5VE68QJX

and still says that hd1 does not exist.

Or is it that I have to create a temporary devicemap where hd0 is the stick?


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

try at grub prompt:
grub > root (hd {tab}

does it list more then (hd0) ? if not check the BIOS setting for ???.

I did this about a month ago, and it worked. But I didn’t write a note of
it, and now I’m unable to replicate.
On the same comp ? did you make any other changes in the BIOS setup ?

Yes, that’s because I just copied my own code without adapting it to your situation. In my case, I have to use (hd0,0) because my device.map points this to the device which I acutally want to modify.

I just tried that and it works nice. I used an empty internal disk instead of an usb stick, but it shouldn’t make a difference.
I guess your usb stick is /dev/sdb and the /boot partition on it is /dev/sdb1, and is mounted in /media/something.


# Remove old device.map
$ rm /media/something/boot/grub/device.map
# Write new device.map
$ grub --device-map=/media/something/boot/grub/device.map <<< quit

Look into /media/something/boot/grub/device.map. It should point (hd1) to your usb-stick /dev/sdb. Put some test file on your usb-stick’s /boot, like “touch /media/something/boot/my_mark_file”. Call grub again, with “grub --device-map=/media/something/boot/grub/device.map”, try again “root (hd1,0)” and verify that you’re on the correct partition with “find /boot/my_mark_file”. It should respond “(hd1,0)”. If it doesn’t, you somehow ended up on a wrong device, maybe your machine’s /boot. If it does, you’re on your way.


setup --stage2=/boot/grub/stage2 --force-lba (hd1,0)
setup --stage2=/boot/grub/stage2 --force-lba (hd1)

From here on, I didn’t test any further.

I don’t think this is a BIOS thing at all. I think BIOS is only relevant at the boot-up’s grub prompt (when the actual bootloader is running). When you run grub from within a running system, it always uses device.map (and it never does while booting).
–Yarny

On 2012-04-01 02:06, LostFarmer wrote:
>
> try at grub prompt:
> grub > root (hd {tab}
>
> does it list more then (hd0) ? if not check the BIOS setting for ???.

Only hd0 is shown. I had tried that already.

The problem is that while it boots, the stick is indeed hd0, because the
bios changes the boot order. But when I write the stick, hd0 is the hard
disk - so what command do I use to write grub on the stick?

>> I did this about a month ago, and it worked. But I didn’t write a note
>> of it, and now I’m unable to replicate.

> On the same comp ? did you make any other changes in the BIOS setup ?

On the same machine, yes… No changes, it is a laptop. On laptops there is
nothing to be changed, the bios setup is really minimal.

Same machine, but different stick. The other stick works.

I know that some sticks simply can not boot at all, this might be one of
those. I might write to this one a copy of a boot CD and see if it boots or
not.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

Carlos, you can use Yast, after a chroot to the installed system on the USB device. Steps described here in dutch, but the commands are valid : http://forums.opensuse.org/nederlands-dutch/community/nl-how-tos/453092-systeem-overnemen-met-een-livecd.html . Your point about the update issue with Yast thus will not occur, since it’s the Yast on the stick and it needs this GRUB config, isn’t it?

I know that some sticks simply can not boot at all, this might be one of
those.
Could be 2 or more problems.

  1. I do not understand but have read that some of the MF software on the stick interferes with booting and a simple format does not remove the software.
  2. with my comp if the usb stick is small (i think less then 800M) , the stick is seen as a floppy, not as a hdd. (my stick is 500m)
    My comp does have BIOS setting I can change how it is seen but if I have it in AUTO it is a floppy. grub> root (fd tab lists fd0 and fd1- fd1 is the stick)
    If I change BIOS setting for stick as a hdd then grub> root (hd tab list is as a hd.

If your stick is small bet problem 2 is the one.

I am trying to get my stick to boot with XP’x recovery console but having no luck yet.

On 2012-04-01 22:36, Knurpht wrote:
>
> Carlos, you can use Yast, after a chroot to the installed system on the
> USB device. Steps described here in dutch, but the commands are valid :
> http://tinyurl.com/73kwj9m . Your point about the update issue with Yast
> thus will not occur, since it’s the Yast on the stick and it needs this
> GRUB config, isn’t it?

Not possible… there is no yast on the stick, it is a rescuecd distro. For
a chroot to work you need the binaries of whatever you need in the chrooted
environment.

Let me see if I can try Yarny’s advice


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

On 2012-04-01 10:46, Yarny wrote:

> I just tried that and it works nice. I used an empty internal disk
> instead of an usb stick, but it shouldn’t make a difference.
> I guess your usb stick is /dev/sdb and the /boot partition on it is
> /dev/sdb1, and is mounted in /media/something.
>
> Code:
> --------------------
>
> # Remove old device.map
> $ rm /media/something/boot/grub/device.map
> # Write new device.map
> $ grub --device-map=/media/something/boot/grub/device.map <<< quit
>
> --------------------
>
> Look into /media/something/boot/grub/device.map. It should point (hd1)
> to your usb-stick /dev/sdb.

Done.
That’s the starting trick, the device map.

> Put some test file on your usb-stick’s
> /boot, like “touch /media/something/boot/my_mark_file”.

Ah, good trick! Let me see…

> Call grub
> again, with “grub --device-map=/media/something/boot/grub/device.map”,
> try again “root (hd1,0)” and verify that you’re on the correct partition
> with “find /boot/my_mark_file”. It should respond “(hd1,0)”.

Right, it does work:


grub> root (hd1,0)
Filesystem type is ext2fs, partition type 0x83

grub> find /boot/mark

Error 15: File not found

grub> find /boot/grub/mark
(hd1,0)

grub>

Good.

If it
doesn’t, you somehow ended up on a wrong device, maybe your machine’s
/boot. If it does, you’re on your way.

Code:

setup --stage2=/boot/grub/stage2 --force-lba (hd1,0)
setup --stage2=/boot/grub/stage2 --force-lba (hd1)



grub> setup --stage2=/boot/grub/stage2 --force-lba (hd1,0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd1,0)"... failed (this is not fatal)
Running "embed /boot/grub/e2fs_stage1_5 (hd1,0)"... failed (this is not fatal)
Running "install --force-lba --stage2=/boot/grub/stage2 /boot/grub/stage1
(hd1,0) /boot/grub/stage2 p /boot/
grub/menu.lst "... succeeded
Done.

grub> setup --stage2=/boot/grub/stage2 --force-lba (hd1)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd1)"...  17 sectors are embedded.
succeeded
Running "install --force-lba --stage2=/boot/grub/stage2 /boot/grub/stage1
(hd1) (hd1)1+17 p (hd1,0)/boot/gru
b/stage2 /boot/grub/menu.lst"... succeeded
Done.

grub>

Looks good.

>
> From here on, I didn’t test any further.

Lets see if it boots.

…]

No… I press F9 to change the boot order, I choose the USB stick, the
screen blanks for a moment, and then I get the bios boot screen again. If I
try a second time, I get a grub crash, dunno if from the stick or the HD.

In fact, I powered off, booted and failed, the HD boot is broken now :frowning:

…]

Booting from a rescue CD I see that /etc/grub.conf was modified, probably
by yast on a previous attempt.

Mmm… I used the same procedure as above to rebuild the laptop device.map,
and hd0 is fd0, which does not exist! It doesn’t see sda! :frowning:

Broken grub :frowning:

Well, I have a full backup of the /boot partition. I’ll make a backup of
the current files, dd the image backup, and then replace the files. Should
be enough.

…]

Failed! I don’t understand… Maybe mc doesn’t work right in a chroot. Copy
failed?

Ok, backup image restored. Now grub stops at a different point. I only see
“GRUB” on the top left.

Trying to restore files… No good.

Trying again. Perhaps the MBR was also modified - no.

It appears my grub is totally destroyed :frowning:

…]

Ah!

I know why I can’t restore from backup. I’m restoring the boot partition,
sda6, but I also need to restore sda4, the extended partition, which is
where grub resides - and I don’t have a backup of this one. Oh, yes, I do!
But it might not work, it is only 512 bytes… will it have stage 1.5?

Bingo! It boots! Pffff!

Reinstalling grub properly… {setup --stage2=/boot/grub/stage2 --force-lba
(hd0,3) (hd0,5)}

booting… no, it crashes loading stage2. I wonder why… restoring grub as
previously, from rescue system. sda4… not enough, it stops at loading
stage2. I have to restore sda6 from image backup.

Fails again… WHY!!! It worked before!

Reinstalling for the Nth time from backup, rebooting… now I get the boot
prompt, no menu!

Doing it again, same error! :-/

Typing the entries manually… booting!

I HATE GRUB!

I’ll have to tell Yast to reinstall grub. I hope it will do it right…

No… it did not. I’m back to the"GRUB loading stage 2" prompt and nothing
more.

WHYY!


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

On 2012-04-03 03:43, Carlos E. R. wrote:
> No… it did not. I’m back to the"GRUB loading stage 2" prompt and nothing
> more.
>
> WHYY!

I had to reinstall. Actually, I booted the DVD and choose “upgrade”. Now i
have to restore things.

I will not play with GRUB again. I destroyed the USB stick, I will use CDs
instead. GRUB is too unreliable. :-/


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

OK, I now feel somehow guilty since I seduced you into trying this. Yet I don’t really see what destroyed your working machine’s boot mechanism.

For the record, and for those who might find this in the future:

I claimed that the “/boot/grub/stage2” is relative to the root set before, but I’m not so sure about this anymore. “info grub” says

Caution3: You must specify the option `–stage2’ in the grub shell, if you cannot unmount the filesystem where your stage2 file resides. The argument should be the file name in your operating system.

Why would they say “if you cannot unmount”? Maybe it’s an absolute path in the current running system here?

If device.map isn’t build correctly, this isn’t fatal. You can build it by hand. It is not relevant during boot, it’s only needed when you maintain a grub-installation from within a running system (this can also happen automatically, e.g. when grub gets updated by zypper). I also sometimes find (fd0) in my device.map and I don’t know why it is there. I ignore it.

Your harddisk’s setup is quite complicated. Grub is installed in the mbr of an extended partition? Hmm, OK. But shouldn’t there be some boot loader in the mbr of the disk (the very first sector) which then chains the mbr of sda4? Maybe this one got somehow destroyed.

Sorry, I hope your system is alright now.
–Yarny

On 2012-04-03 11:26, Yarny wrote:
>
> OK, I now feel somehow guilty since I seduced you into trying this.

No, don’t be. I was interested in trying.

> Yet
> I don’t really see what destroyed your working machine’s boot
> mechanism.

Me neither… I do not know if it was this test, or an earlier test with
yast, or the combination of both. But I didd boot earlier, I think.

And I’m going to remake my image backup. One problem was that it was not
current enough.

> For the record, and for those who might find this in the future:
>
> robin_listas;2453251 Wrote:
>> On 2012-04-01 10:46, Yarny wrote:
>>
>>> Code:
>>> --------------------
>>>
>>> setup --stage2=/boot/grub/stage2 --force-lba (hd1,0)
>>> setup --stage2=/boot/grub/stage2 --force-lba (hd1)
>>
> I claimed that the “/boot/grub/stage2” is relative to the root set
> before, but I’m not so sure about this anymore.

Yes, I wondered about that.

> “info grub” says
>>
>> Caution3: You must specify the option `–stage2’ in the grub shell,

if you cannot unmount the filesystem where your stage2 file resides. The
argument should be the file name in your operating system.

Why would they say “if you cannot unmount”? Maybe it’s an absolute
path in the current running system here?

It could be… I thought that the previous root command affected, but maybe
not.

robin_listas;2453251 Wrote:

Mmm… I used the same procedure as above to rebuild the laptop
device.map,
and hd0 is fd0, which does not exist! It doesn’t see sda! :frowning:

If device.map isn’t build correctly, this isn’t fatal. You can build
it by hand. It is not relevant during boot, it’s only needed when you
maintain a grub-installation from within a running system (this can also
happen automatically, e.g. when grub gets updated by zypper). I also
sometimes find (fd0) in my device.map and I don’t know why it is there.
I ignore it.

The real problem is that when I was trying to type the grub command the
completion like root (hd[tab] did not complete, hd0 was nowhere to be seen.
I rebuilt the map to see what it was seeing, and only fdo was listed - and
the laptop doesn’t have a floppy.

Your harddisk’s setup is quite complicated. Grub is installed in the
mbr of an extended partition? Hmm, OK. But shouldn’t there be some
boot loader in the mbr of the disk (the very first sector) which then
chains the mbr of sda4? Maybe this one got somehow destroyed.

It has a generic MBR, so that I can fool Windows to think it is “pristine”.
The bootable mark is on sda4, which is the extended partition, and holds
part of the grub code. The rest is in sda6, the boot partition (root is
sda7). I have a separate boot because being reiserfs I needed it for
hibernation - a bug that has now been corrected but was active when I
partitioned. However, this allows me to image the boot fast.

See:


minas-tirith:~ # cat /etc/grub.conf
setup --stage2=/boot/grub/stage2 --force-lba (hd0,3) (hd0,5)
quit

> Sorry, I hope your system is alright now.

Yes, it is :slight_smile:

The DVD upgrade solved it all. After that, I only had to replace my repos
again (copy the files in /etc/zypp/repos.d/ from the backup), and update
everything. I keep a local copy of everything I install, I don’t have to
download it all again.

Before that I also tried supergrub, from http://www.supergrubdisk.org/. But
this people played a stupid April fools joke and substituted their iso with
one that says it is deleting all your system and, and even though it
doesn’t, is totally useless.

Stupids! How do they dare to play this way with people that are on nerves
edge to restore a broken installation!? :-((

I then tried an older copy of the ISO, “super_grub_disk_0.9766.iso”, but
this one was not bootable, I got the same prompt on the laptop as with the
broken grub in the HD.

I saw other images, but they appeared to be for grub2.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)