Nixos stage-1-init: An error occurred in stage 1 of the boot process

After executing the command $ sudo nixos-rebuild switch --upgrade , I encounter the following error.

$ journalctl -b | grep stage
Mar 02 21:26:09 nixos stage-1-init: [Thu Mar  2 13:25:28 UTC 2023] loading module vboxsf...
Mar 02 21:26:09 nixos stage-1-init: [Thu Mar  2 13:25:28 UTC 2023] modprobe: ERROR: could not insert 'vboxsf': No such device
Mar 02 21:26:09 nixos stage-1-init: [Thu Mar  2 13:25:28 UTC 2023] loading module dm_mod...
Mar 02 21:26:09 nixos stage-1-init: [Thu Mar  2 13:25:28 UTC 2023] running udev...
Mar 02 21:26:09 nixos stage-1-init: [Thu Mar  2 13:25:28 UTC 2023] Starting version 251.11
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:30 UTC 2023] starting device mapper and LVM...
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:30 UTC 2023] checking /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3...
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:30 UTC 2023] fsck (busybox 1.35.0)
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:30 UTC 2023] [fsck.ext4 (1) -- /mnt-root/] fsck.ext4 -a /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:30 UTC 2023] /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3: recovering journal
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:30 UTC 2023] /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3 contains a file system with errors, check forced.
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:30 UTC 2023] /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3: Inode 2892933 extent tree (at level 1) could be shorter.  IGNORED.
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:30 UTC 2023] /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3: Deleted inode 2894055 has zero dtime.  FIXED.
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:30 UTC 2023] /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3: Inode 2905877 extent tree (at level 1) could be shorter.  IGNORED.
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:30 UTC 2023] /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3: Inode 3145871 extent tree (at level 1) could be narrower.  IGNORED.
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:30 UTC 2023] /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3: Inode 3145891 extent tree (at level 1) could be shorter.  IGNORED.
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:35 UTC 2023] /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3: Inode 16123953 extent tree could be more shallow (51712; could be <= 4)
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:35 UTC 2023] IGNORED.
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:35 UTC 2023] /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3: Inode 16123953 has an invalid extent
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:35 UTC 2023] (logical block 905969664, invalid physical block 259480449187841, len 3389595649)
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:35 UTC 2023] /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:35 UTC 2023] (i.e., without -a or -p options)
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:35 UTC 2023] /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3 has unrepaired errors, please fix them manually.
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:35 UTC 2023] An error occurred in stage 1 of the boot process, which must mount the
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:35 UTC 2023] root filesystem on `/mnt-root' and then start stage 2.  Press one
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:35 UTC 2023] of the following keys:
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:35 UTC 2023] r) to reboot immediately
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:25:35 UTC 2023] *) to ignore the error and continue
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:26:09 UTC 2023] Continuing...
Mar 02 21:26:10 nixos stage-1-init: [Thu Mar  2 13:26:09 UTC 2023] mounting /dev/disk/by-uuid/9e13020e-8b97-4c68-8f3c-fc66c6e26db3 on /...
Mar 02 21:26:10 nixos stage-2-init: running activation script...
Mar 02 21:26:10 nixos stage-2-init: removing group ‘docker’
Mar 02 21:26:10 nixos stage-2-init: setting up /etc...
$ sudo su
# fdisk -l
Disk /dev/nvme0n1: 953.87 GiB, 1024209543168 bytes, 2000409264 sectors
Disk model: ADATA SX8200PNP
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: AFFCCDE1-9F4C-4ACF-9A47-1EBEDAB80094

Device              Start        End    Sectors   Size Type
/dev/nvme0n1p1       2048     206847     204800   100M EFI System
/dev/nvme0n1p2     206848     239615      32768    16M Microsoft reserved
/dev/nvme0n1p3     239616 1095193207 1094953592 522.1G Microsoft basic data
/dev/nvme0n1p4 1999081472 2000404479    1323008   646M Windows recovery environment
/dev/nvme0n1p5 1095194624 1999081471  903886848   431G Linux filesystem

Partition table entries are not in disk order.


Disk /dev/nvme1n1: 953.87 GiB, 1024209543168 bytes, 2000409264 sectors
Disk model: ADATA SX8200PNP
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: A0485444-A3A4-4028-82A0-9C18BDB26994

Device         Start        End    Sectors   Size Type
/dev/nvme1n1p1  2048 2000408575 2000406528 953.9G Linux filesystem

I guess I need to fsck to /dev/nvme0n1p5 but I can’t umount /nix/store

# fsck -f /dev/nvme0n1p5
fsck from util-linux 2.38.1
e2fsck 1.46.5 (30-Dec-2021)
/dev/nvme0n1p5 is mounted.
e2fsck: Cannot continue, aborting.
# umount /dev/nvme0n1p5
umount: /nix/store: target is busy.

Any idea or approach to help me for fixing the issue? Thanks for reading

Can you boot to another root filesystem such as installation media, netboot, or possibly on /dev/nvme1n1p1?

The basic problem is that all executables live in /nix/store. If that is the filesystem needing repair, you need to run everything from a different filesystem. Usually your installation media is the easiest way to accomplish that.

Thank you for your hit!

I boot from USB NixOS Installer and execute # fsck /dev/nvme0n1p5 to fix the issue.

Thank you!