Auto-installer DVD with kexec?

I would like to make a custom DVD that I can attach to cloud VMs for services like Vultr that don’t have custom root disk support.

This DVD should be an auto-installer but also a rescue system.

I’m thinking it would do these things on boot:

  • If any of the following steps fail, send a message and wait
  • check that /dev/vda exists
  • format it if necessary
  • mount it
  • if it has ssh host keys, copy them
  • run sshd
  • copy the keys to the disk if it didn’t have them
  • install a minimal nixos system if there’s none
  • wait a second or two
  • wait until there are no SSH sessions running
  • kexec into the system

This means that if the DVD is attached, it will ensure that there’s a NixOS system on the root for further installation with nixops/morph or it will allow rescueing a system that won’t boot.


  • how to safely detect a disk that isn’t formatted? The first MB is all 0?
  • is it easy to kexec a nixos system?
  • is this way too complex and I should do things in a different way instead?
1 Like

For the formatting, I just found autoFormat which would solve that. It does this:

                if ! [ -e "${fs.device}" ]; then exit 1; fi
                # FIXME: this is scary.  The test could be more robust.
                type=$(blkid -p -s TYPE -o value "${fs.device}" || true)
                if [ -z "$type" ]; then
                  echo "creating ${fs.fsType} filesystem on ${fs.device}..."
                  mkfs.${fs.fsType} ${fs.formatOptions} "${fs.device}"

I think it might be easier to build the installer as NixOS kexec image, then just kexec and run the installer.

This is roughly the approach in clever’s nixos-tests repo in kexec.nix and justdoit.nix.