1

I'm trying to test grub2 on puppet in a VM and one of the tests is to make sure it'll still work on a wiped MBR.

So I wipe the MBR with

dd if=/dev/zero of=/dev/vda bs=512 count=1

Then I try to install grub2 with

grub2-install /dev/vda

and get

Path ‘/boot/grub2’ is not readable by GRUB on boot. Installation is impossible. Aborting.

If I try to install grub2 without wiping the MBR first it works just fine.

Any ideas?

1
  • Indeed, may be you should wipe only 446 bytes with grub code, while leaving partition table (64 bytes) and magic number (2 bytes) untouched? Besides, why would you wipe MBR at all? How is it supposed to work without MBR? :) Commented Apr 7, 2014 at 16:48

1 Answer 1

0

If you take a look at what is stored in the first sector (e.g., in Wikipedia's MBR article) you'll find that you wiped the partition table.

Without a partition table, your /boot partition probably no longer exists.

I suggest you do something like this to save and restore it:

sfdisk -d /dev/vda > part-table
dd if=/dev/zero of=/dev/vda bs=512 count=1 # note, maybe want more than 1
sfdisk /dev/vda < part-table
grub2-install /dev/vda

Note that grub actually occupies part of sector 0 and also sectors 1–n, where n is some number less than the start of your first partition. You may want to wipe those sectors as well.

3
  • Oh, that's interesting. So if I wanted to clear just the MBR what would I need to do? I need to test grub2, so I need to try it on a non-bootable system. Commented Apr 7, 2014 at 17:04
  • @user3439528 You are just clearing the MBR. Its just that the MBR also contains the partition table, so you need to restore that after clearing. Commented Apr 7, 2014 at 17:06
  • Is it any different if I wipe 446 bytes instead of 512? If what I'm reading is correct, that would wipe only the MBR. Otherwise yes, I suppose I could save the partition table and restore it after wiping the sector. Thank you very much for the responses, by the way. Commented Apr 7, 2014 at 17:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.