You are not logged in.

#1 2016-04-06 18:29:41

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

[SOLVED] Grub's Location?

Hey everyone, while taking my morning and going through the GRUB manual:

Grub Install

I came across two questions that are picking at me.  This is in regards to an MBR partitioned disk. There are apparently two "main" methods to installing GRUB to an MBR style disk. We can insert GRUB after the leading chunk of MBR on the disk,  and before the first partition. Or we can install GRUB to a specified partition itself. (Usually the first). Do i have this right?



So my questions are thus:


1. If the first option is chosen, to insert the bootloader after the MBR, would we still have a /boot/grub directory? Or would this directory, along with the core GRUB img, (/boot/grub/i386-pc/core.img) be installed then in the area after the MBR?

2. Does this imply that having a /boot/grub directory and general grub files, mean that GRUB is installed on your partition?

3. I then read from other sources that GRUB is installed IN the MBR? Is this just a difference in syntax? It sounds like it's different than doing it after the MBR and before the 1st partition.

4.  If you put /boot onto a separate partition. Does this work the same way as it being installed on say /dev/sda1 or /dev/sda2?


Thanks everyone, hope these make sense...

Last edited by Horizon_Brave (2016-04-09 00:29:32)


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#2 2016-04-06 18:48:50

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: [SOLVED] Grub's Location?

Horizon_Brave wrote:

There are apparently two "main" methods to installing GRUB to an MBR style disk. We can insert GRUB after the leading chunk of MBR on the disk,  and before the first partition. Or we can install GRUB to a specified partition itself. (Usually the first). Do i have this right?

Yes but it is not recommended to install GRUB to a partition.

Warning: GRUB strongly discourages installation to a partition boot sector or a partitionless disk as GRUB Legacy or Syslinux does. This setup is prone to breakage, especially during updates, and is not supported by the Arch developers.

https://wiki.archlinux.org/index.php/GR … nless_disk

Horizon_Brave wrote:

1. If the first option is chosen, to insert the bootloader after the MBR, would we still have a /boot/grub directory?

Yes, there isn't much space in the MBR.

Horizon_Brave wrote:

2. Does this imply that having a /boot/grub directory and general grub files, mean that GRUB is installed on your partition?

I'm not sure I understand your question but I'm going to go with "no"

Horizon_Brave wrote:

3. I then read from other sources that GRUB is installed IN the MBR? Is this just a difference in syntax? It sounds like it's different than doing it after the MBR and before the 1st partition.

boot.img is stored in the MBR itself (or optionally in any of the volume boot records) and starts the next stage via an LBA48 address; at installation time this is configured to load core.img (stored in the free space between sectors 1 & 63), this then loads any modules needed and passes on to the second stage which reads all it's configuration from /boot/grub

More here:
https://en.wikipedia.org/wiki/GNU_GRUB

Horizon_Brave wrote:

4.  If you put /boot onto a separate partition. Does this work the same way as it being installed on say /dev/sda1 or /dev/sda2?

I don't understand your question sad

Offline

#3 2016-04-06 19:41:34

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: [SOLVED] Grub's Location?

Head_on_a_Stick wrote:
Horizon_Brave wrote:

2. Does this imply that having a /boot/grub directory and general grub files, mean that GRUB is installed on your partition?

I'm not sure I understand your question but I'm going to go with "no"

Thanks for the response HoaS.  I'll try to clarify this one... Right now, I can go into my /boot/grub/i386-pc/ directory and I have core.img and boot.img there. (as well as a bunch of other files)   So because these two are in this directory, what if anything, is installed in the MBR or after the MBR? Does this mean I have 100 percent of GRUB installed on my / partition?  If not, what else is on/after the MBR?


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#4 2016-04-06 19:55:29

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: [SOLVED] Grub's Location?

Horizon_Brave wrote:

So because these two are in this directory, what if anything, is installed in the MBR or after the MBR? Does this mean I have 100 percent of GRUB installed on my / partition?  If not, what else is on/after the MBR?

If you have an MBR disk then the situation is as described on the Wikipedia page.

I don't think the presence of core.img in /boot/grub means that there is no such file in the MBR -- why would it?

If I had to guess, I would say that core.img is there so that it can be copied to the MBR when GRUB is installed to the disk.

Offline

#5 2016-04-06 20:56:39

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: [SOLVED] Grub's Location?

This pretty much sums it up...

MBR_Grub_Boot.jpg


And this one to a degree:

MBR_Grub_Boot2.jpg

T.Hanks Hoas!


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#6 2016-04-06 20:58:32

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: [SOLVED] Grub's Location?

UEFI is completely different, of course big_smile

https://www.happyassassin.net/2014/01/2 … work-then/

Offline

#7 2016-04-06 21:37:38

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: [SOLVED] Grub's Location?

Oh believe me, I know! I'm just making sure I have  the BIOS/MBR/GRUB  relationship down, before I even tackle UEFI/GPT/GRUB

Last edited by Horizon_Brave (2016-04-06 21:38:54)


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#8 2016-04-06 21:55:06

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: [SOLVED] Grub's Location?

Horizon_Brave wrote:

UEFI/GPT/GRUB

I prefer to use gummiboot for UEFI systems smile

Or forgo a bootloader entirely and boot the kernel image directly using EFI_STUB booting via a custom NVRAM entry.

That gets a bit fiddly when you need to change kernel parameters or multiboot though...

Offline

#9 2016-04-06 23:32:37

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: [SOLVED] Grub's Location?

Oh, and HoaS, I think you're right. After snapshotting the heck out of my Bunsenlabs VM, I daringly removed the boot.img and core.img file from /boot/grub/i386-pc/  :

