Windows deleted my bootloader, HELP

So windows decided to destroy everything, lovely as ever. Fine, I thought, just plop a nixos live image and I am set.(note, i downloaded the latest image from nixos.org and have on my own system nixos 24.11) Well, I used nixos-enter, tried nix-collect-garbage -d, followed by

nix-store --verify --check-contents --repair

, followed by followed by a rebuild (nixos-rebuild boot --install-bootloader
), only to be met with


error: builder for '/nix/store/rmlwdsjyvk4l654jdy5ymc5dz46sffm2-logrotate.conf.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/ccz734disd4hispzx3dc0f6k2fv5bf7d-unit-logrotate-checkconf.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/3l68c0191sl8a9c6l13pc3h1s7fjhqjh-system-units.drv' failed to build
copying path '/nix/store/pkpi889x3rvyxcrqsii926nsc6ln27lw-perl5.40.0-CGI-4.59' from 'https://cache.nixos.org'...
copying path '/nix/store/90zvvvrx43i07iwza86pvvl94nygxf2n-protobuf-28.2' from 'https://cache.nixos.org'...
copying path '/nix/store/l40sfbn1hzlbn5cqn6vz49zwvmn3is08-publicsuffix-list-0-unstable-2024-09-10' from 'https://cache.nixos.org'...
copying path '/nix/store/fndm6qgyyc0sdg2ca30vz8bqjv484xxq-qttranslations-5.15.15' from 'https://cache.nixos.org'...
copying path '/nix/store/wv9yil24n76q102qwfqjrn735ra7158d-python3-minimal-3.12.6' from 'https://cache.nixos.org'...
error: 1 dependencies of derivation '/nix/store/y7s33sg7d7xan505sjdxkh9c960407ph-etc.drv' failed to build
copying path '/nix/store/2gndrfl95bk3phkfzds0zdy1jbnfqd35-raptor2-2.0.16' from 'https://cache.nixos.org'...
copying path '/nix/store/5vhbskin0qzg24jnbk6nhmj3wfx081g7-qttranslations-6.8.0' from 'https://cache.nixos.org'...
error: 1 dependencies of derivation '/nix/store/mgnqljii9cvnck6ikqiw5634dskni890-nixos-system-nixos-24.11pre696981.18536bf04cd7.drv' failed to build

updates: i removed lxqt and xfce from my config, errors are now as follows:


copying path '/nix/store/6xq91p4jidpp8b416k85anzfs108brg0-poppler-utils-24.02.0' from 'https://cache.nixos.org'...
building '/nix/store/rmlwdsjyvk4l654jdy5ymc5dz46sffm2-logrotate.conf.drv'...
/nix/store/ph44jcx3ddmlwh394mh1wb7f1qigxqb1-coreutils-9.5/bin/id: cannot find name for group ID 30000
error: builder for '/nix/store/rmlwdsjyvk4l654jdy5ymc5dz46sffm2-logrotate.conf.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/ccz734disd4hispzx3dc0f6k2fv5bf7d-unit-logrotate-checkconf.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/2yq275610s3ys8qcrdrx5i8avyvzzyi0-system-units.drv' failed to build
copying path '/nix/store/32cprs7xwxvb0rw2imfrgy5vcacc27hc-postgresql-16.4-lib' from 'https://cache.nixos.org'...
copying path '/nix/store/9297y6r4z4z3dckq9b0binfrqsnmj0wy-ppp-2.5.0' from 'https://cache.nixos.org'...
error: 1 dependencies of derivation '/nix/store/kyvl4cs1cdwq8rvzn11bjlidss5a4a3n-etc.drv' failed to build
copying path '/nix/store/kw3a8n8qyjasipmdzg22jazg8wd4sxxm-procps-3.3.17' from 'https://cache.nixos.org'...
copying path '/nix/store/zxw03ch0129vy3ir7yra1wmcz5083ip3-procmail-3.24' from 'https://cache.nixos.org'...
copying path '/nix/store/885i5109qp7whqkhp8alwhja2f1fmk8d-proggyfonts-0.1' from 'https://cache.nixos.org'...
error: 1 dependencies of derivation '/nix/store/6xrn1qzw1x149dd96ni7pys4hccds54s-nixos-system-nixos-24.11pre696981.18536bf04cd7.drv' failed to build

