From 81d6032c43bee2400106e1d151cd002b0aaa9d5c Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Mon, 18 May 2009 12:01:31 +0000 Subject: [PATCH] Synced with trunk @ 15505 svn path=/nixos/branches/modular-nixos/; revision=15640 --- installer/grub-menu-builder.sh | 101 +++++++++++++++++++----------- system/switch-to-configuration.sh | 6 +- 2 files changed, 69 insertions(+), 38 deletions(-) diff --git a/installer/grub-menu-builder.sh b/installer/grub-menu-builder.sh index 72635c364335..464fc94ce22c 100644 --- a/installer/grub-menu-builder.sh +++ b/installer/grub-menu-builder.sh @@ -15,6 +15,9 @@ bootMount="@bootMount@" if test -z "$bootMount"; then bootMount=/boot; fi +echo "updating the Grub menu..." + + target=/boot/grub/menu.lst tmp=$target.tmp @@ -27,14 +30,13 @@ GRUBEND if test -n "@grubSplashImage@"; then splashLocation=@grubSplashImage@ - # !!! image in /nix/store doesn't seem to work - #if test -n "@copyKernels@"; then - cp -f $splashLocation /boot/background.xpm.gz - splashLocation="$bootMount/background.xpm.gz" - #fi + # Splash images in /nix/store don't seem to work, so copy them. + cp -f $splashLocation /boot/background.xpm.gz + splashLocation="$bootMount/background.xpm.gz" echo "splashimage $splashLocation" >> $tmp fi + configurationCounter=0 configurationLimit="@configurationLimit@" numAlienEntries=`cat <-/file to --. +cleanName() { + local path="$1" + echo "$path" | sed 's|^/nix/store/||' | sed 's|/|-|g' +} + + +# Copy a file from the Nix store to /boot/kernels. +declare -A filesCopied + +copyToKernelsDir() { + local src="$1" + local dst="/boot/kernels/$(cleanName $src)" + # Don't copy the file if $dst already exists. This means that we + # have to create $dst atomically to prevent partially copied + # kernels or initrd if this script is ever interrupted. + if ! test -e $dst; then + local dstTmp=$dst.tmp.$$ + cp $src $dstTmp + mv $dstTmp $dst + fi + filesCopied[$dst]=1 + result=$dst +} + + +# Add an entry for a configuration to the Grub menu, and if +# appropriate, copy its kernel and initrd to /boot/kernels. addEntry() { local name="$1" local path="$2" local shortSuffix="$3" configurationCounter=$((configurationCounter + 1)) - if test $configurationCounter -gt @configurationLimit@ ; then - return - fi; + if test $configurationCounter -gt @configurationLimit@; then + return + fi if ! test -e $path/kernel -a -e $path/initrd; then return @@ -63,10 +95,10 @@ addEntry() { local initrd=$(readlink -f $path/initrd) if test "$path" = "$default"; then - cp "$kernel" /boot/nixos-kernel - cp "$initrd" /boot/nixos-initrd - cp "$(readlink -f "$path/init")" /boot/nixos-init - cat > /boot/nixos-grub-config < /boot/nixos-grub-config <> $tmp << GRUBEND @@ -108,11 +131,11 @@ GRUBEND } -rm -rf /boot/kernels if test -n "@copyKernels@"; then mkdir -p /boot/kernels fi + # Additional entries specified verbatim by the configuration. extraGrubEntries=`cat <