Change root: Difference between revisions

imported>Ahoneybun
No edit summary
imported>Hucksy
Add more details for nixos-enter and a troubleshooting section
 
(One intermediate revision by one other user not shown)
Line 6: Line 6:


The nixos-enter program is part of NixOS. Before it runs provides a shell, the script mounts api filesystems like /proc and setups the profile and /etc of the target system. To use it, setup <code>/mnt</code> as described in the [https://nixos.org/nixos/manual/#sec-installation installation manual].
The nixos-enter program is part of NixOS. Before it runs provides a shell, the script mounts api filesystems like /proc and setups the profile and /etc of the target system. To use it, setup <code>/mnt</code> as described in the [https://nixos.org/nixos/manual/#sec-installation installation manual].
At the time of writting, the following <code>mount</code> commands should suffice:
<syntaxHighlight lang=console>
$ mount -o bind /dev/disk/by-label/<ROOT_LABEL> /mnt/
$ # mount any partitions you might have; here we assume only home and nix exist
$ mkdir -p /mnt/{home,nix}
$ mount -o bind /dev/disk/by-label/<HOME_LABEL> /mnt/home
$ mount -o bind /dev/disk/by-label/<NIX_LABEL> /mnt/nix
</syntaxHighlight>


Then run <code>nixos-enter</code>:
Then run <code>nixos-enter</code>:
Line 40: Line 52:
</syntaxHighlight>
</syntaxHighlight>


You should now be in your NixOS system, and should be able to adjust it by e.g. editing <code>/etc/nixos/configuration.nix</code> and running <code>nixos-rebuild switch</code> as usual. Remember that you may have to establish Internet access the chroot for some commands.
You should now be in your NixOS system, and should be able to adjust it by e.g. editing <code>/etc/nixos/configuration.nix</code> and running <code>nixos-rebuild switch</code> as usual. Remember that you may have to establish Internet access within the chroot for some commands.
 
= Troubleshooting =
 
== 1. nixos-rebuild fails with "System has not been booted with <program> as init system." ==
 
In some cases, such as when using [[Systemd-networkd|systemd-networkd]] as the [[Bootloader|bootloader]], [[Nixos-rebuild|nixos-rebuild]] commands might fail with a message similar to
 
<syntaxHighlight lang=console>
error: System has not been booted with systemd as init system (PID 1). Can't operate.
</syntaxHighlight>
 
If you have tried to use <code>nixos-rebuild switch</code>, you can try <code>nixos-rebuild boot</code> instead. Should that also fail, you can append <code>NIXOS_SWITCH_USE_DIRTY_ENV=1</code> to the commands, which should bypass the error while also setting the proper boot entries, if the [[Bootloader|bootloader]] is detected.
 
Finally, should all else fail, <code>nixos-install</code> should work as a replacement changing the root.