1

I have tried to corrupt MBR with this command on CentOS 7

dd if=/dev/zero of=/dev/sda bs=446 count=1

As far as i know, the boot sector has 512 bytes length, the first 446 bytes is boot loader code, the rest is partition table.

After booting in Resecure Mode, /dev/sda1 is mounted on /mnt and chroot /mnt, i used grub2-install to repair boot loader on /dev/sda but it didn't success to boot again.

What point did i miss?

  • 2
    You missed taking a backup before intentionally breaking it. – roaima May 6 '18 at 7:18
  • 1
    /dev/sda is the disk. You're talking about MBR and partion table. therefore you shouldn't be talking about mounting /dev/sda to /mnt. that should be /dev/sda1 etc. – A.B May 6 '18 at 8:08
  • @A.B That is a typo, as the OP mentioning he mounts them. Good point though. – Rui F Ribeiro May 6 '18 at 10:11
  • Is Grub even in your MBR? Modern PCs often boot via UEFI. What was the original content of the first 446 bytes of /dev/sda? – Gilles May 6 '18 at 17:23
  • @Gilles pastebin.com/RMgpuskX I copy this from 'fdisk /dev/sda', in the original VM. How can you read this Hex code? btw – Federal Reserve May 20 '18 at 5:29
3

After chrooting, but before running grub2-install, you should have checked if /boot/grub/device.map exists or not. Normally, grub2-install creates it if it does not already exist, and it tries to guess which Linux device corresponds to which BIOS/GRUB disk identifier. If this mapping is wrong, you'll get strange results.

Unless your system is very special, if you are telling BIOS to boot from the disk that is /dev/sda, then /boot/grub/device.map should have this line in it:

(hd0) /dev/sda

If the device.map file did not exist when you ran grub2-install, it would have had to guess the mapping between Linux device names and BIOS/GRUB disk identifiers. Sometimes grub2-install can guess wrong. So if /boot/grub/device.map does not exist, you should create it with the correct information before running grub2-install to ensure successful repair.

If the /boot/grub/device.map file exists but has wrong information, you should fix it before running grub2-install.

Now you should again boot into rescue mode, chroot and then check the /boot/grub/device.map file, then run grub2-install /dev/sda.


Another possibility:

When you overwrite the first 446 bytes of the MBR, it includes the signature bytes that are used as disk UUID on MBR-partitioned disks. If the GRUB configuration is using the disk UUID to select the GRUB "root" partition, the UUID will now be different. Your distribution should have a command that can be used to easily rebuild the GRUB configuration file.

In Debian-style systems, it is probably update-grub.

In RedHat-style systems (Fedora, CentOS etc.), it might be grub2-mkconfig > /boot/grub/grub.cfg or similar.


The message: FATAL: INT18: BOOT FAILURE is not related to Grub at all, but a problem with VirtualBox.

Apparently VirtualBox checks the partition table to verify that a partition has been marked as active, and if there is no active partition, it reports an error instead of even trying to load & run the MBR code.

This check is unnecessary for GRUB, because if GRUB has been installed to the MBR, it will take control of the boot process regardless of which partition is marked as active.

Source: https://neosmart.net/wiki/fatal-int18-boot-failure/

Having the installation media image still inserted in the virtual CD-ROM drive might also do it, at least with older VirtualBox versions:

https://www.dedoimedo.com/computers/fedora-fatal-18.html

  • I tried to create device.map in both /boot/grub and /boot/grub2 After that, i generated config using grub2-mkconfig to both /boot/grub/grub.cfg and /boot/grub2/grub.cfg Then executed grub2-install /dev/sda again. It still got error when i select boot from Local Hard Drive – Federal Reserve May 20 '18 at 4:58
  • The error is FATAL: INIT18 : BOOT FAILURE – Federal Reserve May 20 '18 at 5:04
  • Looks like a VirtualBox error message. Updated my answer. – telcoM May 20 '18 at 5:19
  • OMG, thank you very much, i tested this lab for a week and didn't know what goes wrong. I should Google the Error before, didn't think it was VirtualBox. T_T – Federal Reserve May 20 '18 at 5:39
  • 1
    See? Posting the actual error message helps a lot! – telcoM May 20 '18 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.