aboutsummaryrefslogtreecommitdiffstats
path: root/doc/rescue.md
blob: 431246a66c8c46eef2d2e0a36b8f5203e5fcf9fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Using NixOS Installer as Rescue Environment

As with most Linux distributions, you will need to mount your
core file systems under `/mnt`.  You don't need to worry about
the virtual file systems, just the real ones, including any boot
or ESP partitions.  You can also skip swap for now.

Once you are done with that, you can simply type `nixos-enter` to
pivot into the chroot.  You will probably also want to `unset
SUDO_USER` if you used `sudo -i` or something similar, as having
it set will probably cause issues when trying to run
`nixos-rebuild`.

Should you need to manually set up the rescue environment, beyond
the physical mounts already done above, you will also need to run
the following:

```
mount -o bind /dev /mnt/dev
mount -o bind /proc /mnt/proc
mount -o bind /sys /mnt/sys
chroot /mnt /nix/var/nix/profiles/system/activate
chroot /mnt /run/current-system/sw/bin/bash
```

Lastly, should you get the following error when trying to run
`nixos-rebuild switch` within your rescue environment, usually
caused by systemd as the bootloader:

```
error: System has not been booted with systemd as init system (PID 1). Can't operate.
```

you can instead try running `nixos-rebuild boot`.  If that also
fails, you can try appending those commands with
`NIXOS_SWITCH_USE_DIRTY_ENV=1` which might work around the
problem.  And should none of that work, you can try to use
`nixos-install` as a last resort.