From deb4f88c2c2ec0eeb0c80fbf174d3e670ef5c8da Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 16 Dec 2009 18:57:02 +0000 Subject: [PATCH] * Let the GRUB menu builder detect whether /boot is on a different partition from /. If so, copy the kernels and initrds to /boot and use paths relative to /boot in the GRUB configuration file. This makes the boot.loader.grub.bootDevice option obsolete. (Is there a way to mark obsolete options?) It also makes it unnecessary to set boot.loader.grub.copyKernels, although that option is still available since it can speed up GRUB if the Nix store is very large. svn path=/nixos/trunk/; revision=18998 --- doc/config-examples/root-on-lvm.nix | 13 ++---- modules/installer/grub/grub-menu-builder.sh | 48 ++++++++++++--------- modules/installer/grub/grub.nix | 15 +++---- 3 files changed, 35 insertions(+), 41 deletions(-) diff --git a/doc/config-examples/root-on-lvm.nix b/doc/config-examples/root-on-lvm.nix index 4fd4ca3a65c..2ea1e547921 100644 --- a/doc/config-examples/root-on-lvm.nix +++ b/doc/config-examples/root-on-lvm.nix @@ -1,9 +1,6 @@ # This configuration has / on a LVM volume. Since Grub # doesn't know about LVM, a separate /boot is therefore -# needed. In particular you need to set "copyKernels" -# to tell NixOS to copy kernels and initrds from /nix/store -# to /boot, and "bootMount" to tell Grub the /boot device -# in Grub syntax (e.g. (hd0,0) for /dev/sda1). +# needed. # # In this example, labels are used for file systems and # swap devices: "boot" might be /dev/sda1, "root" might be @@ -12,12 +9,8 @@ # that / is on LVM; that's figured out automatically. { - boot = { - grubDevice = "/dev/sda"; - initrd.kernelModules = ["ata_piix"]; - copyKernels = true; - bootMount = "(hd0,0)"; - }; + boot.loader.grub.device = "/dev/sda"; + boot.initrd.kernelModules = ["ata_piix"]; fileSystems = [ { mountPoint = "/"; diff --git a/modules/installer/grub/grub-menu-builder.sh b/modules/installer/grub/grub-menu-builder.sh index 1cce302fdf0..72ea17875c5 100644 --- a/modules/installer/grub/grub-menu-builder.sh +++ b/modules/installer/grub/grub-menu-builder.sh @@ -12,8 +12,6 @@ fi grubVersion="@version@" defaultConfig="$1" -bootDevice="@bootDevice@" -if test -z "$bootDevice"; then bootDevice=/boot; fi case "$grubVersion" in 1|2) @@ -27,6 +25,20 @@ case "$grubVersion" in esac +# Discover whether /boot is on the same filesystem as /. If not, then +# all kernels and initrds must be copied to /boot, and all paths in +# the GRUB config file must be relative to the root of the /boot +# filesystem. `$bootRoot' is the path to be prepended to paths under +# /boot. +if [ "$(stat -f -c '%i' /)" = "$(stat -f -c '%i' /boot)" ]; then + bootRoot=/boot + copyKernels="@copyKernels@" # user can override in the NixOS config +else + bootRoot= + copyKernels=1 +fi + + prologue() { case "$grubVersion" in 1) @@ -37,7 +49,7 @@ default @default@ timeout @timeout@ GRUBEND if test -n "@splashImage@"; then - echo "splashimage $bootDevice/background.xpm.gz" >> "$1" + echo "splashimage $bootRoot/background.xpm.gz" >> "$1" fi ;; 2) @@ -46,7 +58,7 @@ GRUBEND # Automatically generated. DO NOT EDIT THIS FILE! set default=@default@ set timeout=@timeout@ -if loadfont $bootDevice/grub/unicode.pf2; then +if loadfont $bootRoot/grub/unicode.pf2; then set gfxmode=640x480 insmod gfxterm insmod vbe @@ -59,7 +71,7 @@ EOF # if it doesn't match the video resolution. cat >> "$1" < /boot/nixos-grub-config < /boot/nixos-grub-config </dev/null) if test -n "$confName"; then name="$confName $3" fi @@ -199,7 +205,7 @@ GRUBEND } -if test -n "@copyKernels@"; then +if test -n "$copyKernels"; then mkdir -p /boot/kernels fi diff --git a/modules/installer/grub/grub.nix b/modules/installer/grub/grub.nix index 0939abd6e18..e3df1593e71 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 extraEntries extraEntriesBeforeNixOS - splashImage bootDevice configurationLimit version default timeout; + splashImage configurationLimit version default timeout; }; in @@ -53,15 +53,10 @@ in ''; }; + # !!! How can we mark options as obsolete? bootDevice = mkOption { default = ""; - example = "(hd0,0)"; - description = '' - If the system partition may be wiped on reinstall, it is better - to have /boot on a small partition. To do it, we need to explain - to GRUB where the kernels live. Specify the partition here (in - GRUB notation). - ''; + description = "Obsolete."; }; configurationName = mkOption { @@ -121,8 +116,8 @@ in default = false; description = '' Whether the GRUB menu builder should copy kernels and initial - ramdisks to /boot. This is necessary when /nix is on a - different file system than /boot. + ramdisks to /boot. This is done automatically if /boot is + on a different partition than /. ''; };