multibootusb icon indicating copy to clipboard operation
multibootusb copied to clipboard

Support for NixOS

Open ashkitten opened this issue 7 years ago • 10 comments

Not sure how to approach it. Unlike a "normal" Linux distro, NixOS uses the hash of the build process (or something like that, I don't understand fully how everything works yet) to specify the directory where things should be, for instance the init is stored (for the current version at least) in /nix/store/g5qa0gq6fhqfs56sckyx56d1002i59iw-nixos-system-nixos-17.03.889.9626bc7db7/init. Is there a way to get the linux options from the iso at boot time? Or do we have to make a new boot entry for each and every separate iso?

ashkitten avatar Apr 05 '17 01:04 ashkitten

Hello @ashyon,

To load the boot options from NixOS ISO at boot time you can use syslinux_configfile but, even if they were loaded, we need to pass some parameters to the kernel so it knows to boot from the ISO file.

The closest thing I've found for NixOS is this entry in their mailing list which is far from ideal.

aguslr avatar Apr 06 '17 11:04 aguslr

I've been trying to get NixOS to boot for the past 12 hours!!! Never gets past stage 1, as it can't find the root iso filesystem and mount it to /dev/root

ob7 avatar Apr 14 '17 10:04 ob7

Hi @ob7. To make it work, I'd suggest contacting the developers at their IRC channel and see if they can help with this.

aguslr avatar Apr 14 '17 11:04 aguslr

I think I need some kind of live initrd image to make it work. I couldn't get the Debian DVD installer to load using the normal initrm file but instead I had to swap it out with the one used for the debian live iso to get through a full Debian installation from the DVD with no network booted from my multiboot USB.

Will have to do some reading.

ob7 avatar Apr 15 '17 08:04 ob7

I also am in favor of supporting NixOS

baconicsynergy avatar Jul 13 '17 09:07 baconicsynergy

I am also in favor also. I'll try my hand at this.

tmplt avatar Jan 17 '18 15:01 tmplt

From an initial look at it, a boot parameter with a /nix/store hash must be supplied, and this cannot be derived from the iso's file name. It could be hard-coded, but I don't think we want that; it will break with every NixOS release.

tmplt avatar Jan 17 '18 22:01 tmplt

With the isolinux.cfg

SERIAL 0 38400
TIMEOUT 100
UI vesamenu.c32
MENU TITLE NixOS
MENU BACKGROUND /isolinux/background.png
DEFAULT boot

LABEL boot
MENU LABEL NixOS 17.09.1483.d0f0657ca0 Installer
LINUX /boot/bzImage
APPEND init=/nix/store/k2dd07cmp1iixhljc600qkii4kd528d9-nixos-system-nixos-17.09.1483.d0f0657ca0/init root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4
INITRD /boot/initrd

# A variant to boot with 'nomodeset'
LABEL boot-nomodeset
MENU LABEL NixOS 17.09.1483.d0f0657ca0 Installer (nomodeset)
LINUX /boot/bzImage
APPEND init=/nix/store/k2dd07cmp1iixhljc600qkii4kd528d9-nixos-system-nixos-17.09.1483.d0f0657ca0/init root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4 nomodeset
INITRD /boot/initrd

# A variant to boot with 'copytoram'
LABEL boot-copytoram
MENU LABEL NixOS 17.09.1483.d0f0657ca0 Installer (copytoram)
LINUX /boot/bzImage
APPEND init=/nix/store/k2dd07cmp1iixhljc600qkii4kd528d9-nixos-system-nixos-17.09.1483.d0f0657ca0/init root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4 copytoram
INITRD /boot/initrd

# A variant to boot with verbose logging to the console
LABEL boot-nomodeset
MENU LABEL NixOS 17.09.1483.d0f0657ca0 Installer (debug)
LINUX /boot/bzImage
APPEND init=/nix/store/k2dd07cmp1iixhljc600qkii4kd528d9-nixos-system-nixos-17.09.1483.d0f0657ca0/init root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4 loglevel=7
INITRD /boot/initrd
LABEL memtest
MENU LABEL Memtest86+
LINUX /boot/memtest.bin
APPEND 

I have the following nixos.d/minimal-generic.cfg as test:

for isofile in $isopath/nixos-minimal-*-linux.iso; do
  if [ -e "$isofile" ]; then
    regexp --set=isoname "$isopath/(.*)" "$isofile"
    submenu "$isoname ->" "$isofile" {
      iso_path="$2"
      loopback loop "$iso_path"
      root=(loop)
      menuentry "NixOS Installer" {
        bootoptions="init=/nix/store/k2dd07cmp1iixhljc600qkii4kd528d9-nixos-system-nixos-17.09.1483.d0f0657ca0/init root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4"
        linux /boot/bzImage $bootoptions
        initrd /boot/initrd
      }
    }
  fi
done

It boots, but State 1 fails waiting for /dev/root to appear. An old NixOS issue mentions labeling the USB device as NIXOS_ISO fixed the issue, but is this not what the boot option root=LABEL=NIXOS_ISO does?

tmplt avatar Jan 18 '18 15:01 tmplt

Basically following this guide with the above config worked. If the isos live on a non-linux partition type i. e. fat32 (i. e. you wanted to reuse the partition for more diverse purpose) there could still be a problem with that approach.

573 avatar Aug 27 '19 07:08 573

@tmplt I can confirm that I was now able to boot a nixos iso using multibootusb by doing the as follows but let me first state my assumptions: the stick i am using has three partitions, two of them (efi and data, data is where the isos are stored) formatted as fat, the boot partition linux.

the bootoptions used in the mbusb.d/nixos.d/generic.cfg file are stolen from the iso file I was going to use, loop mount or 7zip-open it for that task, i. e. nixos-minimal-19.09.1861.eb65d1dae62-x86_64-linux.iso/EFI/boot/grub.cfg Of importance here seemed the root=LABEL=NIXOS_ISO, meaning that I labeled (i. e. using mlabel on linux) my usbsticks data partition NIXOS_ISO. Also I found out that it seems needed currently to copy the nixos-minimal-19.09.1861.eb65d1dae62-x86_64-linux.iso/nix-store.squashfs file to the usbsticks root, thus it can be found in stage 1 of the boot process.

for isofile in $isopath/nixos-minimal-*-linux.iso; do
  if [ -e "$isofile" ]; then
    regexp --set=isoname "$isopath/(.*)" "$isofile"
    submenu "$isoname ->" "$isofile" {
      iso_path="$2"
      loopback loop "$iso_path"
      root=(loop)
      menuentry "NixOS Installer" {
        bootoptions="init=/nix/store/8v4s9yd1p4lqxbv0vbimihxf4d977xa2-nixos-system-nixos-19.09.1861.eb65d1dae62/init  root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4 findiso=nixos-minimal-19.09.1861.eb65d1dae62-x86_64-linux.iso"
        linux /boot/bzImage $bootoptions
        initrd /boot/initrd
      }
    }
  fi
done

In case you wanna work that out further, see as well https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/system/boot/stage-1-init.sh#L136 as a reference.

573 avatar Jan 29 '20 11:01 573