mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-16 02:33:25 +00:00
Add GRUB 2 support.
svn path=/nixos/trunk/; revision=17792
This commit is contained in:
parent
ccd2a0b617
commit
f9541e0d12
@ -5,36 +5,87 @@ shopt -s nullglob
|
||||
export PATH=/empty
|
||||
for i in @path@; do PATH=$PATH:$i/bin; done
|
||||
|
||||
default=$1
|
||||
if test -z "$1"; then
|
||||
echo "Syntax: grub-menu-builder.sh <DEFAULT-CONFIG>"
|
||||
if test $# -ne 1; then
|
||||
echo "Usage: grub-menu-builder.sh DEFAULT-CONFIG"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
grubVersion="@version@"
|
||||
defaultConfig="$1"
|
||||
bootDevice="@bootDevice@"
|
||||
if test -z "$bootDevice"; then bootDevice=/boot; fi
|
||||
|
||||
|
||||
echo "updating the GRUB menu..."
|
||||
case "$grubVersion" in
|
||||
1|2)
|
||||
echo "updating GRUB $grubVersion menu..."
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported GRUB version \`$grubVersion'" >&2
|
||||
echo "Supported versions are \`1' (GRUB Legacy) and \`2' (GRUB 1.9x)." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
target=/boot/grub/menu.lst
|
||||
tmp=$target.tmp
|
||||
prologue() {
|
||||
if test -n "@splashImage@"; then
|
||||
splashLocation="@splashImage@"
|
||||
if test "$grubVersion" -eq 1 ; then
|
||||
# Splash images in /nix/store don't seem to work, so copy them.
|
||||
cp -f $splashLocation /boot/background.xpm.gz
|
||||
splashLocation="$bootDevice/background.xpm.gz"
|
||||
fi
|
||||
fi
|
||||
|
||||
cat > $tmp << GRUBEND
|
||||
case "$grubVersion" in
|
||||
1)
|
||||
cat > "$1" << GRUBEND
|
||||
# Automatically generated. DO NOT EDIT THIS FILE!
|
||||
default 0
|
||||
timeout 5
|
||||
GRUBEND
|
||||
|
||||
|
||||
if test -n "@splashImage@"; then
|
||||
splashLocation=@splashImage@
|
||||
# Splash images in /nix/store don't seem to work, so copy them.
|
||||
cp -f $splashLocation /boot/background.xpm.gz
|
||||
splashLocation="$bootDevice/background.xpm.gz"
|
||||
echo "splashimage $splashLocation" >> $tmp
|
||||
if test -n "@splashImage@"; then
|
||||
echo "splashimage $splashLocation" >> "$1"
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
cat > "$1" <<EOF
|
||||
# Automatically generated. DO NOT EDIT THIS FILE!
|
||||
set default=0
|
||||
set timeout=5
|
||||
if loadfont @grub@/share/grub/unicode.pf2 ; then
|
||||
set gfxmode=640x480
|
||||
insmod gfxterm
|
||||
insmod vbe
|
||||
terminal_output gfxterm
|
||||
fi
|
||||
EOF
|
||||
if test -n "@splashImage@"; then
|
||||
# FIXME: GRUB 1.97 doesn't resize the background image
|
||||
# if it doesn't match the video resolution.
|
||||
cat >> "$1" <<EOF
|
||||
insmod png
|
||||
if background_image $splashLocation ; then
|
||||
set color_normal=black/black
|
||||
set color_highlight=magenta/black
|
||||
else
|
||||
set menu_color_normal=cyan/blue
|
||||
set menu_color_highlight=white/blue
|
||||
fi
|
||||
EOF
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
case "$grubVersion" in
|
||||
1) target="/boot/grub/menu.lst";;
|
||||
2) target="/boot/grub/grub.cfg";;
|
||||
esac
|
||||
|
||||
tmp="$target.tmp"
|
||||
|
||||
prologue "$tmp"
|
||||
|
||||
|
||||
configurationCounter=0
|
||||
@ -94,15 +145,27 @@ addEntry() {
|
||||
local kernel=$(readlink -f $path/kernel)
|
||||
local initrd=$(readlink -f $path/initrd)
|
||||
|
||||
if test "$path" = "$default"; then
|
||||
if test "$path" = "$defaultConfig"; then
|
||||
cp "$kernel" /boot/nixos-kernel
|
||||
cp "$initrd" /boot/nixos-initrd
|
||||
cp "$(readlink -f "$path/init")" /boot/nixos-init
|
||||
cat > /boot/nixos-grub-config <<EOF
|
||||
case "$grubVersion" in
|
||||
1)
|
||||
cat > /boot/nixos-grub-config <<EOF
|
||||
title Emergency boot
|
||||
kernel ${bootDevice:-/boot}/nixos-kernel systemConfig=$(readlink -f "$path") init=/boot/nixos-init $(cat "$path/kernel-params")
|
||||
initrd ${bootDevice:-/boot}/nixos-initrd
|
||||
EOF
|
||||
;;
|
||||
2)
|
||||
cat > /boot/nixos-grub-config <<EOF
|
||||
menuentry "Emergency boot" {
|
||||
linux ${bootDevice:-/boot}/nixos-kernel systemConfig=$(readlink -f "$path") init=/boot/nixos-init $(cat "$path/kernel-params")
|
||||
initrd ${bootDevice:-/boot}/initrd
|
||||
}
|
||||
EOF
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if test -n "@copyKernels@"; then
|
||||
@ -122,12 +185,23 @@ EOF
|
||||
name="$confName $3"
|
||||
fi
|
||||
|
||||
cat >> $tmp << GRUBEND
|
||||
|
||||
case "$grubVersion" in
|
||||
1)
|
||||
cat >> "$tmp" << GRUBEND
|
||||
title $name
|
||||
kernel $kernel systemConfig=$(readlink -f $path) init=$(readlink -f $path/init) $(cat $path/kernel-params)
|
||||
initrd $initrd
|
||||
GRUBEND
|
||||
;;
|
||||
2)
|
||||
cat >> "$tmp" << GRUBEND
|
||||
menuentry "$name" {
|
||||
linux $kernel systemConfig=$(readlink -f $path) init=$(readlink -f $path/init) $(cat $path/kernel-params)
|
||||
initrd $initrd
|
||||
}
|
||||
GRUBEND
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
@ -146,7 +220,7 @@ if test -n "@extraEntriesBeforeNixOS@"; then
|
||||
echo "$extraEntries" >> $tmp
|
||||
fi
|
||||
|
||||
addEntry "NixOS - Default" $default ""
|
||||
addEntry "NixOS - Default" $defaultConfig ""
|
||||
|
||||
if test -z "@extraEntriesBeforeNixOS@"; then
|
||||
echo "$extraEntries" >> $tmp
|
||||
@ -154,7 +228,7 @@ fi
|
||||
|
||||
# Add all generations of the system profile to the menu, in reverse
|
||||
# (most recent to least recent) order.
|
||||
for link in $((ls -d $default/fine-tune/* ) | sort -n); do
|
||||
for link in $((ls -d $defaultConfig/fine-tune/* ) | sort -n); do
|
||||
date=$(stat --printf="%y\n" $link | sed 's/\..*//')
|
||||
addEntry "NixOS - variation" $link ""
|
||||
done
|
||||
|
@ -7,10 +7,13 @@ let
|
||||
grubMenuBuilder = pkgs.substituteAll {
|
||||
src = ./grub-menu-builder.sh;
|
||||
isExecutable = true;
|
||||
grub = if config.boot.loader.grub.version == 1
|
||||
then pkgs.grub
|
||||
else pkgs.grub2;
|
||||
inherit (pkgs) bash;
|
||||
path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep];
|
||||
inherit (config.boot.loader.grub) copyKernels extraEntries extraEntriesBeforeNixOS
|
||||
splashImage bootDevice configurationLimit;
|
||||
splashImage bootDevice configurationLimit version;
|
||||
};
|
||||
|
||||
in
|
||||
@ -30,6 +33,15 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
version = mkOption {
|
||||
default = 1;
|
||||
example = 2;
|
||||
description = ''
|
||||
The version of GRUB to use: <literal>1</literal> for GRUB Legacy
|
||||
(versions 0.9x), or <literal>2</literal> for GRUB 2.
|
||||
'';
|
||||
};
|
||||
|
||||
device = mkOption {
|
||||
default = "";
|
||||
example = "/dev/hda";
|
||||
@ -78,10 +90,17 @@ in
|
||||
};
|
||||
|
||||
splashImage = mkOption {
|
||||
default = pkgs.fetchurl {
|
||||
url = http://www.gnome-look.org/CONTENT/content-files/36909-soft-tux.xpm.gz;
|
||||
sha256 = "14kqdx2lfqvh40h6fjjzqgff1mwk74dmbjvmqphi6azzra7z8d59";
|
||||
};
|
||||
default =
|
||||
if config.boot.loader.grub.version == 1
|
||||
then pkgs.fetchurl {
|
||||
url = http://www.gnome-look.org/CONTENT/content-files/36909-soft-tux.xpm.gz;
|
||||
sha256 = "14kqdx2lfqvh40h6fjjzqgff1mwk74dmbjvmqphi6azzra7z8d59";
|
||||
}
|
||||
# GRUB 1.97 doesn't support gzipped XPMs.
|
||||
else pkgs.fetchurl {
|
||||
url = http://www.gnu.org/graphics/winkler-gnu-blue.png;
|
||||
sha256 = "0y8fvxalwxyid4k438k7c21bnv728qjsb92rqfapsmpv2bcj7f6k";
|
||||
};
|
||||
example = null;
|
||||
description = "
|
||||
Background image used for Grub. It must be a 640x480,
|
||||
@ -124,9 +143,16 @@ in
|
||||
# set at once.
|
||||
system.boot.loader.id = "grub";
|
||||
system.boot.loader.kernelFile = "vmlinuz";
|
||||
|
||||
environment.systemPackages = mkIf config.boot.loader.grub.enable [ pkgs.grub ];
|
||||
|
||||
|
||||
environment.systemPackages =
|
||||
mkIf config.boot.loader.grub.enable
|
||||
(let version = config.boot.loader.grub.version; in
|
||||
assert version != 1 -> version == 2;
|
||||
|
||||
if version == 1
|
||||
then [ pkgs.grub ]
|
||||
else [ pkgs.grub2 ]);
|
||||
|
||||
# and many other things that have to be moved inside this file.
|
||||
|
||||
};
|
||||
|
@ -27,6 +27,7 @@ if test "$action" = "switch" -o "$action" = "boot"; then
|
||||
mkdir -m 0700 -p /boot/grub
|
||||
@menuBuilder@ @out@
|
||||
if test "$NIXOS_INSTALL_GRUB" = 1; then
|
||||
echo "running \`@grub@/sbin/grub-install'..."
|
||||
@grub@/sbin/grub-install "@grubDevice@" --no-floppy --recheck
|
||||
fi
|
||||
else
|
||||
|
@ -110,7 +110,12 @@ let
|
||||
|
||||
# Boot loaders
|
||||
bootLoader = config.system.boot.loader.id;
|
||||
grub = if config.boot.loader.grub.enable then pkgs.grub else null;
|
||||
grub =
|
||||
if config.boot.loader.grub.enable
|
||||
then (if config.boot.loader.grub.version == 1
|
||||
then pkgs.grub
|
||||
else pkgs.grub2)
|
||||
else null;
|
||||
grubDevice = config.boot.loader.grub.device;
|
||||
configurationName = config.boot.loader.grub.configurationName;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user