Wednesday, May 14, 2025

How to boot FreeBSD into Single User Mode

When something went wrong, it is good to boot into single user mode (without the user/root authorization) and do some maintenance tasks.

Boot in to a single user mode

First of all, you must have access to FreeBSD console to manage boot process, because you have to somehowe initiated reboot of the system. When you have access to console keyboard, simply press CTRL+ALT+DEL. Another option is hardware reset or power-ofF & power-on, but this is not a graceful reboot and you can damage something.

During the boot sequence, there is "Bestie boot menu" where you can simply select option 2 by pressing key 2.

Bestie boot menu

Change read-only filesystem to read-write

When FreeBSD is booted into a single user mode, the file system is in read-only mode for safety.

When you want to change someting in file system or even change root or user password, you have to remount file system from read-only mode into read-write mode. 

For UFS

Below is the sequence of commands to do so if you have UFS file system.

mount -u / 
mount -a

Command (mount -u /) remounts the root filesystem (/) using the options specified (or defaults from /etc/fstab), without unmounting it.

Command (mount -a) mounts the rest of the filesystems defined in /etc/fstab.

For ZFS

Below is the sequence of commands for ZFS file system.

zfs set readonly=off zroot/ROOT/default
zfs mount -a
 
Commands above are self explanatory.

Work in a single user mode

Now you can do a troubleshooting or fixing some problems in single user operating system, where nobody else can login into the system and noone will interfere with you.

Alternative to single user mode

You can boot your system from FreeBSD boot media (ISO, USB Stick, etc.) into a recovery mode. It is essentialy running system from Live CD/USB disk. In such mode you have to mount disk filesystems by yourself to have read/write access to it.

No comments:

Post a Comment