diff --git a/modules/installer/cd-dvd/iso-image.nix b/modules/installer/cd-dvd/iso-image.nix index 71b797b0d950..9ce05522f484 100644 --- a/modules/installer/cd-dvd/iso-image.nix +++ b/modules/installer/cd-dvd/iso-image.nix @@ -107,11 +107,22 @@ in system.boot.loader.kernelFile = "bzImage"; environment.systemPackages = [ pkgs.grub2 ]; - # In stage 1 of the boot, mount the CD/DVD as the root FS by label - # so that we don't need to know its device. + # In stage 1 of the boot, mount the CD as the root FS by label so + # that we don't need to know its device. We pass the label of the + # root filesystem on the kernel command line, rather than in + # `fileSystems' below. This allows CD-to-USB converters such as + # UNetbootin to rewrite the kernel command line to pass the label or + # UUID of the USB stick. It would be nicer to write + # `root=/dev/disk/by-label/...' here, but UNetbootin doesn't + # recognise that. + boot.kernelParams = [ "root=LABEL=${config.isoImage.volumeID}" ]; + + # Note that /dev/root is a symlink to the actual root device + # specified on the kernel command line, created in the stage 1 init + # script. fileSystems = [ { mountPoint = "/"; - label = config.isoImage.volumeID; + device = "/dev/root"; } { mountPoint = "/nix/store"; fsType = "squashfs"; diff --git a/modules/system/boot/stage-1-init.sh b/modules/system/boot/stage-1-init.sh index 11a10629d7cf..080016dc32c6 100644 --- a/modules/system/boot/stage-1-init.sh +++ b/modules/system/boot/stage-1-init.sh @@ -80,6 +80,20 @@ for o in $(cat /proc/cmdline); do stage1panic) panicOnFail=1 ;; + root=*) + # If a root device is specified on the kernel command + # line, make it available through the symlink /dev/root. + # Recognise LABEL= and UUID= to support UNetbootin. + set -- $(IFS==; echo $o) + if [ $2 = "LABEL" ]; then + root="/dev/disk/by-label/$3" + elif [ $2 = "UUID" ]; then + root="/dev/disk/by-uuid/$3" + else + root=$2 + fi + ln -s "$root" /dev/root + ;; esac done diff --git a/modules/system/boot/stage-1.nix b/modules/system/boot/stage-1.nix index 0a5cec8b1d23..4eb0eedf0b40 100644 --- a/modules/system/boot/stage-1.nix +++ b/modules/system/boot/stage-1.nix @@ -130,6 +130,7 @@ let cp -v ${pkgs.coreutils}/bin/cat $out/bin cp -v ${pkgs.coreutils}/bin/chroot $out/bin cp -v ${pkgs.coreutils}/bin/sleep $out/bin + cp -v ${pkgs.coreutils}/bin/ln $out/bin # Copy e2fsck and friends. cp -v ${pkgs.e2fsprogs}/sbin/e2fsck $out/bin