On Monday, February 13, 2017 at 10:35:39 AM UTC-8, Simon Perfer wrote: > > Thank you Zlatko. > > > I actually have no idea how to call init_module() from my Go program. > Happy to do the legwork in figuring this out, but not even sure where to > start. > Is there something I should Google to get my search started? What are the > keywords I should look up to begin this process? >
Take a look at how the syscall package actually invokes a Linux syscall (https://golang.org/pkg/syscall/#Syscall). The syscall package appears to already define a constant "SYS_INIT_MODULE" with the appropriate syscall number for each supported platform, so in theory something like "syscall.Syscall(syscall.SYS_INIT_MODULE, <args>)" is all you need to do. Would calling this function preclude me from compiling a static binary? > Not if you do it via the syscall package. > ------------------------------ > *From:* golan...@googlegroups.com <javascript:> <golan...@googlegroups.com > <javascript:>> on behalf of Zlatko Čalušić <zcal...@bitsync.net > <javascript:>> > *Sent:* Monday, February 13, 2017 1:06:54 PM > *To:* golan...@googlegroups.com <javascript:> > *Subject:* Re: [go-nuts] two questions > > On 13.02.2017 17:50, Simon Perfer wrote: > > I've been working on a pet science project: building an initramfs with > only one file. Specifically, an executable written in Go. > > > The only thing I can't figure out is how to do a "modprobe" in Go without > actually having the modprobe utility. Is there a libkmod library available? > If > not, how would I go about creating a wrapper for the libkmod library? > Never done this before. > > > Finally, if I'm relying on C libraries like libkmod does this preclude me > from creating a statically-compiled binary? Goal being, again, that I am > creating an initramfs with only a single file: the compiled Go binary. > > > Thanks! > > > Hello Simon, > > that definitely looks like a nice project. I like simplicity. Do share > when you feel ready. > > I straced modprobe, and behind the scenes it just calls init_module(). So, > it should be pretty simple to call from Go. > > NAME > init_module, finit_module - load a kernel module > > DESCRIPTION > init_module() loads an ELF image into kernel space, performs > any necessary symbol > relocations, initializes module parameters to values provided by > the caller, and then > runs the module's init function. This system call requires > privilege. > > Hope it helps! > > -- > Zlatko > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts...@googlegroups.com <javascript:>. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.