gamera@bunsenlab2:/boot/grub/i386-pc$ ls | egrep "*.img"
boot.img
core.img

gamera@bunsenlab2:/boot/grub/i386-pc$ sudo rm *.img
[sudo] password for gamera: 
gamera@bunsenlab2:/boot/grub/i386-pc$ ls | egrep "*.img"
gamera@bunsenlab2:/boot/grub/i386-pc$ 

I went for a reboot, to see if grub still existed, and walla, it still boots. So you're definitely right when you say that those two files are probably put there to copy into the MBR and "post-mbr" area.  And again the wiki images and article verify that as well...

**That being said, no one here should actually rm these two files!! Unless you're in a VM and are experimenting!**

Last edited by Horizon_Brave (2016-04-06 23:34:22)


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#10 2016-04-07 07:22:21

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: [SOLVED] Grub's Location?

Horizon_Brave wrote:

I daringly removed the boot.img and core.img file from /boot/grub/i386-pc/

Just out of interest, what happens if you try `grub-install` with those files removed?

Also, using `mv` rather than `rm` would have been more sensible wink

Offline

#11 2016-04-07 11:33:50

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: [SOLVED] Grub's Location?

Head_on_a_Stick wrote:
Horizon_Brave wrote:

I daringly removed the boot.img and core.img file from /boot/grub/i386-pc/

Just out of interest, what happens if you try `grub-install` with those files removed?

Also, using `mv` rather than `rm` would have been more sensible wink

Ooo good idea, I'll make another backup and find out later today! ?  thank the maker for virtualbox...


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#12 2016-04-07 16:10:43

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: [SOLVED] Grub's Location?

Okay, pretty interesting...

So I reset my Bunsen VM back to normal state, the boot.img and core.img file exist as per normal, in /boot/grub/i386-pc/

gamera@bunsenlab2:/boot/grub/i386-pc$ ls | grep .img
boot.img
core.img
gamera@bunsenlab2:/boot/grub/i386-pc$ 

Now, I'll rm them both...

gamera@bunsenlab2:/boot/grub/i386-pc$ sudo rm *.img
gamera@bunsenlab2:/boot/grub/i386-pc$ ls | grep .img
gamera@bunsenlab2:/boot/grub/i386-pc$ 

All gone... Now as HoaS suggests to try to do a grub install:

gamera@bunsenlab2:/boot/grub/i386-pc$ sudo grub-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
gamera@bunsenlab2:/boot/grub/i386-pc$ 
gamera@bunsenlab2:/boot/grub/i386-pc$ ls | grep .img
boot.img
core.img
gamera@bunsenlab2:/boot/grub/i386-pc$ 

After the install, the files are re-generated! My question is where did it pull the files from? Did it query the MBR, for the boot.img and query the 'post MBR' area for the core.img file?  OR does it have both files stored elsewhere on the drive, for redundancy?


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#13 2016-04-07 16:25:35

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: [SOLVED] Grub's Location?

I found this here

For a BIOS/USB boot, Grub 2 basically works on the principle of a standard MBR (boot.img), that calls a custom second stage (core.img), which usually sits right after the MBR (sector 1, or 0x200 on the UFD) and which is a flat compressed image containing the Grub 2 kernel plus a user hand-picked set of modules (.mod).

So it would seem that boot.img and core.img are both written to or next to the MBR when grub is first installed. Presumably they are backed up automatically after you have deleted them from /boot/, if the grub-install checks for them first.


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#14 2016-04-07 18:32:26

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,709

Re: [SOLVED] Grub's Location?

damo wrote:

So it would seem that boot.img and core.img are both written to or next to the MBR when grub is first installed. Presumably they are backed up automatically after you have deleted them from /boot/, if the grub-install checks for them first.

It is exactly like that!
Unfortunately, I have the only in German. Better I have can not find.

How GRUB2 comes to disk?
..
Writing boot.img and core.img in the boot sector and the area between boot sector and partition first, by grub-setup.

..
A disadvantage of GRUB2 is that it is not usable when between boot sector and partition first not enough space for the core.img with appropriate file system module is free.

Offline

#15 2016-04-07 18:41:34

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: [SOLVED] Grub's Location?

unklar wrote:
damo wrote:

So it would seem that boot.img and core.img are both written to or next to the MBR when grub is first installed. Presumably they are backed up automatically after you have deleted them from /boot/, if the grub-install checks for them first.

It is exactly like that!
Unfortunately, I have the only in German. Better I have can not find.

How GRUB2 comes to disk?
..
Writing boot.img and core.img in the boot sector and the area between boot sector and partition first, by grub-setup.

..
A disadvantage of GRUB2 is that it is not usable when between boot sector and partition first not enough space for the core.img with appropriate file system module is free.

Das ist gut! Ich leise Deustch!


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#16 2016-04-08 10:06:22

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,709

Re: [SOLVED] Grub's Location?

@Horizon_Brave

das freut mich sehr!
that pleases me very much!   wink

Offline

#17 2016-04-08 22:34:41

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: [SOLVED] Grub's Location?

So... is this thread [SOLVED] then?

Offline

#18 2016-04-09 00:29:12

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: [SOLVED] Grub's Location?

Head_on_a_Stick wrote:

So... is this thread [SOLVED] then?


lol, whoops. Yep. I'll tag it. There may be another set of questions once I return to this from the UEFI>GPT>GRUB  config..but that'll be a different thread perhaps.  For now... i'm good.  Thanks everyone.


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

Board footer

Powered by FluxBB