Netboot: Difference between revisions

From NixOS Wiki
imported>Erikarvstedt
mNo edit summary
imported>Erikarvstedt
m update to nixpkgs 20.09
Line 23: Line 23:
       systemd.services.sshd.wantedBy = mkOverride 0 [ "multi-user.target" ];
       systemd.services.sshd.wantedBy = mkOverride 0 [ "multi-user.target" ];
       # users.users.root.openssh.authorizedKeys.keys = [ ... ];
       # users.users.root.openssh.authorizedKeys.keys = [ ... ];
       # i18n.consoleKeyMap = "de";
       # console.keyMap = "de";
     };
     };
   };
   };
Line 43: Line 43:
init=$(grep -ohP 'init=\S+' $n/netboot.ipxe)
init=$(grep -ohP 'init=\S+' $n/netboot.ipxe)


# As of May 2020, Pixiecore is only available on nixos-unstable
nix build -o /tmp/pixiecore nixpkgs.pixiecore
nix build -o /tmp/pixiecore -f channel:nixos-unstable pixiecore


# Start the PXE server.
# Start the PXE server.

Revision as of 20:49, 27 November 2020

Building and serving a netboot image

Example

This example uses Pixiecore for hosting, which works in an ordinary network environment with an existing DHCP server.

#!/usr/bin/env bash

set -euo pipefail

nix-build --out-link /tmp/netboot - <<'EOF'
let
  bootSystem = import <nixpkgs/nixos> {
    # system = ...;

    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 = [ ... ];
      # console.keyMap = "de";
    };
  };

  pkgs = import <nixpkgs> {};
in
  pkgs.symlinkJoin {
    name = "netboot";
    paths = with bootSystem.config.system.build; [
      netbootRamdisk
      kernel
      netbootIpxeScript
    ];
    preferLocalBuild = true;
  }
EOF

n=$(realpath /tmp/netboot)
init=$(grep -ohP 'init=\S+' $n/netboot.ipxe)

nix build -o /tmp/pixiecore nixpkgs.pixiecore

# Start the PXE server.
# These ports need to be open in your firewall:
# UDP: 67, 69
# TCP: 64172
sudo /tmp/pixiecore/bin/pixiecore \
  boot $n/bzImage $n/initrd \
  --cmdline "$init loglevel=4" \
  --debug --dhcp-no-bind --port 64172 --status-port 64172

See also

NixOS manual: PXE booting.

NixOS unstable has a Pixiecore service module.

netboot.xyz

There is now official netboot.xyz support. Just select NixOS from Linux installs and you should be ready to go.

Note: Your iPXE must be recent enough to support https:// links