Skip to main content

Fixing root filesystem errors with fsck on NixOS

If you run into an error like this:

An error occurred in stage 1 of the boot process, which must mount the root filesystem on `/mnt-root` and then start stage 2. Press one of the following keys:

r) to reboot immediately
*) to ignore the error and continue

Then you can fix it like this:

  1. Boot into a live CD/DVD for NixOS, or some other environment that has fsck installed, but not your installed copy of NixOS (as that will mount the root filesystem) (source)
  2. Run fsck -yf /dev/sda1 where you replace /dev/sda1 with your root filesystem. (source)
    • If you're on a (KVM) VPS, it'll probably be /dev/vda1. If you're using LVM (even on a VPS), then you need to specify your logical volume instead (eg. /dev/vg_main/lv_root, but it depends on what you've named it).

The above command will automatically agree to whatever suggestion fsck makes. This can technically lead to data loss!

Many distributions will give you an option to drop down into a shell from the error directly, but NixOS does not do that. In theory you could add the boot.shell_on_fail flag to the boot options for your existing installation, but for reasons that I didn't bother debugging any further, the installed fsck was unable to fix the issues.