Author: eelco
Date: Thu Jul 22 14:40:29 2010
New Revision: 22712
URL: https://svn.nixos.org/websvn/nix/?rev=22712&sc=1

Log:
* Use the regular GRUB menu builder for Amazon.  There are two issues:
  we want to generate the GRUB menu without actually installing GRUB
  (because Amazon supplies its own pv-grub), and each menu entry
  requires "root (hd0)".  For the first, allow boot.loader.grub.device
  to be set to "nodev" to indicate that the GRUB menu should be
  generated without installing GRUB.  For the second, add an option
  boot.loader.grub.extraPerEntryConfig to allow commands to be added
  to each GRUB menu entry (in this case, "root (hd0)").

Modified:
   nixos/trunk/modules/installer/grub/grub-menu-builder.sh
   nixos/trunk/modules/installer/grub/grub.nix
   nixos/trunk/modules/system/activation/switch-to-configuration.sh
   nixos/trunk/modules/system/boot/stage-1-init.sh
   nixos/trunk/modules/virtualisation/amazon-image.nix

Modified: nixos/trunk/modules/installer/grub/grub-menu-builder.sh
==============================================================================
--- nixos/trunk/modules/installer/grub/grub-menu-builder.sh     Thu Jul 22 
14:08:44 2010        (r22711)
+++ nixos/trunk/modules/installer/grub/grub-menu-builder.sh     Thu Jul 22 
14:40:29 2010        (r22712)
@@ -159,17 +159,17 @@
        case "$grubVersion" in
            1)
                cat > /boot/nixos-grub-config <<EOF
-       title Emergency boot
-       kernel $bootRoot/nixos-kernel systemConfig=$(readlink -f "$path") 
init=/boot/nixos-init $(cat "$path/kernel-params")
-       initrd $bootRoot/nixos-initrd
+title Emergency boot
+  kernel $bootRoot/nixos-kernel systemConfig=$(readlink -f "$path") 
init=/boot/nixos-init $(cat "$path/kernel-params")
+  initrd $bootRoot/nixos-initrd
 EOF
                ;;
            2)
                cat > /boot/nixos-grub-config <<EOF
-        menuentry "Emergency boot" {
-          linux  $bootRoot/nixos-kernel systemConfig=$(readlink -f "$path") 
init=/boot/nixos-init $(cat "$path/kernel-params")
-          initrd $bootRoot/initrd
-        }
+menuentry "Emergency boot" {
+  linux  $bootRoot/nixos-kernel systemConfig=$(readlink -f "$path") 
init=/boot/nixos-init $(cat "$path/kernel-params")
+  initrd $bootRoot/initrd
+}
 EOF
                ;;
        esac
@@ -189,6 +189,7 @@
        1)
            cat >> "$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 @@
        2)
            cat >> "$tmp" << GRUBEND
 menuentry "$name" {
+  @extraPerEntryConfig@
   linux  $kernel systemConfig=$(readlink -f $path) init=$(readlink -f 
$path/init) $(cat $path/kernel-params)
   initrd $initrd
 }

Modified: nixos/trunk/modules/installer/grub/grub.nix
==============================================================================
--- nixos/trunk/modules/installer/grub/grub.nix Thu Jul 22 14:08:44 2010        
(r22711)
+++ nixos/trunk/modules/installer/grub/grub.nix Thu Jul 22 14:40:29 2010        
(r22712)
@@ -13,7 +13,7 @@
     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 @@
         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 <literal>nodev</literal> means that a GRUB boot menu
+          will be generated, but GRUB itself will not actually be
+          installed.
         '';
       };
 
@@ -77,6 +80,15 @@
         '';
       };
 
+      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 = ''

Modified: nixos/trunk/modules/system/activation/switch-to-configuration.sh
==============================================================================
--- nixos/trunk/modules/system/activation/switch-to-configuration.sh    Thu Jul 
22 14:08:44 2010        (r22711)
+++ nixos/trunk/modules/system/activation/switch-to-configuration.sh    Thu Jul 
22 14:40:29 2010        (r22712)
@@ -30,14 +30,17 @@
           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 [ "$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 [ "@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
+              fi
           fi
           
       else

Modified: nixos/trunk/modules/system/boot/stage-1-init.sh
==============================================================================
--- nixos/trunk/modules/system/boot/stage-1-init.sh     Thu Jul 22 14:08:44 
2010        (r22711)
+++ nixos/trunk/modules/system/boot/stage-1-init.sh     Thu Jul 22 14:40:29 
2010        (r22712)
@@ -291,10 +291,10 @@
 # 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
 

Modified: nixos/trunk/modules/virtualisation/amazon-image.nix
==============================================================================
--- nixos/trunk/modules/virtualisation/amazon-image.nix Thu Jul 22 14:08:44 
2010        (r22711)
+++ nixos/trunk/modules/virtualisation/amazon-image.nix Thu Jul 22 14:40:29 
2010        (r22712)
@@ -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 @@
           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 @@
   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 = [ ];
 
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits

Reply via email to