I need to recover generic MBR code, instead of grub code

Hi,

I have a laptop that double boots windows 7 / openSUSE 13.1. I’m on the
Windows side this instant. I have a problem with some Windows updates,
and I suspect the issue is that the boot partition is not marked
bootable and/or grub is on mbr.

Now, I do not know how grub is there, because it was originally
installed on sda4, the extended partition. Somehow, someday, it went
also to the mbr.

So, using yast boot module, I told it to boot from extended instead of
mbr, and also selected to write boot code. I was looking for the entry
“write generic code to the MBR”, but could not find it.

Then I intentionally marked as bootable sda1 (windows boot) instead of
sda4 (sorry, I’m on windows now, can’t paste a proper partition table
here). This change should have disabled Grub, and Windows should boot
instantly. But no, I still get Grub.

I MUST remove GRUB from the MBR, ie, restore a generic MBR.

So I tried from Windows. I should use “Bootrec.exe /FixMbr”, but the
tool is nowhere to be found in the hard disk. Microsoft help
(https://support.microsoft.com/en-us/kb/927392/es-es) says I have to run
it from the recovery disk.

Of course, I did create a recovery disk years ago, but I don’t know
where it is. So ok, I thought, I will create a new one.

Not possible! The daft thing says wrong parameter, error “0x80070057”. I
tried a CD and a DVD, no go.

Of course, I also searched for this error
(https://support.microsoft.com/en-us/kb/982736/es). The page proposes
two methods, none works. I can not create the recovery disk.

(I’ll try searching for it again, somewhere in this house)

So, questions:

Can I tell YaST somewhere to restore a generic MBR code somehow?

Another way to do it in Windows?


Carlos E. R.
(W7 at Minas-Morgul)

If you open YaST>Boot Loader, there is an option to Write Generic Boot Code to MBR

There should be an option in Yast bootloader. I can’t check right now, because I’m on a UEFI system, and that option doesn’t show for UEFI installs.

As an alternative, you can find the generic boot code at:

/usr/share/syslinux/mbr.bin

I’m pretty sure that “syslinux” was installed by default for 13.1, so it should be there.

The file should be 440 bytes long. So just copying to “/dev/sda”, or use “dd” should work.

Note that this isn’t the Windows provided boot code, but I doubt that Windows is that fussy. If you want a 440 byte file with Windows boot code, send me a PM with information on how to get it to you.

Yes, some Windows updates check the booting. And those go astray if the active flag is not set for the Windows partition. So your diagnosis is probably correct.

On 26/05/2015 23:26, john hudson wrote:
>
> If you open YaST>Boot Loader, there is an option to Write Generic Boot
> Code to MBR

Are you sure?
I have seen it other times, but this time I could not find it. I’ll have
another look when I exit Windows.


Carlos E. R.
(W7 at Minas-Morgul)

On 2015-05-26 23:37, Carlos E. R. wrote:
> On 26/05/2015 23:26, john hudson wrote:
>>
>> If you open YaST>Boot Loader, there is an option to Write Generic Boot
>> Code to MBR
>
> Are you sure?
> I have seen it other times, but this time I could not find it. I’ll have
> another look when I exit Windows.

I don’t see it, and the system is not UEFI.
Ah, found it! It is not on the “Other” button, but on “boot loader options”.

But I’m unsure it worked…


minas-tirith:~ # file -s /dev/sda
/dev/sda: DOS/MBR boot sector; GRand Unified Bootloader, stage1 version 0x3, LBA flag 0x1, stage2 address 0x2000, stage2 segment 0x200, GRUB version 0.97
minas-tirith:~ #

I’ll try rebooting.


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

On 2015-05-26 23:46, nrickert wrote:
>
> robin_listas;2712199 Wrote:

> There should be an option in Yast bootloader.

Yes, I found it, but it is not where I was looking.
I’ll reboot in an instant to find out if it worked. I’ll say in a minute.

> As an alternative, you can find the generic boot code at:
>
> Code:
> --------------------
> /usr/share/syslinux/mbr.bin
> --------------------

Yes, it is there. I’ll try the dd way if the previous attempt doesn’t work.

> The file should be 440 bytes long. So just copying to “/dev/sda”, or
> use “dd” should work.

If it has to be copied at the start, not at the end… I don’t remember.

> Note that this isn’t the Windows provided boot code, but I doubt that
> Windows is that fussy. If you want a 440 byte file with Windows boot
> code, send me a PM with information on how to get it to you.

No need, thanks, I can get it from a test install I did on a spare disk.
It is a non-updated W7 system, so I can get it from there.

I only have to locate that HD in the cardboxes O:-)

Or… I did an image backup of this laptop, but I don’t know if the
damage (to the MBR) was already done or not. Otherwise… the original
hard disk of this laptop broke down, it must be somewhere still (the
damage was on a partition only). So I could retrieve the original, I
think. Maybe.

Several ways :slight_smile:

> Yes, some Windows updates check the booting. And those go astray if the
> active flag is not set for the Windows partition. So your diagnosis is
> probably correct.

It happened to me on the first service pack.


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

It’s at the start. After that is 6 bytes of some windows disk ID, 64 bytes of partition table and 2 bytes of bootable-flag. So the first 440 bytes is what you need to replace.

On 2015-05-27 00:20, Carlos E. R. wrote:
> On 2015-05-26 23:46, nrickert wrote:
>>
>> robin_listas;2712199 Wrote:
>
>> There should be an option in Yast bootloader.
>
> Yes, I found it, but it is not where I was looking.
> I’ll reboot in an instant to find out if it worked. I’ll say in a minute.

No… did not work. YaST fails to restore generic MBR.


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

On 2015-05-27 00:20, Carlos E. R. wrote:
> On 2015-05-26 23:46, nrickert wrote:

>> As an alternative, you can find the generic boot code at:
>>
>> Code:
>> --------------------
>> /usr/share/syslinux/mbr.bin
>> --------------------
>
> Yes, it is there. I’ll try the dd way if the previous attempt doesn’t work.

There are instructions in /usr/share/doc/packages/syslinux/syslinux.txt:

+++—-—-—-—-—-—-—-
A simple MBR, roughly on par with the one installed by DOS (but
unencumbered), is included in the SYSLINUX distribution. To install
it under Linux, simply type:

cat mbr.bin > /dev/XXX

… where /dev/XXX is the device you wish to install it on.
̣—-—-—-—-—-—-—-+±

I’ll make a backup copy of the current MBR first, just in case.

Actually, I did a backup before telling yast to do its job, and the copy before and after are the same. YaST did nothing. Bug? But useless to report, this is 13.1

Looks good:


minas-tirith:~/MBR_BCK # file -s /dev/sda
/dev/sda: DOS/MBR boot sector; partition 1 : ID=0x7, active, start-CHS (0x0,32,33), end-CHS (0x19,126,37), startsector 2048, 407552 sectors; partition 2 : ID=0x7, start-CHS (0x19,126,38), end-CHS (0x3ff,254,63), startsector 409600, 332869632 sectors; partition 3 : ID=0x7, start-CHS (0x3ff,254,63), end-CHS (0x3ff,254,63), startsector 950562816, 26208256 sectors; partition 4 : ID=0xf, start-CHS (0x3ff,254,63), end-CHS (0x3ff,254,63), startsector 333284490, 617265495 sectors
minas-tirith:~/MBR_BCK #

I’ll try booting again.


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

On 27/05/2015 0:51, Carlos E. R. wrote:

> I’ll try booting again.

It worked! Windows booted happily, no grub. Now I’ll try again the
updates. Later I’ll restore the boot mark to get grub back, should be easy.


Cheers,
Carlos E. R.
(W7 - minas-morgul)

On 27/05/2015 0:20, Carlos E. R. wrote:

>> Yes, some Windows updates check the booting. And those go astray if the
>> active flag is not set for the Windows partition. So your diagnosis is
>> probably correct.
>
> It happened to me on the first service pack.

Yes, that was it: the update succeeded this time.

I use Windows very seldom, so I forget what was pending from the last
session, but as far as I remember, the update failed twice, and was
reverted, twice as well (automatically). This time, with the generic MBR
and sda1 marked bootable, it went well. Now there is one more update
pending.

Sigh… each time I have to use Windows, to do maintenance or updates on
gadgets that are only supported via Windows, it is a black hole of time.
Lots of updates, that download slowly even on a fast network, done via
many interfaces. Each program updating independently, instead of having
YaST doing it all. Or almost all.


Cheers,
Carlos E. R.
(W7 - minas-morgul)

That happened to me with a Vista service pack. So I setup my system to use the Windows boot manager, so that Windows could think it was in charge.

I had a similar problem with Windows 8, and then again with 8.1. I had to revert some of the changes that I had made to UEFI booting to keep it happy.

In my experience yast-bootloader is quite unreliable at changing bootloader location. I always recommend to select “No bootloader” first, save and quit, and then start yast-bootloader again, chose bootloader and configure it. Yast-bootoader apparently does many things only the first time ever.

On 2015-05-27 06:46, arvidjaar wrote:
>
> robin_listas;2712217 Wrote:
>>
>>
>> No… did not work. YaST fails to restore generic MBR.
>>
>
> In my experience yast-bootloader is quite unreliable at changing
> bootloader location. I always recommend to select “No bootloader” first,
> save and quit, and then start yast-bootloader again, chose bootloader
> and configure it. Yast-bootoader apparently does many things only the
> first time ever.

Ah… worth a try. I’m on my desktop now, later I’ll try the laptop (it
is there I have the issue).


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

That’s about what I have experienced.

Changing from grub2 to grub2-efi has worked, as has the converse. But for anything less it seems that some additional manual “adjustment” is needed.

On 2015-05-27 00:36, nrickert wrote:
>
> robin_listas;2712215 Wrote:
>> If it has to be copied at the start, not at the end… I don’t remember.
> It’s at the start. After that is 6 bytes of some windows disk ID, 64
> bytes of partition table and 2 bytes of bootable-flag. So the first 440
> bytes is what you need to replace.

Oh, my. The ID! If it is what fdisk calls “Disk identifier”, changing it
makes Windows think it is an illegal copy.

I’ll try booting. If Windows complains, I’ll restore the backup, get the
ID, copy again the generic mbr from isolinux, then write the ID using fdisk.


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

I haven’t run into that particular problem. However, I do remember back in the good old days, where every time “lilo” rewrote the MBR, Windows would ask if it could set something for the disk. I think that was Window NT workstation 3.5 or so. Eventually, lilo started writing 6 fewer bytes to avoid annoying Windows.

Around 2 weeks ago, I replaced the hard drive in my wife’s computer. I use Acronis for backup and restore. Windows didn’t make much of a fuss, though shortly after boot it did say something about “installing a driver”. It didn’t act as if this was an illegal copy. This was a Dell computer with the OEM installed Windows 7.

On 2015-05-27 15:06, nrickert wrote:
>
> robin_listas;2712297 Wrote:
>> Oh, my. The ID! If it is what fdisk calls “Disk identifier”, changing it
>> makes Windows think it is an illegal copy.
>
> I haven’t run into that particular problem.

No, this time it did not happen. The identifier must be part of the
partition table section, not the code section.

It is this one:


minas-tirith:~ # fdisk -l /dev/sda

Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 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
Disk label type: dos
Disk identifier: 0xb4e*****   <===========

Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048      409599      203776    7  HPFS/NTFS/exFAT
....

You can change it in fdisk. I had to replace this laptop HD some time
ago, and I cloned the disk. I thought I would change that ID, and on the
next boot Windows said it was a pirated copy. Change it back, Windows
was happy again.

> However, I do remember back
> in the good old days, where every time “lilo” rewrote the MBR, Windows
> would ask if it could set something for the disk. I think that was
> Window NT workstation 3.5 or so. Eventually, lilo started writing 6
> fewer bytes to avoid annoying Windows.

Rings a bell here.

> Around 2 weeks ago, I replaced the hard drive in my wife’s computer. I
> use Acronis for backup and restore. Windows didn’t make much of a fuss,
> though shortly after boot it did say something about “installing a
> driver”. It didn’t act as if this was an illegal copy. This was a Dell
> computer with the OEM installed Windows 7.

Probably Acronis cloned the ID. You can play with it in fdisk and find
out :wink:


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

Since, you have sorted out your problem, let’s break our heads over WIndoze /FixMbr. Might be a little off track to what you people are discussing right now. Other ways to access /FixMbr

  • The windoze 7 installation medium also has /FixMbr tool. When running windoze 7 installation medium, it will ask whether you want to troubleshoot and you go into cmd and access /FixMbr by the command.
  • There is another hack. You can directly create Recovery USB for windoze 7. Read kioskea.net article - Windows 7 - Create a system repair USB

Not possible! The daft thing says wrong parameter, error “0x80070057”. I
tried a CD and a DVD, no go.

Of course, I also searched for this error
("0x80070057" error message when you back up files in Windows 7 - Microsoft Support). The page proposes
two methods, none works. I can not create the recovery disk.

Sorry never had this problem.

On 2015-05-27 18:46, vishy wrote:
> robin_listas;2712199 Wrote:

> Since, you have sorted out your problem, let’s break our heads over
> WIndoze /FixMbr. Might be a little off track to what you people are
> discussing right now. Other ways to access /FixMbr
>
> - The windoze 7 installation medium also has /FixMbr tool. When
> running windoze 7 installation medium, it will ask whether you
> want to troubleshoot and you go into cmd and access /FixMbr by
> the command.

But I don’t have the original installation medium: it is a Compaq
laptop, that came with Windows already installed and a recovery
partition. I made a set of recovery disks, which I stored safely away,
and of course, I have forgotten where.

I do have a Windows installation DVD, but it contains all the Windows 7
and the corresponding server edition. I’m not sure it allows rescue: I
was about to try, when I saw the suggestion here on how to copy the
generic code, which was faster to do.

> - There is another hack. You can directly create Recovery USB
> for windoze 7. Read ‘kioskea.net article - Windows 7 -
> Create a system repair USB’ (http://tinyurl.com/of94gmw)

Wow! That’s nice. I can try that.

Now I only need to find a small stick. Even 8 GB units are difficult to
find.

>> Not possible! The daft thing says wrong parameter, error “0x80070057”. I
>> tried a CD and a DVD, no go.
>>
>> Of course, I also searched for this error
>> (https://support.microsoft.com/en-us/kb/982736/es). The page proposes
>> two methods, none works. I can not create the recovery disk.
> Sorry never had this problem.

Isn’t it lovely, those numeric errors? :-/


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)