diff --git a/nixos/doc/manual/installation/installing-from-other-distro.section.md b/nixos/doc/manual/installation/installing-from-other-distro.section.md index 3608cd7716fc..b470c5736f71 100644 --- a/nixos/doc/manual/installation/installing-from-other-distro.section.md +++ b/nixos/doc/manual/installation/installing-from-other-distro.section.md @@ -160,6 +160,18 @@ The first steps to all these are the same: Refer to the `nixos-generate-config` step in [](#sec-installation) for more information. + ::: {.note} + On [UEFI](https://en.wikipedia.org/wiki/UEFI) systems, check that your `/etc/nixos/hardware-configuration.nix` did the right thing with the [EFI System Partition](https://en.wikipedia.org/wiki/EFI_system_partition). + In NixOS, by default, both [systemd-boot](https://systemd.io/BOOT/) and [grub](https://www.gnu.org/software/grub/index.html) expect it to be mounted on `/boot`. + However, the configuration generator bases its [](#opt-fileSystems) configuration on the current mount points at the time it is run. + If the current system and NixOS's bootloader configuration don't agree on where the [EFI System Partition](https://en.wikipedia.org/wiki/EFI_system_partition) is to be mounted, you'll need to manually alter the mount point in `hardware-configuration.nix` before building the system closure. + ::: + + ::: {.note} + The lustrate process will not work if the [](#opt-boot.initrd.systemd.enable) option is set to `true`. + If you want to use this option, wait until after the first boot into the NixOS system to enable it and rebuild. + ::: + You'll likely want to set a root password for your first boot using the configuration files because you won't have a chance to enter a password until after you reboot. You can initialize the root password @@ -231,26 +243,46 @@ The first steps to all these are the same: $ echo etc/nixos | sudo tee -a /etc/NIXOS_LUSTRATE ``` -1. Finally, move the `/boot` directory of your current distribution out - of the way (the lustrate process will take care of the rest once you - reboot, but this one must be moved out now because NixOS needs to - install its own boot files: +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. + 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 mv -v /boot /boot.bak && - sudo /nix/var/nix/profiles/system/bin/switch-to-configuration boot + $ 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: diff --git a/nixos/modules/system/activation/switch-to-configuration.pl b/nixos/modules/system/activation/switch-to-configuration.pl index 774e77131f5d..5220f8ef8c09 100755 --- a/nixos/modules/system/activation/switch-to-configuration.pl +++ b/nixos/modules/system/activation/switch-to-configuration.pl @@ -41,10 +41,6 @@ use Fcntl ':flock'; my $out = "@out@"; # System closure path to switch to my $toplevel = "@toplevel@"; -# Path to the directory containing systemd tools of the old system -my $cur_systemd = abs_path("/run/current-system/sw/bin"); -# Path to the systemd store path of the new system -my $new_systemd = "@systemd@"; # To be robust against interruption, record what units need to be started etc. # We read these files again every time this script starts to make sure we continue @@ -130,6 +126,12 @@ if ($action eq "boot") { exit(0); } +# Path to the directory containing systemd tools of the old system +# Needs to be after the "boot" action exits, as this directory will not exist when doing a NIXOS_LUSTRATE install +my $cur_systemd = abs_path("/run/current-system/sw/bin"); +# Path to the systemd store path of the new system +my $new_systemd = "@systemd@"; + # Check if we can activate the new configuration. my $cur_init_interface_version = read_file("/run/current-system/init-interface-version", err_mode => "quiet") // ""; my $new_init_interface_version = read_file("$toplevel/init-interface-version"); diff --git a/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs b/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs index 0c4ccbec89fc..489259700d21 100644 --- a/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs +++ b/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs @@ -997,10 +997,6 @@ fn do_system_switch(action: Action) -> anyhow::Result<()> { std::env::set_var("LOCALE_ARCHIVE", locale_archive); } - let current_system_bin = std::path::PathBuf::from("/run/current-system/sw/bin") - .canonicalize() - .context("/run/current-system/sw/bin is missing")?; - let os_release = parse_os_release().context("Failed to parse os-release")?; let distro_id_re = Regex::new(format!("^\"?{}\"?$", distro_id).as_str()) @@ -1072,6 +1068,11 @@ fn do_system_switch(action: Action) -> anyhow::Result<()> { std::process::exit(0); } + // Needs to be after the "boot" action exits, as this directory will not exist when doing a NIXOS_LUSTRATE install + let current_system_bin = std::path::PathBuf::from("/run/current-system/sw/bin") + .canonicalize() + .context("/run/current-system/sw/bin is missing")?; + let current_init_interface_version = std::fs::read_to_string("/run/current-system/init-interface-version").unwrap_or_default();