diff --git a/modules/installer/grub/grub-menu-builder.sh b/modules/installer/grub/grub-menu-builder.sh index f23184b0a06..0d5ddf60787 100644 --- a/modules/installer/grub/grub-menu-builder.sh +++ b/modules/installer/grub/grub-menu-builder.sh @@ -159,17 +159,17 @@ addEntry() { case "$grubVersion" in 1) cat > /boot/nixos-grub-config < /boot/nixos-grub-config <> "$tmp" << GRUBEND title $name + @extraPerEntryConfig@ kernel $kernel systemConfig=$(readlink -f $path) init=$(readlink -f $path/init) $(cat $path/kernel-params) initrd $initrd GRUBEND @@ -196,6 +197,7 @@ GRUBEND 2) cat >> "$tmp" << GRUBEND menuentry "$name" { + @extraPerEntryConfig@ linux $kernel systemConfig=$(readlink -f $path) init=$(readlink -f $path/init) $(cat $path/kernel-params) initrd $initrd } diff --git a/modules/installer/grub/grub.nix b/modules/installer/grub/grub.nix index 40c2ca60675..50ae0ddb596 100644 --- a/modules/installer/grub/grub.nix +++ b/modules/installer/grub/grub.nix @@ -13,7 +13,7 @@ let inherit (pkgs) bash; path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep]; inherit (config.boot.loader.grub) copyKernels - extraConfig extraEntries extraEntriesBeforeNixOS + extraConfig extraEntries extraEntriesBeforeNixOS extraPerEntryConfig splashImage configurationLimit version default timeout; }; @@ -48,9 +48,12 @@ in example = "/dev/hda"; type = with pkgs.lib.types; uniq string; description = '' - The device on which the boot loader, GRUB, will be installed. - If empty, GRUB won't be installed and it's your responsibility - to make the system bootable. + The device on which the boot loader, GRUB, will be + installed. If empty, GRUB won't be installed and it's your + responsibility to make the system bootable. The special + value nodev means that a GRUB boot menu + will be generated, but GRUB itself will not actually be + installed. ''; }; @@ -77,6 +80,15 @@ in ''; }; + extraPerEntryConfig = mkOption { + default = ""; + example = "root (hd0)"; + description = '' + Additional GRUB commands inserted in the configuration file + at the start of each NixOS menu entry. + ''; + }; + extraEntries = mkOption { default = ""; example = '' diff --git a/modules/system/activation/switch-to-configuration.sh b/modules/system/activation/switch-to-configuration.sh index ccb3d230e8d..bc7af231b97 100644 --- a/modules/system/activation/switch-to-configuration.sh +++ b/modules/system/activation/switch-to-configuration.sh @@ -30,14 +30,17 @@ if [ "$action" = "switch" -o "$action" = "boot" ]; then mkdir -m 0700 -p /boot/grub @menuBuilder@ @out@ - # If the GRUB version has changed, then force a reinstall. - oldGrubVersion="$(cat /boot/grub/version 2>/dev/null || true)" - newGrubVersion="@grubVersion@" + if [ "@grubDevice@" != nodev ]; then + + # If the GRUB version has changed, then force a reinstall. + oldGrubVersion="$(cat /boot/grub/version 2>/dev/null || true)" + newGrubVersion="@grubVersion@" - if [ "$NIXOS_INSTALL_GRUB" = 1 -o "$oldGrubVersion" != "$newGrubVersion" ]; then - echo "installing the GRUB bootloader..." - @grub@/sbin/grub-install "@grubDevice@" --no-floppy --recheck - echo "$newGrubVersion" > /boot/grub/version + if [ "$NIXOS_INSTALL_GRUB" = 1 -o "$oldGrubVersion" != "$newGrubVersion" ]; then + echo "installing the GRUB bootloader..." + @grub@/sbin/grub-install "@grubDevice@" --no-floppy --recheck + echo "$newGrubVersion" > /boot/grub/version + fi fi else diff --git a/modules/system/boot/stage-1-init.sh b/modules/system/boot/stage-1-init.sh index 0c9f1d46b2f..11a10629d7c 100644 --- a/modules/system/boot/stage-1-init.sh +++ b/modules/system/boot/stage-1-init.sh @@ -291,10 +291,10 @@ echo /sbin/modprobe > /proc/sys/kernel/modprobe # current root. It also moves the /proc, /sys and /dev mounts over to # the new root. Note that $stage2Init might be an absolute symlink, # in which case "-e" won't work because we're not in the chroot yet. -#if ! test -e "$targetRoot/$stage2Init" -o -L "$targetRoot/$stage2Init"; then -# echo "stage 2 init script ($targetRoot/$stage2Init) not found" -# fail -#fi +if ! test -e "$targetRoot/$stage2Init" -o -L "$targetRoot/$stage2Init"; then + echo "stage 2 init script ($targetRoot/$stage2Init) not found" + fail +fi mkdir -m 0755 -p $targetRoot/proc $targetRoot/sys $targetRoot/dev diff --git a/modules/virtualisation/amazon-image.nix b/modules/virtualisation/amazon-image.nix index 81f6a25758e..a0fc9cce908 100644 --- a/modules/virtualisation/amazon-image.nix +++ b/modules/virtualisation/amazon-image.nix @@ -2,20 +2,6 @@ with pkgs.lib; -let - - grubMenu = pkgs.writeText "pv-grub-menu.lst" - '' - default 0 - timeout 0 - title EC2 - root (hd0) - kernel /nix/var/nix/profiles/system/kernel systemConfig=/nix/var/nix/profiles/system init=/nix/var/nix/profiles/system/init - initrd /nix/var/nix/profiles/system/initrd - ''; - -in - { system.build.amazonImage = pkgs.vmTools.runInLinuxVM ( @@ -62,10 +48,8 @@ in mkdir -p /mnt/etc/nixos cp ${./amazon-config.nix} /mnt/etc/nixos/configuration.nix - # Amazon uses `pv-grub', which expects a - # /boot/grub/menu.lst. - mkdir -p /mnt/boot/grub - cp ${grubMenu} /mnt/boot/grub/menu.lst + # Generate the GRUB menu. + chroot /mnt ${config.system.build.toplevel}/bin/switch-to-configuration boot umount /mnt '' @@ -87,6 +71,11 @@ in boot.initrd.kernelModules = [ "xen-blkfront" ]; boot.kernelModules = [ "xen-netfront" ]; + # Generate a GRUB menu. Amazon's pv-grub uses this to boot our kernel/initrd. + boot.loader.grub.device = "nodev"; + boot.loader.grub.timeout = 0; + boot.loader.grub.extraPerEntryConfig = "root (hd0)"; + # There are no virtual consoles. services.mingetty.ttys = [ ];