update: after following this post error is now as follows


Checking runtime dependencies for opentelemetry_proto-1.26.0-py3-none-any.whl
  - protobuf<5.0,>=3.19 not satisfied by version 5.28.2
error: builder for '/nix/store/bq0872szxnxhfyrj2aracprxk61c7wp7-python3.12-opentelemetry-proto-1.26.0.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/bpsi6bjzj2hin0j457xb23b1400rpsnp-python3.12-opentelemetry-exporter-otlp-proto-grpc-1.26.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/6cl8q6qhi20ca5g4b1ahvn34sz48498a-python3.12-chromadb-0.5.11.drv' failed to build
copying path '/nix/store/vg9c05lif87mdg2dqp6jx3b21bl2p4jl-xavs-55' from 'https://cache.nixos.org'...
error: 1 dependencies of derivation '/nix/store/kfz6w8n92q59nri0vgmxsflifds0i1ll-open-webui-0.3.32.drv' failed to build
copying path '/nix/store/rbhihn3pbrf3jda2h355r129z5b7p3di-xbitmaps-1.1.3' from 'https://cache.nixos.org'...
copying path '/nix/store/k649nr65djgqisxs4z9rizc7n3z0jnib-xcb-util-0.4.1' from 'https://cache.nixos.org'...
copying path '/nix/store/alpq25n8lzjm82lmnkmq60aywly282iz-xcb-util-keysyms-0.4.1' from 'https://cache.nixos.org'...
error: 1 dependencies of derivation '/nix/store/vskkq63104h3pbbjsl2l86phgfyx2jk4-user-environment.drv' failed to build
copying path '/nix/store/pkasyi6bhq5mfj8500qlslgki83w6xgi-xcb-util-renderutil-0.3.10' from 'https://cache.nixos.org'...
error: 1 dependencies of derivation '/nix/store/76s3ma3nk5dpfn16mvkm2k1mpzi1853z-etc.drv' failed to build
copying path '/nix/store/f333qv7qwkvqgy11d9vn32hxniww59al-xcb-util-wm-0.4.2' from 'https://cache.nixos.org'...
copying path '/nix/store/pkfvd6k2kr2k1v164fdr68xq7qklv6ki-xdg-dbus-proxy-0.1.6' from 'https://cache.nixos.org'...
error: 1 dependencies of derivation '/nix/store/idjjp1sc8smnqdvxvvmdipvc71ndd54i-nixos-system-nixos-24.11pre696981.18536bf04cd7.drv' failed to build

update:after removing a few more problematic packages :



[root@nixos:/]# nixos-rebuild boot --install-bootloader 
building Nix...
building the system configuration...
evaluation warning: mdadm: Neither MAILADDR nor PROGRAM has been set. This will cause the `mdmon` service to crash.
these 3 derivations will be built:
  /nix/store/b4nb699sigx1bj31dpnpcbgm0y0ggjzg-user-environment.drv
  /nix/store/7cd6wxykcnvr4gwx37q859cx3dv8gw8p-etc.drv
  /nix/store/75y9d423yi871jfjlgg31lmjr265fc16-nixos-system-nixos-24.11pre696981.18536bf04cd7.drv
