grub change hd0 to hd1

Hello All,

I am trying to change my boot device from hd0 to hd1.

hd0(/dev/sda1) started failing so I moved my /root to hd1(dev/sdb1).

I added the new root to the menu.lst

###Don’t change this comment - YaST2 identifier: Original name: linux-2.6.25.20-0.1-Stefan2###
title Stefan2 – openSUSE 11.0 - 2.6.25.20-0.1
kernel (hd0,1)/boot/vmlinuz-2.6.25.20-0.1-Stefan2 root=/dev/sda2
initrd (hd0,1)/boot/initrd-2.6.25.20-0.1-Stefan2

I added

title Stefan3 – openSUSE 11.0 - 2.6.25.20-0.1
root (hd1,1)
kernel /boot/vmlinuz-2.6.25.20-0.1-Stefan2 root=/dev/disk/by-id/scsi-SATA_WDC_WD3200AAKS-_WD-WCAPZ1701835-part2
initrd /boot/initrd-2.6.25.20-0.1-Stefan2

device.map
(hd0) /dev/sda
(hd1) /dev/sdb

cat /etc/grub.conf
setup --stage2=/boot/grub/stage2 (hd0) (hd1,1)
setup --stage2=/boot/grub/stage2 (hd1) (hd1,1)

fdisk -l /dev/sda

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000be445

Device Boot Start End Blocks Id System
/dev/sda1 1 262 2104483+ 82 Linux swap / Solaris
/dev/sda2 * 263 2873 20972857+ 83 Linux
/dev/sda3 2874 121601 953682660 8e Linux LVM

fdisk -l /dev/sdb

Disk /dev/sdb: 320.0 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0003831a

Device Boot Start End Blocks Id System
/dev/sdb1 1 244 1959898+ 82 Linux swap / Solaris
/dev/sdb2 * 245 2677 19543072+ 83 Linux
/dev/sdb3 2678 38913 291065670 8e Linux LVM

grub-install

GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

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> setup --stage2=/boot/grub/stage2 (hd0) (hd1,1)
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 (hd0)”… 15 sectors are embedded.
succeeded
Running “install --stage2=/boot/grub/stage2 /boot/grub/stage1 d (hd0) (hd0)1+15 p (hd1,1)/boot/grub/stage2 /boot/grub/menu.lst”… succeeded
Done.
grub> setup --stage2=/boot/grub/stage2 (hd1) (hd1,1)
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)”… 15 sectors are embedded.
succeeded
Running “install --stage2=/boot/grub/stage2 /boot/grub/stage1 (hd1) (hd1)1+15 p (hd1,1)/boot/grub/stage2 /boot/grub/menu.lst”… succeeded
Done.
grub> quit

looks all good to me.

init 0

remove hd0

machine will not boot. it seem that the install on /dev/sdb has not compleated corectly or the device map is not right.

I do have 4 more hd so the MBR could have been installed on one of them, non of them has a boot flag set.

OK NEXT step.

I pluged in the replacement hd (no partitions brand new)

Now I get Grub and I can select the boot image BUT it says it can not find “root=/dev/disk/by-id/scsi SATA_WDC_WD3200AAKS-_WD-WCAPZ1701835-part2”
which is wiered because that HD is still in the system.

I select the other menue entry which pointing to root=/dev/sda2

So now the /dev/sdb2 can bee seen as /dev/sda2

What am I missing?

I want to be able to boot of /dev/sda2 and /dev/sdb2 independently.

The idear is that I boot from /dev/sdb2

mount /dev/sda2 as /root_back , run a nighly rsync across after shutting down a few deamons. So when I have a problem with /dev/sdb2 I just boot of the other hd with the last backup on it.

you help is apriciated.

Stefan

Did you change /etc/fstab ???

###Don’t change this comment - YaST2 identifier: Original name: linux-2.6.25.20-0.1-Stefan2###
title Stefan2 – openSUSE 11.0 - 2.6.25.20-0.1
kernel (hd0,1)/boot/vmlinuz-2.6.25.20-0.1-Stefan2 root=/dev/sda2
initrd (hd0,1)/boot/initrd-2.6.25.20-0.1-Stefan2

I updated

title Stefan3 – openSUSE 11.0 - 2.6.25.20-0.1
root (hd1,1)
kernel (hd1,1) /boot/vmlinuz-2.6.25.20-0.1-Stefan2 root=/dev/sdb2
initrd (hd1,1) /boot/initrd-2.6.25.20-0.1-Stefan2

now It start booting but then it fails with cannot mount /dev/sda2 would you like /dev/by-id/<removed HD>

where is that coming from?

I booted Stefan3 there is not mention od /dev/sda2

I am not sure if what you are trying to do will work.

Here is one for sure fact, your Boot Drive is Always HD0… This is true no matter the physical order of your drives. What ever drive I have picked to boot from in my BIOS, I make it HD0 in my device.map file. I then number the rest of the drives in the remaining physical order. The names HD0, HD1 and so forth are logical drive designations while the name sda, sdb, sdc are physical names based on the physical identification order your BIOS finds and assigns the drive(s) at boot time.

Grub has to be loaded on the boot drive (HD0), all of it. It can be in the MBR if you like. openSUSE can be on any other drive, which could be HD1 or what ever, but if your boot drive is failing, it may be time to reload openSUSE on the new drive.

Thank You,

I did some more reading

Stage1:
the MBR part
loads stage2

Stage2:
the actual boot loader

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

this looks at disk (hd1,1) /dev/sdb2 my /root

grub> setup (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)”… 15 sectors are embedded.
succeeded
Running “install /boot/grub/stage1 (hd1) (hd1)1+15 p (hd1,1)/boot/grub/stage2 /boot/grub/menu.lst”… succeeded
Done.

