2022-06-09 20:08:34 +02:00
|
|
|
|
<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 can’t
|
|
|
|
|
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 '<nixpkgs/nixos/release.nix>'
|
|
|
|
|
</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>
|
2022-12-21 21:24:48 +01:00
|
|
|
|
Note its symlinks pointing elsewhere, so <literal>cd</literal> in,
|
2022-06-09 20:08:34 +02:00
|
|
|
|
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>
|
2022-12-21 22:00:27 +01:00
|
|
|
|
<programlisting language="nix">
|
2022-06-09 20:08:34 +02:00
|
|
|
|
{ modulesPath, ... }: {
|
|
|
|
|
imports = [
|
|
|
|
|
(modulesPath + "/installer/netboot/netboot-minimal.nix")
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
services.openssh.enable = true;
|
|
|
|
|
users.users.root.openssh.authorizedKeys.keys = [
|
|
|
|
|
"my-ssh-pubkey"
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
</programlisting>
|
|
|
|
|
<programlisting>
|
|
|
|
|
nix-build '<nixpkgs/nixos>' \
|
|
|
|
|
--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>
|