Home Explore Blog CI



nixpkgs

4th chunk of `nixos/doc/manual/installation/installing-from-other-distro.section.md`
7da686af8404e3b45dc262b2eec5ba696710d7933cc2550f0000000100000f0e
    `/nix` or `/boot` gets "lustrated" on the next boot.

    lustrate /ˈlʌstreɪt/ verb.

    purify by expiatory sacrifice, ceremonial washing, or some other
    ritual action.
    :::

    Let's create the files:

    ```ShellSession
    $ sudo touch /etc/NIXOS
    $ sudo touch /etc/NIXOS_LUSTRATE
    ```

    Let's also make sure the NixOS configuration files are kept once we
    reboot on NixOS:

    ```ShellSession
    $ echo etc/nixos | sudo tee -a /etc/NIXOS_LUSTRATE
    ```

1.  Finally, install NixOS's boot system, backing up the current boot system's files in the process.

    The details of this step can vary depending on the bootloader configuration in NixOS and the bootloader in use by the current system.

    The commands below should work for:

    - [BIOS](https://en.wikipedia.org/wiki/BIOS) systems.

    - [UEFI](https://en.wikipedia.org/wiki/UEFI) systems where both the current system and NixOS mount the [EFI System Partition](https://en.wikipedia.org/wiki/EFI_system_partition) on `/boot`.
      Both [systemd-boot](https://systemd.io/BOOT/) and [grub](https://www.gnu.org/software/grub/index.html) expect this by default in NixOS, but other distributions vary.

    ::: {.warning}
    Once you complete this step, your current distribution will no longer be bootable!
    If you didn't get all the NixOS configuration right, especially those settings pertaining to boot loading and root partition, NixOS may not be bootable either.
    Have a USB rescue device ready in case this happens.
    :::

    ::: {.warning}
    On [UEFI](https://en.wikipedia.org/wiki/UEFI) systems, anything on the [EFI System Partition](https://en.wikipedia.org/wiki/EFI_system_partition) will be removed by these commands, such as other coexisting OS's bootloaders.
    :::

    ```ShellSession
    $ sudo mkdir /boot.bak && sudo mv /boot/* /boot.bak &&
    sudo NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system/bin/switch-to-configuration boot
    ```

    Cross your fingers, reboot, hopefully you should get a NixOS prompt!

    In other cases, most commonly where the [EFI System Partition](https://en.wikipedia.org/wiki/EFI_system_partition) of the current system is instead mounted on `/boot/efi`, the goal is to:

    - Make sure `/boot` (and the [EFI System Partition](https://en.wikipedia.org/wiki/EFI_system_partition), if mounted elsewhere) are mounted how the NixOS configuration would mount them.

    - Clear them of files related to the current system, backing them up outside of `/boot`.
      NixOS will move the backups into `/old-root` along with everything else when it first boots.

    - Instruct the NixOS closure built earlier to install its bootloader with:
      ```ShellSession
      sudo NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system/bin/switch-to-configuration boot
      ```

1.  If for some reason you want to revert to the old distribution,
    you'll need to boot on a USB rescue disk and do something along
    these lines:

    ```ShellSession
    # mkdir root
    # mount /dev/sdaX root
    # mkdir root/nixos-root
    # mv -v root/* root/nixos-root/
    # mv -v root/nixos-root/old-root/* root/
    # mv -v root/boot.bak root/boot  # We had renamed this by hand earlier
    # umount root
    # reboot
    ```

    This may work as is or you might also need to reinstall the boot
    loader.

    And of course, if you're happy with NixOS and no longer need the
    old distribution:

    ```ShellSession
    sudo rm -rf /old-root
    ```

1.  It's also worth noting that this whole process can be automated.
    This is especially useful for Cloud VMs, where provider do not
    provide NixOS. For instance,
    [nixos-infect](https://github.com/elitak/nixos-infect) uses the
    lustrate process to convert Digital Ocean droplets to NixOS from
    other distributions automatically.

Title: Finalizing NixOS Installation and Reverting to Old Distribution
Summary
This section details the last steps for installing NixOS's boot system, emphasizing the importance of having a rescue USB ready due to the current distribution becoming unbootable. It warns about potential removal of other OS bootloaders on UEFI systems and provides commands for installing the bootloader. Additionally, it outlines the process for reverting to the old distribution using a USB rescue disk, including mounting partitions, moving files, and potentially reinstalling the boot loader. Finally, it touches on the possibility of automating the entire process, referencing tools like `nixos-infect` for converting cloud VMs to NixOS.