* 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:
parent
3a0f295337
commit
d659488209
@ -159,17 +159,17 @@ addEntry() {
|
||||
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 @@ EOF
|
||||
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 @@ 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
|
||||
}
|
||||
|
@ -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 <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 {
|
||||
default = "";
|
||||
example = ''
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 = [ ];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user