Skip to content

Instantly share code, notes, and snippets.

@sacsbrainz
Last active December 13, 2023 20:24
Show Gist options
  • Save sacsbrainz/104fa5f35477da11703b7d154a406703 to your computer and use it in GitHub Desktop.
Save sacsbrainz/104fa5f35477da11703b7d154a406703 to your computer and use it in GitHub Desktop.
fix no bootable device error in nixos

Prerequisite

insert a nixos bootable drive

run this command to get list of drives

lsblk

enter sudo mode

sudo -i

mount the bad drive in my case nvme0n1pe2 is the main partition and nvme0n1pe1 is the boot partition

mount /dev/nvme0n1p2 /mnt

mount /dev/nvme0n1p1 /mnt/boot

add all the channels you had on your bad drive to confirm them run

nixos-enter

then

sudo nix-channel --list

this will give the list of all the channels

now you can exit it by typing

exit

Method 1 (works well if you have a previous generation)

nixos-enter

pick a previous generation you want the build to be based on

NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system-<generation-number>-link/bin/switch-to-configuration boot

example:

NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system-113-link/bin/switch-to-configuration boot

thats all you can reboot you pc and everything should be back to normal

Mthod 2 (this may take more bandwidth)

now add the channels. In my case i use nixos unstable and home manager so i will run

nix-channel --add https://nixos.org/channels/nixos-unstable nixos

nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager

and after adding all the channels we update our channels by running

nix-channel --update

then finally run

nixos-install

at the end it will ask you for password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment