0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

* 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)").

svn path=/nixos/trunk/; revision=22712
This commit is contained in:
Eelco Dolstra 2010-07-22 14:40:29 +00:00
parent 3a0f295337
commit d659488209
5 changed files with 46 additions and 40 deletions

View file

@ -159,17 +159,17 @@ addEntry() {
case "$grubVersion" in case "$grubVersion" in
1) 1)
cat > /boot/nixos-grub-config <<EOF cat > /boot/nixos-grub-config <<EOF
title Emergency boot title Emergency boot
kernel $bootRoot/nixos-kernel systemConfig=$(readlink -f "$path") init=/boot/nixos-init $(cat "$path/kernel-params") kernel $bootRoot/nixos-kernel systemConfig=$(readlink -f "$path") init=/boot/nixos-init $(cat "$path/kernel-params")
initrd $bootRoot/nixos-initrd initrd $bootRoot/nixos-initrd
EOF EOF
;; ;;
2) 2)
cat > /boot/nixos-grub-config <<EOF cat > /boot/nixos-grub-config <<EOF
menuentry "Emergency boot" { menuentry "Emergency boot" {
linux $bootRoot/nixos-kernel systemConfig=$(readlink -f "$path") init=/boot/nixos-init $(cat "$path/kernel-params") linux $bootRoot/nixos-kernel systemConfig=$(readlink -f "$path") init=/boot/nixos-init $(cat "$path/kernel-params")
initrd $bootRoot/initrd initrd $bootRoot/initrd
} }
EOF EOF
;; ;;
esac esac
@ -189,6 +189,7 @@ EOF
1) 1)
cat >> "$tmp" << GRUBEND cat >> "$tmp" << GRUBEND
title $name title $name
@extraPerEntryConfig@
kernel $kernel systemConfig=$(readlink -f $path) init=$(readlink -f $path/init) $(cat $path/kernel-params) kernel $kernel systemConfig=$(readlink -f $path) init=$(readlink -f $path/init) $(cat $path/kernel-params)
initrd $initrd initrd $initrd
GRUBEND GRUBEND
@ -196,6 +197,7 @@ GRUBEND
2) 2)
cat >> "$tmp" << GRUBEND cat >> "$tmp" << GRUBEND
menuentry "$name" { menuentry "$name" {
@extraPerEntryConfig@
linux $kernel systemConfig=$(readlink -f $path) init=$(readlink -f $path/init) $(cat $path/kernel-params) linux $kernel systemConfig=$(readlink -f $path) init=$(readlink -f $path/init) $(cat $path/kernel-params)
initrd $initrd initrd $initrd
} }

View file

@ -13,7 +13,7 @@ let
inherit (pkgs) bash; inherit (pkgs) bash;
path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep]; path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep];
inherit (config.boot.loader.grub) copyKernels inherit (config.boot.loader.grub) copyKernels
extraConfig extraEntries extraEntriesBeforeNixOS extraConfig extraEntries extraEntriesBeforeNixOS extraPerEntryConfig
splashImage configurationLimit version default timeout; splashImage configurationLimit version default timeout;
}; };
@ -48,9 +48,12 @@ in
example = "/dev/hda"; example = "/dev/hda";
type = with pkgs.lib.types; uniq string; type = with pkgs.lib.types; uniq string;
description = '' description = ''
The device on which the boot loader, GRUB, will be installed. The device on which the boot loader, GRUB, will be
If empty, GRUB won't be installed and it's your responsibility installed. If empty, GRUB won't be installed and it's your
to make the system bootable. 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 @@ 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 { extraEntries = mkOption {
default = ""; default = "";
example = '' example = ''

View file

@ -30,14 +30,17 @@ if [ "$action" = "switch" -o "$action" = "boot" ]; then
mkdir -m 0700 -p /boot/grub mkdir -m 0700 -p /boot/grub
@menuBuilder@ @out@ @menuBuilder@ @out@
# If the GRUB version has changed, then force a reinstall. if [ "@grubDevice@" != nodev ]; then
oldGrubVersion="$(cat /boot/grub/version 2>/dev/null || true)"
newGrubVersion="@grubVersion@" # 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 if [ "$NIXOS_INSTALL_GRUB" = 1 -o "$oldGrubVersion" != "$newGrubVersion" ]; then
echo "installing the GRUB bootloader..." echo "installing the GRUB bootloader..."
@grub@/sbin/grub-install "@grubDevice@" --no-floppy --recheck @grub@/sbin/grub-install "@grubDevice@" --no-floppy --recheck
echo "$newGrubVersion" > /boot/grub/version echo "$newGrubVersion" > /boot/grub/version
fi
fi fi
else else

View file

@ -291,10 +291,10 @@ echo /sbin/modprobe > /proc/sys/kernel/modprobe
# current root. It also moves the /proc, /sys and /dev mounts over to # current root. It also moves the /proc, /sys and /dev mounts over to
# the new root. Note that $stage2Init might be an absolute symlink, # 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. # 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 if ! test -e "$targetRoot/$stage2Init" -o -L "$targetRoot/$stage2Init"; then
# echo "stage 2 init script ($targetRoot/$stage2Init) not found" echo "stage 2 init script ($targetRoot/$stage2Init) not found"
# fail fail
#fi fi
mkdir -m 0755 -p $targetRoot/proc $targetRoot/sys $targetRoot/dev mkdir -m 0755 -p $targetRoot/proc $targetRoot/sys $targetRoot/dev

View file

@ -2,20 +2,6 @@
with pkgs.lib; 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 = system.build.amazonImage =
pkgs.vmTools.runInLinuxVM ( pkgs.vmTools.runInLinuxVM (
@ -62,10 +48,8 @@ in
mkdir -p /mnt/etc/nixos mkdir -p /mnt/etc/nixos
cp ${./amazon-config.nix} /mnt/etc/nixos/configuration.nix cp ${./amazon-config.nix} /mnt/etc/nixos/configuration.nix
# Amazon uses `pv-grub', which expects a # Generate the GRUB menu.
# /boot/grub/menu.lst. chroot /mnt ${config.system.build.toplevel}/bin/switch-to-configuration boot
mkdir -p /mnt/boot/grub
cp ${grubMenu} /mnt/boot/grub/menu.lst
umount /mnt umount /mnt
'' ''
@ -87,6 +71,11 @@ in
boot.initrd.kernelModules = [ "xen-blkfront" ]; boot.initrd.kernelModules = [ "xen-blkfront" ];
boot.kernelModules = [ "xen-netfront" ]; 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. # There are no virtual consoles.
services.mingetty.ttys = [ ]; services.mingetty.ttys = [ ];