Solved Boot without loading kernel modules

I installed a kernel module, which causes error while booting. Is there a way to boot without loading kernel modules, so I can remove it?
 
Boot single user (it's in the boot menu), start the standard shell, set your root fs to rw (depends on which fs you use) and edit /etc/rc.conf
 
If it's a kernel module loaded through loader.conf that's causing panics you won't be able to boot to single user mode either.

Drop to the loader prompt. Then unload the kernel and run boot /boot/kernel/kernel -s (the -s will cause it to boot to single user mode). The boot command will only load the kernel, no additional modules. In single user mode you can modify your loader.conf and remove the offending kernel module. Then just reboot.

Code:
     boot
     boot kernelname [...]
     boot -flag ...
             Immediately proceeds to bootstrap the system, loading the kernel
             if necessary.  Any flags or arguments are passed to the kernel,
             but they must precede the kernel name, if a kernel name is
             provided.

             WARNING: The behavior of this builtin is changed if loader.4th(8)
             is loaded.

...
     unload  Remove all modules from memory.
From loader(8).
 
If it's a kernel module loaded through loader.conf that's causing panics you won't be able to boot to single user mode either.

Drop to the loader prompt. Then unload the kernel and run boot /boot/kernel/kernel -s (the -s will cause it to boot to single user mode). The boot command will only load the kernel, no additional modules. In single user mode you can modify your loader.conf and remove the offending kernel module. Then just reboot.

Code:
     boot
     boot kernelname [...]
     boot -flag ...
             Immediately proceeds to bootstrap the system, loading the kernel
             if necessary.  Any flags or arguments are passed to the kernel,
             but they must precede the kernel name, if a kernel name is
             provided.

             WARNING: The behavior of this builtin is changed if loader.4th(8)
             is loaded.

...
     unload  Remove all modules from memory.
From loader(8).
I used sysrc kld_list+="amdgpu" to add it. I think it adds to the loader.conf as you wrote. I booted, but now I got something called mountroot> I have no idea how to mount the root file system manually. It is ZFS, but if I write the zfs:zroot/ROOT/default from the examples, it does not work.
 
Boot single user (it's in the boot menu), start the standard shell, set your root fs to rw (depends on which fs you use) and edit /etc/rc.conf
Looks like it boots in single user mode and it is in the rc.conf. Thanks!
 
Boot single user (it's in the boot menu), start the standard shell, set your root fs to rw (depends on which fs you use) and edit /etc/rc.conf
I cannot remount it in rw, I tried mount -o rw,remount / but it writes that unknown special file or filesystem.
 
It works now with mount -o rw,remount zfs:zroot/ROOT/default
The remount option doesn't exist on FreeBSD, that's a Linux mount option. Besides that, this is not how ZFS filesystems are mounted. It's zfs set readonly=off zroot/ROOT/default. If there are other ZFS filesystems that need to be mounted (in single user mode only the root filesystem is mounted); zfs mount -a
 
The remount option doesn't exist on FreeBSD, that's a Linux mount option. Besides that, this is not how ZFS filesystems are mounted. It's zfs set readonly=off zroot/ROOT/default. If there are other ZFS filesystems that need mounted (in single user mode only the root filesystem is mounted); zfs mount -a
Still it worked somehow.
 
The remount option doesn't exist on FreeBSD, that's a Linux mount option. Besides that, this is not how ZFS filesystems are mounted. It's zfs set readonly=off zroot/ROOT/default. If there are other ZFS filesystems that need to be mounted (in single user mode only the root filesystem is mounted); zfs mount -a
I run into this again and now it did not work. As if "mount" would not recognize ZFS. I had the same when I booted with "boot /boot/kernel/kernel -s" and tried to mount it. Now I realize that in that case ZFS kernel module was not loaded and that's why it failed to mount root. In this case I booted single user mode from the boot menu and it wrote the same. The system was slightly different 12.2-RELEASE in this time and 12.2-STABLE the previous time when mount worked. The "zfs set readonly=off zroot/ROOT/default" you suggested worked just fine. :)
 
Just for the record, here's how to blacklist a FreeBSD kernel module at boot from the bootloader prompt. This works for me on FreeBSD 14 and x86_64.
  1. Get to the bootloader screen. This may require entering your GELI password if you’re using that kind of encryption.
  2. Once in the bootloader countdown screen, select 3, Escape to loader prompt. (At this point you might (?) need to have loader.4th loaded, but this seems to happen by default. At least I didn’t have to do anything in that regard.)
  3. In the loader prompt, type show. This will produce a list of variables.
  4. Keep paging until you spot a variable called module_blacklist. Quit the pager right there, so that you have a reference.
  5. Append the module(s) you want to blacklist to the variable using the set command (i.e., re-type the original value and append the extra modules). For instance, if I wanted to blacklist nvidia and nvidia-modeset, I’d use set like this:
    Code:
    set module_blacklist='some previously present modules nvidia nvidia-modeset'
  6. Then just boot using the boot command (wihtout any arguments).
  7. Once you’re in a running system, edit /boot/loader.conf to prevent whatever was causing trouble from loading again. (You can also uninstall the module if it’s in a package.)
Perhaps a simpler alternative would be to edit /boot/loader.conf on another system. But that might be complicated (e.g. with certain VM disk setups or on bare metal or if you dream about opening GELI on Linux).
 
It works now with mount -o rw,remount zfs:zroot/ROOT/default
For the future reference (man mount):
Code:
 -u      The -u flag indicates that the status of an already mounted file            
             system should be changed.  Any of the options discussed above               
             (the -o option) may be changed; also a file system can be changed           
             from read-only to read-write or vice versa.  An attempt to change           
             from read-write to read-only will fail if any files on the file             
             system are currently open for writing unless the -f flag is also            
             specified.  The set of options is determined by applying the                
             options specified in the argument to -o and finally applying the            
             -r or -w option.
So it's simply mount -uw $filesystem to make it rw and mount -ur $filesystem to make it ro.
 
Another thing to remember is ZFS Boot Environments. /boot should be part of the root data set, so boot into a BE that is not broken, then use bectl to mount the broken root dataset and edit loader.conf.
ZFS BE's have saved me more than once or twice, so use them.
All the above advice about how to do things in the loader are worth printing out and taping to the wall so you can find it easily.
 
When in single user mode. I use mount -fuo rw /
Why not. Just in some situations it will tell you something like "mount: the system is busy".
While mount -uw/-ur will just do it. Because it doesn't "remount", it changes the status "of an already mounted file system".
 
Back
Top