How to fix a (slightly) broken root filesystem on NixOS VM image

I’m currently running NixOS inside a VM and I’m getting this error on booting up:

nixos: Inodes that were part of a corrupted orphan linked list found.
nixos: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
(i.e., without -a or -p options)
/dev/disk/by-label/nixos has unrepaired errors, please fix them manually.

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

If I ignore the error, the system happily boots without issue, and besides this message popping up every boot, nothing seems amiss, although running on a notionally broken filesystem concerns me.

If I press r, I just get back to the same spot.

I’ve tried a few things:

  1. Add single to the linux line in GRUB on boot. This gives me a single user prompt, but / is still mounted rw. Hence I can’t run fsck on it.
  2. Instead, add fsck.mode=force fsck.repair=yes to the linux in GRUB on boot. This seems to do nothing.

So is there anyway other a rescue disk to get fsck running on my root partition?

I note that there is no /etc/nixos/hardware-configuration.nix that exists. I don’t know if this is a peculiarity of VM based nix, or something more normal. Also everything is stored in the / partition, the disk isn’t partitioned in any other way.

How about just repairing it from the outside?

https://news.numlock.ch/it/how-to-check-filesystems-in-a-qcow2-image

I’m running this VM on Windows in VirtualBox, is there a Windows host version of your suggestion?

I’m not sure how to do that from a windows host. But instead, you can do it from the VM two ways.

  1. From the boot loader, you can press e to edit the kernel cmdline and add boot.shell_on_fail, which will put you into a shell and let you fix the disk with fsck.
  2. You can boot the live CD ISO on the VM and fix the disk from there.