nixpkgs/nixos/doc/manual/from_md/installation/installing-kexec.section.xml
Florian Klink 06aa64684c nixos/doc: document how to use kexecTree
This documents how to build kexec artifacts.
2022-06-09 20:08:34 +02:00

95 lines
3.1 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-booting-via-kexec">
<title><quote>Booting</quote> into NixOS via kexec</title>
<para>
In some cases, your system might already be booted into/preinstalled
with another Linux distribution, and booting NixOS by attaching an
installation image is quite a manual process.
</para>
<para>
This is particularly useful for (cloud) providers where you cant
boot a custom image, but get some Debian or Ubuntu installation.
</para>
<para>
In these cases, it might be easier to use <literal>kexec</literal>
to <quote>jump into NixOS</quote> from the running system, which
only assumes <literal>bash</literal> and <literal>kexec</literal> to
be installed on the machine.
</para>
<para>
Note that kexec may not work correctly on some hardware, as devices
are not fully re-initialized in the process. In practice, this
however is rarely the case.
</para>
<para>
To build the necessary files from your current version of nixpkgs,
you can run:
</para>
<programlisting>
nix-build -A kexec.x86_64-linux '&lt;nixpkgs/nixos/release.nix&gt;'
</programlisting>
<para>
This will create a <literal>result</literal> directory containing
the following:
</para>
<itemizedlist spacing="compact">
<listitem>
<para>
<literal>bzImage</literal> (the Linux kernel)
</para>
</listitem>
<listitem>
<para>
<literal>initrd</literal> (the initrd file)
</para>
</listitem>
<listitem>
<para>
<literal>kexec-boot</literal> (a shellscript invoking
<literal>kexec</literal>)
</para>
</listitem>
</itemizedlist>
<para>
These three files are meant to be copied over to the other already
running Linux Distribution.
</para>
<para>
Note its symlinks pointing elsewhere, so <literal>cd</literal> in,
and use <literal>scp * root@$destination</literal> to copy it over,
rather than rsync.
</para>
<para>
Once you finished copying, execute <literal>kexec-boot</literal>
<emphasis>on the destination</emphasis>, and after some seconds, the
machine should be booting into an (ephemeral) NixOS installation
medium.
</para>
<para>
In case you want to describe your own system closure to kexec into,
instead of the default installer image, you can build your own
<literal>configuration.nix</literal>:
</para>
<programlisting language="bash">
{ modulesPath, ... }: {
imports = [
(modulesPath + &quot;/installer/netboot/netboot-minimal.nix&quot;)
];
services.openssh.enable = true;
users.users.root.openssh.authorizedKeys.keys = [
&quot;my-ssh-pubkey&quot;
];
}
</programlisting>
<programlisting>
nix-build '&lt;nixpkgs/nixos&gt;' \
--arg configuration ./configuration.nix
--attr config.system.build.kexecTree
</programlisting>
<para>
Make sure your <literal>configuration.nix</literal> does still
import <literal>netboot-minimal.nix</literal> (or
<literal>netboot-base.nix</literal>).
</para>
</section>