this installs /stage1 to (hd1) the MBR with the information where it finds stage2 and the medu.lst

that should work, I try it out as soon my kids stop using my mythtv box.

Stefan

So this installs stage1 to (hd1)

Sorry to say so, but this is not true. This is from my, booting and running server:


###Don't change this comment - YaST2 identifier: Original name: linux###
title openSUSE 11.2 - 2.6.31.12-0.2
    root (hd4,0)
    kernel /boot/vmlinuz-2.6.31.12-0.2-default root=/dev/disk/by-id/ata-OCZ_CORE_SSD_MK01090307F0C001C-part1 splash=silent quiet showopts vga=0x346
    initrd /boot/initrd-2.6.31.12-0.2-default

As you see, the SSD is the 5th disk, boots from 1st partition.

IMHO you should perform a nice clean install on the replacement disk. Takes about an hour, and it would make sure everything is in place and properly addressed.

I managed to boot of hd1 (MBR)
read the stage2 and menuefile from hd1 (I nenamed the files on hd0)

for some reason when I replace hd0 it will not work anymore.

I will rename all other boot related files (initrd and the kernel) from hd0 to figure out what is still refering to hd0.
at the time the information in menu.lst are read the stage1 is already loaded.

title Stefan3 - hd1 - openSUSE 11.0 - 2.6.25.20-0.1
root (hd1,1)
kernel /boot/vmlinuz-2.6.25.20-0.1-Stefan2 root=/dev/disk/by-id/scsi-SATA_WDC_WD3200AAKS-_WD-WCAPZ1701835-part2
#kernel (hd1,1)/boot/vmlinuz-2.6.25.20-0.1-Stefan2 root=/dev/sdb2
initrd (hd1,1)/boot/initrd-2.6.25.20-0.1-Stefan2

This is working when I have the old drive hd0 in, when I replace it withe the new one grub tells me that it can onot find /dev/disk/by-id/scsi-SATA_WDC_WD3200AAKS-_WD-WCAPZ1701835-part2 anymore.

That drives me nuts since this should not changed regardless of hd numbering.

In terms of reinstall:

It is ok for a stock system, but I compiled a custom kernel , compiled one wire drivers, confiured cacti, muthtv, drivers for my usb tv card, configuration for my remote, vmware, samba, custom inity scripts etc… it would be a pain to reconfigure all that and certainly take to long for my likeing.

Stefan

one think what I did notice is that

gfxmenu (hd1,1)/boot/message

only works with the old hd0 in place which is wired because you would think that if it was reading it frm hd0

it would need to look like

gfxmenu (hd0,1)/boot/message for it to fail when the old drive hd0 is missing.

??

Knurpht, your entry below just shows you are loading openSUSE from HD4, which is no problem.

###Don’t change this comment - YaST2 identifier: Original name: linux###
title openSUSE 11.2 - 2.6.31.12-0.2
root (hd4,0)
kernel /boot/vmlinuz-2.6.31.12-0.2-default root=/dev/disk/by-id/ata-OCZ_CORE_SSD_MK01090307F0C001C-part1 splash=silent quiet showopts vga=0x346
initrd /boot/initrd-2.6.31.12-0.2-default

This entry does not show the boot drive or Grubs location. I am saying that what ever boot drive you select in your computer BIOS, it will be HD0. For Grub to be able to load SUSE from another drive, it needs to have been loaded from the boot drive. Once Grub is up and running, you can load openSUSE from any other drive in your system. We are talking only about the booting process, not where you load openSUSE from.

Thank You,

ok i figured it out

The MBR is only loaded from the first hd, and by first hd I mean the boot order in the Bios not the order on the controller.

The boot order can be changed in the Bios so the first drive to bot becomes (hd0) in grubs view. The drive you like to bot from needs an MBR with stage1 installed.

The grub stage1 which is installed into the MBR is only there to load stage2. Stage1 reads the stage2 file raw (it does not know any file systems)

Once state2 is loaded, stage2 looks at the file system and reads menu.lst, messages files and presents you with the menu.

From here you can boot a kernel on any hd. so you can have 4 hd with for different installation of linux.

In my case.

hd0 /dev/sda (boken hd) with stage1 in MBR
hd1 /dev/sdb (hd with linux /root)
hd2 and so on.

device.map
(hd0) /dev/sda
(hd1) /dev/sdb

I change hd0 with a new one
hd0 /dev/sda (new hd) with NO stage1 in MBR
hd1 /dev/sdb (hd with linux /root)
hd2 and so on.

system will not boot because the bios tries to read from hd0 (the new /dev/sda with no valid MBR)

So I changed the boot order in the bios. so /dev/sdb becomes (hd0) and /dev/sda becomes (hd1)

This means the MBR will be read from the 2nd hd. For grub this will change the order of the HD’s.

I needed to change the device.map and the menu.lst to reflect this
device.map
(hd0) /dev/sdb
(hd1) /dev/sda

this works.

The confusing bit was that the device ordering /dev/sda /dev/sdb does not change when you change the boot order. on the order during boot will change.

/dev/sda, /dev/sdb describes the hd ordering on the controller
(hd0), (hd1) describes the boot order of the hd as specified in the Bios.

Stefan

Great! I’ll bookmark this, it will be helpful in the future.

Thank you snantz :slight_smile:

Happy to hear you got it figured out and made it work snantz. Thanks for your detail listing on the issue and how you got it to work.

Thank You,

Stefan - excellent work. Excellent communication.

I’m pretty sure this BIOS feature is not available in all m-boards. Or not in older ones. Whichever drive was set to “master” was the 1st, or boot, drive. This could be set via the connector position, or the hdd jumpers.