# binfmt_misc: How 2 stop automatic load @kernel boot?[solved]

## CaptainBlood

binfmt_misc set as module here.

I guess the question sounds silly to many.

Still kernel boot automatically loads it.

Since qemu is only very occasionally used here and requires a little command sequence, it would be preferable to avoid such a default loading.

Can't figure how to manage it...  :Sad:  Any idea?

Thks 4 ur attention, interest & support.Last edited by CaptainBlood on Tue Mar 03, 2020 6:38 am; edited 1 time in total

----------

## Ionen

Assuming openrc (I'd bet systemd does something similar), it's likely the /etc/init.d/procfs script:

```
start()

{

        # Setup Kernel Support for miscellaneous Binary Formats

        if [ -d /proc/sys/fs/binfmt_misc ] &&

                [ ! -e /proc/sys/fs/binfmt_misc/register ]; then

                if ! grep -qs binfmt_misc /proc/filesystems &&

                        modprobe -q binfmt-misc; then
```

Could always remove the section with a openrc patch (Edit: although seems need more setting up than just auto-loading the module, notably a mount point, so it's technically needed if ever used). Personally never use binfmt_misc and prefer to use full commands or wrappers/alias, so I don't even have it as a module.Last edited by Ionen on Mon Mar 02, 2020 10:57 am; edited 1 time in total

----------

## CaptainBlood

 *Ionen wrote:*   

> Personally never use binfmt_misc and prefer to use full commands or wrappers/alias, so I don't even have it as a module.

 Here's openrc.

Maybe I should try to follow that path, if applicable to qemu used for an architecture # to host's.

Thks 4 ur attention, interest & support.

----------

## krinn

You shouldn't patch procfs, it will be lost after an update

Go with openrc strengh it's better, and you could conditionaly load it, in my example, if kernel have some "qemu" name in it, it continue trying to load the modules, else it just stop ; upto you to have an entry with a kernel name with some "qemu" in it to use qemu and another entry without that keyword

create this in /etc/conf.d/procfs

```
procfs_start=

{

   if [[ "$(uname -a)" != *"qemu"* ]]; then

      return 0

      fi

   # Setup Kernel Support for miscellaneous Binary Formats

   if [ -d /proc/sys/fs/binfmt_misc ] &&

      [ ! -e /proc/sys/fs/binfmt_misc/register ]; then

      if ! grep -qs binfmt_misc /proc/filesystems &&

         modprobe -q binfmt-misc; then

         ewarn "The binfmt-misc module needs to be loaded by" \

            "the modules service or built in."

      fi

      if grep -qs binfmt_misc /proc/filesystems; then

         ebegin "Mounting misc binary format filesystem"

         mount -t binfmt_misc -o nodev,noexec,nosuid \

            binfmt_misc /proc/sys/fs/binfmt_misc

            eend $?

      fi

   fi

   return 0

}
```

----------

## CaptainBlood

Very interesting.

I see your script loads binfmt-misc module under specified conditions.

Lonen refers to /etc/init.d/procfs which is declared in rc-update scripts list.

Should I remove it from rc-update, does your script inihibits /etc/init.d/procfs or should your script be adapted to unload bindmt-misc module?

Thks 4 ur attention, interest & support.

----------

## Ionen

 *krinn wrote:*   

> You shouldn't patch procfs, it will be lost after an update

 By patch, I meant a patch to openrc rather than procfs, aka a /etc/portage/patches/ which isn't lost with updates. I find it simpler if it's just to change one line or similar rather than have a copy of the whole function in conf.d. Patch failure is also a nice reminder that you should probably check/update rather than changes going unnoticed and your conf.d function staying outdated.

That aside, conf.d is a nice solution if you just don't like using patches (or can't, like on a binary gentoo).

----------

## CaptainBlood

I'm used to /etc/portage/patches/xxx so that path shouldn't be an issue.

I'm wondering still how /etc/init.d/procfs got installed in rc-update script list.

I'm relunctant to remove it as I have no emergency media to set it back should it brakes (silly me).

Thks 4 ur attention, interest & support.Last edited by CaptainBlood on Mon Mar 02, 2020 9:24 pm; edited 1 time in total

----------

## Ionen

I actually was under the impression that script was doing more things given it says "misc filesystemS" (I didn't look beyond the modprobe line   :Laughing: ). I guess it may be a placeholder to do more things if ever needed.

If that's all it does, you could turn it off (I feel like I should remove it too, does nothing for me). Although you'll need to start it to mount /proc/sys/fs/binfmt_misc normally if you ever want to use binfmt_misc.

----------

## CaptainBlood

 *Ionen wrote:*   

> (I didn't look beyond the modprobe line  )

 I indeed didn't, and feel quite ashamed about it.

It indeed doesn't do anything more that what you reported.

Currently building an emergency USB key though (easy2boot here).

Will only try to remove once validated precaution measures have been taken.

My best to all of you, as I feel great having linux talks somehow beyond 'couldn't emerge package xxxx' stanza.

Plz note I'm not blaming those as such, as I did my share there for the last a decade now.

Becoming a little more mature though with the help of guys such as you.

Thks 4 ur attention, interest & support.

----------

## CaptainBlood

Removed from rc-update list scripts.

Fine boot here.

Thks 4 ur attention, interest & support

----------

## krinn

it was more an example of openrc strengh rather than simply disabling procfs ; for the beauty  :Smile: 

----------

