10 Replies Latest reply on May 20, 2005 12:43 PM by Jarrod Boland


      Has anyone ever added grub.conf as a configuration object? None of the grammars seem to apply, the first few lines are name=value but I can't figure out how to address the remaining entries.

        • 1. Re: /boot/grub/grub.conf

          I'm not sure if you will be able to do this. The problem with grub.conf is that it is a mix of name=value and name . I run a machine that boots with grub. When I get back to it, I will take a look at it and see if I can come up with a solution.



          • 2. Re: /boot/grub/grub.conf

            All right, I took a look at my grub.conf file and these are the type of entries that are actually in there:


            name value (eg. timeout 15)

            name=value (eg. title=Gentoo 2.6.10)

            name value value... (eg. kernel /kernel-2.6.10 root=/dev/hda3 )


            I would be pretty sure that there is defiantly no grammer that handles this entire config file. One main reason is their many different ways to configure the grub.conf. If you have the sample file that comes with grub (grub.conf.sample) you will see what I mean. Each type of system has its own way to do it, using different combinations of the grammers above.


            Do you have an example file that you would want to parse? Are you trying to parse a config that has multiple boot configuration or a single one? If it is something that would be uniform, you might be able to do it, otherwise I'm not sure you will be able to. Jarrod might also be able to help. I know he has written several grammers.



            • 3. Re: /boot/grub/grub.conf

              You will notice that there can be a simple grammar written for a grub.conf file that uses ' ' or '=' as the seperator. Then anything after the seperator as a single value. So, define:




              for the read.


              KEY is 1 or more alpha-numeric characters.


              SEPERATOR is ' ' or '='

              Note: ' ' is only considered a seperator if the first character following the white space after the KEY is not an '='. This is because the GRUB parser does respect whitespace surrounding an '=' and it does not need to butt up to the KEY and VALUE sections.


              VALUE is '.*' or NULL, though I haven't seen a good example of a NULL value.


              Now the trick is to store and reprint the proper SEPERATOR when re-writing the file. This is done by prepending the SEPERATOR to the VALUE when the VALUE is stored. The write portion of the grammar then only outputs KEY and VALUE and automatically inherits the SEPERATOR from the first character of the VALUE.


              Yes, Jarrod tought me how to write grammars. I know just enough to be dangerous... I wish I had time to create this grammar. So, who wants to do it?


              • 4. Re: /boot/grub/grub.conf

                I forgot to mention that there is the potential for duplicate keys for sections of different booting groups. The section needs to work like the INI file type using a combination of section and key for defining a unique key.


                There are also non-sectional global values that will end up with a NULL section. But, being global these will not duplicate and should stay unique with a NULL section value.


                Complex but not impossible...

                • 5. Re: /boot/grub/grub.conf



                  I've been looking at the file a bit and am now entirely sure of how the non-= part of the file is divided into sections. How does the file know when a new header has begun? Could you please post an example section of the file and show how the file understands when a section ends. From what I can tell, it's either based on indentation (less likely) or on some keyword (more likely), but I've only seen 1-2 of these files and don't feel confident making that assumption. If you provide this info, then I can crank out a grammar for the file.

                  • 6. Re: /boot/grub/grub.conf

                    At the top of the file are all the non-sectional parameters. If a section key is required perhaps start with it set to "NONE" or "" if it is easier for printing. Then when you hit a section use that value. Sections begin with the "title" keyword. A new section begins when a new "title" line is encountered.



                    • 7. Re: /boot/grub/grub.conf

                      Just to help you lot out, here's a copy from my laptop:


                      title Fedora Core (2.6.10-1.766_FC3)
                      root (hd0,4)
                      kernel /boot/vmlinuz-2.6.10-1.766_FC3 ro root=LABEL=/ rhgb quiet
                      initrd /boot/initrd-2.6.10-1.766_FC3.img resolution=1920x1200
                      title Fedora Core (2.6.10-1.766_FC3) textual startup
                      root (hd0,4)
                      kernel /boot/vmlinuz-2.6.10-1.766_FC3 ro root=LABEL=/ quiet
                      initrd /boot/initrd-2.6.10-1.766_FC3.img resolution=1920x1200
                      title Fedora Core (2.6.10-1.766_FC3smp)
                      root (hd0,4)
                      kernel /boot/vmlinuz-2.6.10-1.766_FC3smp ro root=LABEL=/ rhgb quiet
                      initrd /boot/initrd-2.6.10-1.766_FC3smp.img resolution=1920x1200
                      title Fedora Core (2.6.10-1.741_FC3)
                      root (hd0,4)
                      kernel /boot/vmlinuz-2.6.10-1.741_FC3 ro root=LABEL=/ rhgb quiet
                      initrd /boot/initrd-2.6.10-1.741_FC3.img resolution=1920x1200
                      title Windows XP
                      rootnoverify (hd0,0)
                      chainloader +1


                      • 8. Re: /boot/grub/grub.conf

                        Just a bump for this topic. Is the grub.conf grammar looking feasible?


                        • 9. Re: /boot/grub/grub.conf

                          Thanks for the reminder. I've written a grammar to handle the parsing of 1-2 example grub.conf files I've seen. It does NOT do any deployments at this point, but it should parse (i.e. browse/snap/audit) successfully. I'll get around to looking at the deployment functionality later this week.


                          I'll post it to the KB once I get the deployment functionality working; for now, feel free to test the browse/snap/audit. Grammar text below:





                          1. JBoland, 5/17/05 - Grammar to parse grub.conf.

                          2. Does not support deployments at this time.




                          BL_CFG_DEBUG 1


                          VAR_EQUAL =

                          VAR_TAB \t





                          WS /t/n%20*

                          VAL *

                          KEY +

                          SQUOTE_STR '[^'\n]*

                          DQUOTE_STR \"[^"\n]*["\n]

                          EQUAL =

                          TITLE title

                          TITLE_VAL /n*

                          TAB \t




                          record WS KEY WS EQUAL WS VAL WS $new_field $1 $new_field $5 $save_record $1


                          subitem TAB KEY WS VAL WS $new_field $1 $new_field $3 $set_parent $PARENT \

                          $save_record $1


                          ext_vals VAL WS $append_field_to_var $PARENT $0 %ext_vals


                          header TITLE WS VAL WS $new_field $0 $save_var $PARENT $2 %ext_vals \

                          $new_field $PARENT $set_as_nonleaf $save_record $PARENT





                          add $write_field $0 $write_var $VAR_EQUAL $write_fields $1 $VAR_TAB

                          • 10. Re: /boot/grub/grub.conf



                            I've make some modifications to the grub.gm:


                            1. Fixed some of the parsing

                            2. Added deployment capability.


                            I've posted the actual file in the KB. Enjoy!





                            Message was edited by: Jarrod Boland