help-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Legacy Grub restore with fresh MBR boot sector


From: Winston Smith
Subject: Legacy Grub restore with fresh MBR boot sector
Date: Sun, 25 Mar 2018 01:49:47 +0000

Hi all,

I'm trying to restore a Legacy Grub (version 0.97) on an MBR drive.

The drive has four partitions, sdb2 with /, sdb1 with /boot, sdb3 with a swap 
FS, and sdb4 with /home. Its partition table type is MBR, all partitions are 
primary, and sda1 is has the boot flag set:


# fdisk -l /dev/sdb
Disk /dev/sdb: 223.6 GiB, 240057409536 bytes, 468862128 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6829bb3a

Device     Boot    Start       End   Sectors   Size Id Type
/dev/sdb1  *        2048    526335    524288   256M 83 Linux
/dev/sdb2         526336  42469375  41943040    20G 83 Linux
/dev/sdb3       42469376  46663679   4194304     2G 82 Linux swap / Solaris
/dev/sdb4       46663680 468862094 422198415 201.3G 83 Linux


For reasons unknown to mankind, the drive had a GPT before, I changed it to MBR 
with gdisk, because Legacy Grub cannot boot from GPT partitions unless there is 
a BIOS boot partition (which it never had).

Hexdumping the first 2047 sectors, I find that sector 1 contains a vanilla Grub 
0.94 MBR (which I copied from another MBR drive):

# head -c 512 /dev/sdb > /tmp/x
# file /tmp/x 
/tmp/x: DOS/MBR boot sector; GRand Unified Bootloader, stage1 version 0x3, boot 
drive 0x80, 1st sector stage2 0xdb0658, GRUB version 0.94

Because the stage 2 sector pointer is definitely wrong, and all sectors from 2 
through 2047 are zeroed out (no stage 1.5), I tried the following:

- mounted sdb2 as /mnt/t, sdb1 as /mnt/t/boot
- re-bound /{dev,proc,sys} as /mnt/t/{dev,proc,sys}
- chroot /mnt/t (to make sure I use Grub from sdb, not sda)
- grub-install /dev/sdb

which yielded (expectedly):

/dev/sdb does not have any corresponding BIOS drive

since it's sitting in a USB dock for now. I got around this with grub-install 
--recheck /dev/sdb, which updated /boot/grub/device.map, all 
/boot/grub/*stage1_5 files, as well as /boot/grub/stage{1,2}. However, when I 
tried to boot from it, it doesn't boot. All I get is a blank screen with cursor 
in top left corner.

So I used the grub shell directly:

# grub
>root (hd1,0)
>setup (hd1)

which printed some information, but no error. But it still doesn't boot, 
there's still a blank screen with a cursor after POST.

My questions:

1. The above grub commands seemed to have no impact at all in the first sectors 
of the drive. All sectors 2 through 2047 are zeroed out even after the grub 
commands above. Where should Legacy Grub's stage 1.5 be, assuming I want to use 
stage 1.5 because Grub stage 2 sits on a ext3 FS?
2. What is /grub/stage1 on sdb1? It differs from the actual MBR on the drive in 
so far as that it let its stage 2 pointer point to 0x01 0x00 0x00 0x00. The 
actual MBR on disk points to some location from the old drive, see above. I 
would have expected that the sequence of commands about would update that 
pointer to point to an existing stage 1.5 (or stage 2?), or put stage 1.5 in 
sector 2, and update the pointer to 0x01 0x00 0x00 0x00?
3. All put together: How can I get Legacy Grub to either put stage 1.5 to disk, 
and update the stage 2 pointer in stage 1 to point to it, or update the state 2 
pointer in stage 1 directly to point at the existing /grub/stage2?
4. Could I just edit the stage 2 pointer manually in the MBR to achieve 3.)? 
But would that work, given stage 2 lives on a file system? Or could I manually 
dd a stage 1.5 file to sector 2 and following sectors, and update the pointers 
manually?


Thanks a lot for your help!

Regards,
Winston



reply via email to

[Prev in Thread] Current Thread [Next in Thread]