OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:30 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: A question about GRUB
PostPosted: Fri May 05, 2017 9:34 am 
Offline
User avatar

Joined: Thu May 04, 2017 2:03 am
Posts: 13
Not specifically OS dev. related so I thought I'd just post it here.

After compilation of my kernel has finished, the linked binary is copied to a root directory which in turn is written to an ISO image by genisoimage, pretty normal stuff.
Instead of using grub-mkrescue however (which is recommended by the Wiki if I remember correctly and many of you probably also do it like this), I'm using grub-mkimage so that I can select which GRUB modules I want and the image doesn't immediately become 20 megabytes.

The modules I have included are
Code:
i386-pc biosdisk boot iso9660 multiboot normal

Works like a charm for booting from cdrom

The thing is that comments in my grub.cfg file are interpreted instead of ignored, which results 3 (the amount of comments in the file) ugly warnings during boot:
Code:
Unknown command '#'.
Unknown command '#'.
Unknown command '#'.


I've looked through a bunch of docs (and even tried to find it in the enormous GRUB2 source which is pretty much impossible) but I just can't seem to find what I'm missing. If anyone knows about a module or switch that resolves this, I'd love to hear it!

_________________
"Writing a portable OS is not much harder than a nonportable one, and all systems should be written with portability in mind these days." — Andrew S. Tanenbaum

Elarix
Source: https://github.com/teeuwen/elarix


Top
 Profile  
 
 Post subject: Re: A question about GRUB
PostPosted: Sat May 06, 2017 7:33 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
Do these comments start on the start of the line? (Column 1) or somewhere after a few whitespaces?

The grub2 docs mention that starting a line with # makes it a comment, but it warns if a command has been broken in the middle then parser will be upset.

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: A question about GRUB
PostPosted: Sat May 06, 2017 10:26 am 
Offline
User avatar

Joined: Thu May 04, 2017 2:03 am
Posts: 13
dozniak wrote:
Do these comments start on the start of the line? (Column 1) or somewhere after a few whitespaces?

The grub2 docs mention that starting a line with # makes it a comment, but it warns if a command has been broken in the middle then parser will be upset.


Nope, it contains exactly this:

Code:
#
# /boot/grub/grub.cfg: configuration file for GRUB
#

multiboot /boot/kernel root=/sys/dev/hda0 rootfs=iso9660 console=/sys/dev/con0
boot


Unix line endings, nothing out of the ordinary. And I should mention that this works just fine if I'm using grub-mkrescue, so it has nothing to do with syntax errors. Thanks for your reply though!

_________________
"Writing a portable OS is not much harder than a nonportable one, and all systems should be written with portability in mind these days." — Andrew S. Tanenbaum

Elarix
Source: https://github.com/teeuwen/elarix


Top
 Profile  
 
 Post subject: Re: A question about GRUB
PostPosted: Sat May 06, 2017 2:28 pm 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
teeuwen wrote:
Unix line endings, nothing out of the ordinary. And I should mention that this works just fine if I'm using grub-mkrescue, so it has nothing to do with syntax errors. Thanks for your reply though!


Does mkrescue probably strip the comments from the cfg file before writing it to the image?

I haven't looked into the grub code itself, but it may be worth doing just to see where exactly the `#` parsing and stripping takes place.

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: A question about GRUB
PostPosted: Sat May 06, 2017 3:19 pm 
Offline
User avatar

Joined: Thu May 04, 2017 2:03 am
Posts: 13
dozniak wrote:
teeuwen wrote:
Unix line endings, nothing out of the ordinary. And I should mention that this works just fine if I'm using grub-mkrescue, so it has nothing to do with syntax errors. Thanks for your reply though!


Does mkrescue probably strip the comments from the cfg file before writing it to the image?

I haven't looked into the grub code itself, but it may be worth doing just to see where exactly the `#` parsing and stripping takes place.


I have, like I mentioned before, and here's my findings:

So after downloading the source I did a grep for '#', which gives about 2 dozen results. Note that all the relevant results are in the grub-core/ directory and utilities like grub-mkrescue and grub-mkimage are in utils/.
This (probably) rules out the possibility that mkrescue strips out comments, because this is all handled by the "normal" module (which I did include) and I couldn't find any comment stripping code in the mkrescue source.
The exact location where the comments are stripped is: grub-core/normal/main.c > grub_cmd_normal > grub_enter_normal_mode > grub_normal_executable > read_config_file > read_config_file_getline (on line 96 in the GRUB git repo). No arguments to any of the functions to ignore comments or anything like that. This just seems like a dead end to me. It may even be a bug.

_________________
"Writing a portable OS is not much harder than a nonportable one, and all systems should be written with portability in mind these days." — Andrew S. Tanenbaum

Elarix
Source: https://github.com/teeuwen/elarix


Top
 Profile  
 
 Post subject: Re: A question about GRUB
