Netboot: Difference between revisions
imported>Hhm m fix link |
imported>Erikarvstedt Add section 'Building and serving a netboot image' |
||
| Line 1: | Line 1: | ||
== Building a netboot image == | == Building and serving a netboot image == | ||
=== Prerequisites === | |||
Enable Docker on the host system: <code>virtualisation.docker.enable = true</code> | |||
=== Example === | |||
This example uses [https://github.com/danderson/netboot/tree/master/pixiecore pixicore] for hosting, which works in an ordinary network environment with an existing DHCP server. | |||
= | <syntaxHighlight lang=bash> | ||
#!/usr/bin/env bash -e | |||
nix-build --out-link /tmp/netboot - <<'EOF' | |||
let | |||
nixpkgs = <nixpkgs>; | |||
pkgs = import nixpkgs {}; | |||
configuration = { config, pkgs, lib, ... }: with lib; { | |||
imports = [ | |||
"${nixpkgs}/nixos/modules/installer/netboot/netboot-minimal.nix" | |||
]; | |||
## Some useful options for setting up a new system | |||
services.mingetty.autologinUser = mkForce "root"; | |||
# Enable sshd which gets disabled by netboot-minimal.nix | |||
systemd.services.sshd.wantedBy = mkOverride 0 [ "multi-user.target" ]; | |||
# users.users.root.openssh.authorizedKeys.keys = [ ... ]; | |||
# i18n.consoleKeyMap = "de"; | |||
}; | |||
nixos = import "${nixpkgs}/nixos" { | |||
inherit configuration; | |||
# system = ...; | |||
}; | |||
in | |||
pkgs.symlinkJoin { | |||
name = "netboot"; | |||
paths = with nixos.config.system.build; [ | |||
netbootRamdisk | |||
kernel | |||
netbootIpxeScript | |||
]; | |||
preferLocalBuild = true; | |||
} | |||
EOF | |||
n=$(realpath /tmp/netboot) | |||
init=$(grep -ohP 'init=\S+' $n/netboot.ipxe) | |||
# Start the PXE server. | |||
# These ports need to be open in your firewall: | |||
# UDP: 67, 69 | |||
# TCP: 64172 | |||
docker run --rm \ | |||
-v /etc/ssl/certs:/etc/ssl/certs:ro \ | |||
-v /nix/store:/nix/store:ro \ | |||
--net=host \ | |||
pixiecore/pixiecore:master \ | |||
boot $n/bzImage $n/initrd \ | |||
--cmdline "$init loglevel=4" \ | |||
-d --dhcp-no-bind --port 64172 --status-port 64172 | |||
</syntaxHighlight> | |||
See the [https://nixos.org/nixos/manual/index.html#sec-booting-from-pxe official NixOS Manual] for more information about PXE booting. | |||
== Native netboot hosting with NixOS == | |||
Pixiecore is still in the process of being [https://github.com/NixOS/nixpkgs/pull/62113 added to NixOS]. Meanwhile, you can use the <code>netboot_server</code> module from [https://github.com/cleverca22/nixos-configs/blob/1d6a7de65c1b133f623fd4ce6619c56ef749ffa6/netboot_server.nix clever]. | |||
== netboot.xyz == | == netboot.xyz == | ||
| Line 10: | Line 67: | ||
Just select <b>NixOS</b> from Linux installs and you should be ready to go. | Just select <b>NixOS</b> from Linux installs and you should be ready to go. | ||
<b>Note:</b> Your | <b>Note:</b> Your iPXE must be recent enough to support https:// links | ||