Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

One of the new features of Grub2 is scriptability. At my work we're using it to great affect. However, I recent stumbled on a terrible short coming. There isn't any string manipulation or arithmetic support.

My exact problem: I need to mess with a PCI device before booting. Between setpci and write_dword I can easily write the values I need to. I get the Base address register from setpci, and 0x18 to it, and write the desired value to that address.

I did the math in my head while experimenting, but now I can't figure out how to get Grub2 to do the same math at boot time.

To add insult to injury, the PCI address always end in 000. So in theory I could just replace the last two 0's with "18" and that would work as well. Once again Grub2 fails me, with no string manipulation support.

Is there a way to get a substring in Grub2 script?
Is there a way to perform arithmetic in Grub2 script?

share|improve this question
up vote 1 down vote accepted

If you want scriptability in Grub2, you need the lua support, which is not part of the released version. It's part of the grub-extras, and you can get the source from the bazaar repository. You'll need to rebuild Grub2 from source. I don't think there's any documentation apart from the source, though you can ask for help on the grub-devel mailing list. Good luck.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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