PostPosted: Sat May 06, 2017 3:25 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 21, 2011 9:47 pm
Posts: 286
Location: Tustin, CA USA
It was a simple test for me... grub2-mkrescue did not strip comments.

Just curious, is this grub or grub2?

_________________
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber


Top
 Profile  
 
 Post subject: Re: A question about GRUB
PostPosted: Sat May 06, 2017 3:33 pm 
Offline
User avatar

Joined: Thu May 04, 2017 2:03 am
Posts: 13
eryjus wrote:
It was a simple test for me... grub2-mkrescue did not strip comments.

Just curious, is this grub or grub2?


GRUB2, 2.02~rc2 to be specific.

But what do mean when you say that grub-mkrescue does NOT strip comments for you? Because it sure does for me.

_________________
"Writing a portable OS is not much harder than a nonportable one, and all systems should be written with portability in mind these days." — Andrew S. Tanenbaum

Elarix
Source: https://github.com/teeuwen/elarix


Top
 Profile  
 
 Post subject: Re: A question about GRUB
PostPosted: Sat May 06, 2017 3:39 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 21, 2011 9:47 pm
Posts: 286
Location: Tustin, CA USA
teeuwen wrote:
But what do mean when you say that grub-mkrescue does NOT strip comments for you?


I added a comment into my grub.cfg and ran grub2-mkrescue. In fact:
Code:
grub2-mkrescue -o $@ $(I686-KERNEL-SYSROOT) 2> /dev/null

the command line is rather simple. I opened the resulting .iso with ark and navigated to the grub.cfg therein and opened it. The comments were still there as I wrote them. I also checked that the image was bootable and I was able to boot both my MB and MB2 header from the resulting .iso.

For the record:
Code:
[adam@os-dev century]$ grub2-mkrescue --version
grub2-mkrescue (GRUB) 2.02~beta3

and I am running on FC25 and I am patch-current as of 7 days ago.

_________________
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber


Top
 Profile  
 
 Post subject: Re: A question about GRUB
PostPosted: Sat May 06, 2017 3:58 pm 
Offline
User avatar

Joined: Thu May 04, 2017 2:03 am
Posts: 13
eryjus wrote:
teeuwen wrote:
But what do mean when you say that grub-mkrescue does NOT strip comments for you?


I added a comment into my grub.cfg and ran grub2-mkrescue. In fact:
Code:
grub2-mkrescue -o $@ $(I686-KERNEL-SYSROOT) 2> /dev/null

the command line is rather simple. I opened the resulting .iso with ark and navigated to the grub.cfg therein and opened it. The comments were still there as I wrote them. I also checked that the image was bootable and I was able to boot both my MB and MB2 header from the resulting .iso.

For the record:
Code:
[adam@os-dev century]$ grub2-mkrescue --version
grub2-mkrescue (GRUB) 2.02~beta3

and I am running on FC25 and I am patch-current as of 7 days ago.


I think you're missing the point here I'm afraid.
Attachment:
2017-05-06-235603_3200x1080_scrot.png
2017-05-06-235603_3200x1080_scrot.png [ 7.25 KiB | Viewed 5318 times ]

And grub-mkrescue is the one that is working just fine. The problem is with grub-mkimage.

_________________
"Writing a portable OS is not much harder than a nonportable one, and all systems should be written with portability in mind these days." — Andrew S. Tanenbaum

Elarix
Source: https://github.com/teeuwen/elarix


Top
 Profile  
 
 Post subject: Re: A question about GRUB
PostPosted: Sat May 06, 2017 5:07 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 21, 2011 9:47 pm
Posts: 286
Location: Tustin, CA USA
teeuwen wrote:
I think you're missing the point here I'm afraid.


Perhaps I did. I thought one comment was that mkrescue was stripping comments in grub.cfg. I was going after that comment and I was not clear.

Anyway, I'm more than happy to run a test for you here if you feel that would help. Just send me your command line.

_________________
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber


Top
 Profile  
 
 Post subject: Re: A question about GRUB
PostPosted: Sun May 07, 2017 4:08 am 
Offline
User avatar

Joined: Thu May 04, 2017 2:03 am
Posts: 13
I've filed a bug report: https://savannah.gnu.org/bugs/?50963

We'll see what happens now.

EDIT: Got a reply:
Quote:
Embedded config is interpreted by rescue parser, not by normal.mod. It is intended for limited use cases and not for general purpose scripting.

For some reason I don't quite believe the guy (even though he's a maintainer) as I've looked though the normal.mod code myself but I guess I'm gonna have to use grub-mkrescue or simply remove the comment after all.

_________________
"Writing a portable OS is not much harder than a nonportable one, and all systems should be written with portability in mind these days." — Andrew S. Tanenbaum

Elarix
Source: https://github.com/teeuwen/elarix


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 31 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group