Grub bootloader with shared library support
Asked Answered
C

1

11

I'd like to load a shared library (closed-source binary user-space library) at boot stage with grub boot-loader. Are there any chances for this or I must write a custom-elf-loader (grub module) to do it?


  • 29/08/2014: For more detail, this is a programming problem in which I want to customize or add some new features to Grub boot-loader project. Thank you for your all supporting!
Communize answered 20/8, 2014 at 4:25 Comment(8)
Why not?? @JonathonReinhartCommunize
As the most prolific off-topic flagger on the grub tag, I would just like to point out this question is 100% on-topic.Imbrue
Oh, and I would also quite like to write an answer. So could it be de-[on hold]ed please?Imbrue
Hey, this has just been reopened and people already start flagging it as off-topic. Stop. It's perfectly on-topic here. @Imbrue go ahead, answer before it's too late again.Infeudation
@LucasTrzesniewski: much obliged.Imbrue
@LucasTrzesniewski As I said on Meta, I still feel this question is off-topic. If it were to ask how to write a grub module to load a shared object/.so file, it'd be a programming question. As it stands, it appears to be a question on how to use grub, which is a question more suited to UNIX & Linux or SuperUser.Sycee
@Sycee I agree there's some ambiguity here, but I wouldn't expect an answer on superuser to be anything else than a "Nope. Not possible. No OS, no SO.", while an answer detailing how to programmatically achieve it is conceivable here. OP talks about a custom ELF loader so he supposedly knows what's he's dealing with..Infeudation
@powerlord - no, it is a simple yes/no question - can the existing codebase support this, or do they need to build their own solution from scratch.Hokkaido
I
20

So, you don't make it crystal clear what you are trying to do, but:

Loading a userspace (assuming Linux SysV ELF type) shared library straight into GRUB is not possible. GRUB modules are indeed in ELF format, but they contain additional headers. Among the information contained in that header is an explicit license statement - GRUB will refuse to load any modules that are not explicitly GPLv2+, GPLv3 or GPLv3+.

It should be possible to write an ELF loader, but an easier way might be to write a tool to convert a userspace library to a GRUB module. There would of course be several restrictions here:

  • You would need to ensure the userspace library performed no system calls - GRUB would have nothing in place to handle them.
  • You would need to abide by the licensing rules (so only above three licenses would be acceptable).
  • You would need to ensure these libraries were not dependent on a global offset table being set up by glibc for them.

If recompiling is an option, GRUB also provides a POSIX emulation layer - add CPPFLAGS_POSIX to your CPPFLAGS, and use core standard POSIX header files. Have a look at the gcrypt support for an example.

Imbrue answered 25/8, 2014 at 18:26 Comment(2)
Oh, that's interesting (the additional headers). I'm glad you got the question re-opened so you could post that information.Tourism
Thanks @unixsmurf, your answer is really helpful. I'll update my question soon with some experiment based on your ideas. Thank you again.Communize

© 2022 - 2024 — McMap. All rights reserved.