building '/nix/store/b4nb699sigx1bj31dpnpcbgm0y0ggjzg-user-environment.drv'...
created 4784 symlinks in user environment
gtk-update-icon-cache: Cache file created successfully.
building '/nix/store/7cd6wxykcnvr4gwx37q859cx3dv8gw8p-etc.drv'...
building '/nix/store/75y9d423yi871jfjlgg31lmjr265fc16-nixos-system-nixos-24.11pre696981.18536bf04cd7.drv'...
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to system scope bus via local transport: Host is down
efiSysMountPoint = '/boot' is not a mounted partition. Is the path configured correctly?
Traceback (most recent call last):
  File "/nix/store/d8vipqpqkyin5k80fmbygi3289j1z97h-systemd-boot/bin/systemd-boot", line 435, in <module>
    main()
  File "/nix/store/d8vipqpqkyin5k80fmbygi3289j1z97h-systemd-boot/bin/systemd-boot", line 415, in main
    run([CHECK_MOUNTPOINTS])
  File "/nix/store/d8vipqpqkyin5k80fmbygi3289j1z97h-systemd-boot/bin/systemd-boot", line 58, in run
    return subprocess.run(cmd, check=True, text=True, stdout=stdout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/wfbjq35kxs6x83c3ncpfxdyl5gbhdx4h-python3-3.12.6/lib/python3.12/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/nix/store/i3ld9qzipgdhc36ndq7p1pv5yybydcwg-check-mountpoints']' returned non-zero exit status 1.
Failed to install bootloader
warning: error(s) occurred while switching to the new configuration
[ble: exit 1]

You probably forgot to mount the boot partition into the correct place for nixos-enter. Follow the mount instructions here: NixOS Manual

You might also want to double check your channels. You probably don’t have the same channel versions as in the booted system, otherwise you wouldn’t be seeing these errors.

Your nix store repair and gc shenanigans isn’t necessary, either, and potentially harmful, since you’re not in a system with the correct garbage collection roots, which might be what prompted those builds.

I actually think nixos-install has a flag to just install the bootloader which would have been enough here. But yeah, your system is likely unbootable now, you’ll have to figure out how to fix it from within the chroot.

4 Likes

To repair the boot loader there is indeed a command to just reinstall the bootloader:


Bootloader broken or Entry gone:
  1. Boot from installation media Nixos
  2. mount /dev/[root partition] /mnt
  3. mount /dev/[boot partition] /mnt/boot
  4. sudo nixos-enter
  5. NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system/bin/switch-to-configuration boot
  6. reboot into Bios 
3 Likes

FWIW, I wouldn’t call this user error (up until where you decided to wipe the nix store for some reason), this should probably be somewhere prominent in the NixOS manual. Windows likes deleting other bootloaders, so this is unlikely to be a rare scenario.

1 Like

Completely right. I needed it many times but not because windows deleted my bootloader but rather my bootloader got corrupted after a Bios Update three times. But this solution to reinstall the bootloader I only found after some digging in the forums. So adding a instruction how to repair the bootloader in the wiki should be necessary.

1 Like

FWIW I was not able to get NIXOS_INSTALL_BOOTLOADER to work on my system (EDIT: as in it runs without error, but doesn’t update EFI vars), so this may be a fallback solution:

Though it won’t work in this case as mentioned, since the store was blown out and the bootloader entries will therefore point to nonexistent paths.

I wish there was some way to warn/remind users that gc is not a standard troubleshooting step. People seem to think of it like clearing a browser cache or something.

1 Like

That is strange. Just ran the command on my system and it worked just fine.
However I if the store is “blown up” this most likely will not work.
But could you try to repair the nix store:

sudo nix-store --verify --check-contents --repair

OP already ran this command, but it’s not related to their error.

1 Like

Thanks everyone for your help, I feel kind of silly for not remembering to mount the partitions, but it is now solved (am writing this from my NIXOS installed) :slight_smile:

2 Likes

To be clear, this command will only do anything if files in the nix store have become “corrupted”, i.e., if the file contents have changed to be different from what nix expects them to be.

If a store path has been deleted because of an unwise garbage collect, it will do absolutely nothing because the store entry no longer exists, so there are no contents to check.

All files in the nix store are read-only, so this can only happen due to nix bugs, kernel bugs, file system bugs, file system failure… Basically, if the command does anything something has gone catastrophically wrong; only changes not intended by nix will be solved by this. It will also only touch files in /nix/store, so will not do anything to a broken boot partition, or stuff in your home directory. You should almost never run it, though at least it isn’t destructive.

For the record, in about 8 years of using nix I have never seen that command do anything on my systems. Files don’t typically just become corrupted - though I do know of 2 cases where it did resolve mystery bugs if you consider all the folks I’ve helped in the forums.

A “garbage collect” OTOH will simply remove files from the nix store which aren’t currently used by anything. This is necessary because - unlike other package managers - nix doesn’t actually overwrite old versions of packages, it just creates a new nix store entry and then “switches” what version is exposed in e.g. $PATH. The old files remain in place. This is half the reason NixOS is so cool - if something doesn’t work after an update, you can easily switch back - unless you garbage collected the old state.

A garbage collect should really only be done when you are in a sane state, and need to clear up disk space. Deleting old files is only ever going to hurt you if there is any chance that you might need to recover an old generation or such, and kind of defies the purpose of the distro.

4 Likes