HxHippy

FreeBSD Boot Process

Understanding the FreeBSD boot process and boot loader configuration.

Last updated: 2025-01-15

Boot Stages

Stage 1: BIOS/UEFI

Hardware initialization, finds bootable device.

Stage 2: Boot Loader

GPT Boot:
  - gptboot or gptzfsboot
  - Loads /boot/loader

MBR Boot:
  - boot0 -> boot1 -> boot2
  - Loads /boot/loader

Stage 3: Loader

# /boot/loader loads:
# - Kernel modules
# - Kernel configuration
# - Eventually transfers control to kernel

Stage 4: Kernel

# Kernel initializes:
# - Hardware detection
# - Root filesystem mount
# - Starts /sbin/init (PID 1)

Stage 5: Init

# /sbin/init runs:
# - /etc/rc scripts
# - Services from rc.conf
# - Login prompts

Loader Configuration

# /boot/loader.conf

# Load ZFS module early
zfs_load="YES"

# Kernel tuning
kern.maxfiles="200000"
kern.ipc.shmmax="1073741824"

# Console settings
kern.vty=vt
autoboot_delay="3"

# Hardware settings
hw.usb.no_boot_wait="1"

Boot Environments (ZFS)

# List boot environments
bectl list

# Create boot environment
bectl create pre-upgrade

# Activate boot environment
bectl activate pre-upgrade

# Boot menu shows boot environments

Boot Problems

Single User Mode

# At loader prompt:
boot -s

# Or select "Single User Mode" from boot menu

Boot Specific Kernel

# At loader prompt:
boot kernel.old

# Or:
set kernel="kernel.old"
boot

Fix Corrupted Boot

# Boot from USB
# Mount root partition
mount /dev/ada0p2 /mnt

# Reinstall boot code
gpart bootcode -b /mnt/boot/pmbr -p /mnt/boot/gptboot -i 1 ada0
intermediate System Administration Updated 2025-01-15
  • freebsd
  • boot
  • loader
  • bios
  • uefi