Installing from Linux: Difference between revisions
imported>Chuangzhu Chroot doesn't work for now, use pivot_root |
Phanirithvij (talk | contribs) m change iso url |
||
(15 intermediate revisions by 9 users not shown) | |||
Line 1: | Line 1: | ||
== Why? == | |||
You already have a running linux | For 'normal' NixOS installations, you'd use the instructions from https://nixos.org/manual/nixos/stable/index.html#sec-installation | ||
However, you can install 'directly from Linux' if: | |||
* You already have a running linux distro | |||
* You don't want to waste a CD-R (and can't boot from USB) | |||
* You have a spare partition where to install NixOS ready. | |||
One method is described in the manual at https://nixos.org/manual/nixos/stable/#sec-installing-from-other-distro. For an alternative method, see below. | |||
== How? == | |||
To simplify, we will be using these abbreviations: | To simplify, we will be using these abbreviations: | ||
Line 20: | Line 29: | ||
== Installing through a chroot == | == Installing through a chroot == | ||
In this section we will install NixOS by unpacking the ISO and then chrooting into its contents to start the final install. | In this section we will install NixOS by unpacking the ISO and then chrooting into its contents to start the final install. | ||
Note that this may not work on all distributions (eg. older versions of debian stable). | |||
=== Preparations === | === Preparations === | ||
Line 28: | Line 40: | ||
# cd ~ | # cd ~ | ||
# mkdir -p inst host/nix | # mkdir -p inst host/nix | ||
# wget https://channels.nixos.org/nixos-21. | # wget https://channels.nixos.org/nixos-21.11/latest-nixos-minimal-x86_64-linux.iso | ||
# modprobe loop | # modprobe loop | ||
# mount -o loop latest-nixos-minimal-x86_64-linux.iso inst | # mount -o loop latest-nixos-minimal-x86_64-linux.iso inst | ||
Line 39: | Line 51: | ||
# mkdir -p etc dev proc sys | # mkdir -p etc dev proc sys | ||
# cp /etc/resolv.conf etc | # cp /etc/resolv.conf etc | ||
# for fn in dev proc sys; do mount --bind /$fn $fn; done | # for fn in dev proc sys; do mount --bind "/${fn}" "${fn}"; done | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 58: | Line 70: | ||
Next we have to edit the target system init script to start a bash session instead of systemd. As that is the last thing the script does, adding an interactive program does not pose a problem. | Next we have to edit the target system init script to start a bash session instead of systemd. As that is the last thing the script does, adding an interactive program does not pose a problem. | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# sed -i "s,exec systemd,exec /$BASH," $INIT | # sed -i "s,exec /.*systemd,exec /$BASH," $INIT | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 64: | Line 76: | ||
Now we are able to chroot into the NixOS system used for installation. ''You may get several warnings and errors, but you can safely ignore them unless they are fatal.'' If you're installing from Arch, you may need to remove the mount call that tries to make / private in the same init script. | Now we are able to chroot into the NixOS system used for installation. ''You may get several warnings and errors, but you can safely ignore them unless they are fatal.'' If you're installing from Arch, you may need to remove the mount call that tries to make / private in the same init script. | ||
Using chroot: | |||
<syntaxhighlight lang="console"> | |||
# chroot . /$INIT | |||
</syntaxhighlight> | |||
Using pivot_root: | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# mkdir old_root | # mkdir old_root | ||
Line 76: | Line 94: | ||
# (chroot) mount /dev/sda3 /mnt | # (chroot) mount /dev/sda3 /mnt | ||
# (chroot) nixos-generate-config --root /mnt | # (chroot) nixos-generate-config --root /mnt | ||
# (chroot) nano /etc/nixos/configuration.nix | # (chroot) nano /mnt/etc/nixos/configuration.nix | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Before executing nixos-install you might want to run nixos-checkout to obtain the most recent version of packages to be installed into your NixOS system. You might need to copy /etc/resolv.conf from the host to the target system. | Before executing nixos-install you might want to run nixos-checkout to obtain the most recent version of packages to be installed into your NixOS system. You might need to copy /etc/resolv.conf from the host to the target system. | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# (chroot) NIX_PATH="nixpkgs=channel:nixos-21. | # (chroot) NIX_PATH="nixpkgs=channel:nixos-21.11" nixos-install | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 105: | Line 123: | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# wget https:// | # wget https://channels.nixos.org/nixos-24.05/latest-nixos-minimal-x86_64-linux.iso # get the latest iso (URL might change!) | ||
# modprobe loop | # modprobe loop | ||
# mount -o loop nixos-minimal | # mount -o loop latest-nixos-minimal-x86_64-linux.iso ~/inst | ||
# # mount /dev/sda1 # mount the /boot partition if you have it | # # mount /dev/sda1 # mount the /boot partition if you have it | ||
# cp ~/inst/boot/bzImage /boot/nixos-livecd-bzImage | # cp ~/inst/boot/bzImage /boot/nixos-livecd-bzImage | ||
Line 170: | Line 188: | ||
Thats it. Now follow the manual (Alt-F8), mount /dev/sda3 as /mnt, do | Thats it. Now follow the manual (Alt-F8), mount /dev/sda3 as /mnt, do | ||
nixos-option and so on. | nixos-option and so on. | ||
[[Category:Tutorial]] |