- echo "Adjusting grub configuration for use on ${GROOT}."
-
- # copy stage-files to /boot/grub/
- [ -d /boot/grub/ ] || mkdir /boot/grub
- # i386 specific:
- [ -d /usr/lib/grub/i386-pc ] && cp /usr/lib/grub/i386-pc/* /boot/grub/
- # amd64 specific:
- [ -d /usr/lib/grub/x86_64-pc ] && cp /usr/lib/grub/x86_64-pc/* /boot/grub/
- # sarge ships grub files in another directory
- [ "$RELEASE" = 'sarge' ] && cp /lib/grub/i386-pc/* /boot/grub/
-
- # finally install grub
- if [ -x /usr/sbin/update-grub ] ; then
- UPDATEGRUB='/usr/sbin/update-grub'
- else
- UPDATEGRUB='/sbin/update-grub'
- fi
- $UPDATEGRUB -y
- if [ -f /boot/grub/menu.lst ] ; then
- sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
- if [ -n "$TARGET_UUID" ] ; then
- sed -i "s|^# kopt=root=.*|# kopt=root=UUID=${TARGET_UUID} ro ${BOOT_APPEND}|g" /boot/grub/menu.lst
- else
- sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro ${BOOT_APPEND}|g" /boot/grub/menu.lst
- fi
- # not sure why savedefault does not work for me; any ideas?
- sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
- $UPDATEGRUB -y
- fi
+ GRUB_PACKAGE=grub-pc
+ fi
+
+ # make sure this is pre-defined so we have sane settings for automated
+ # upgrades, see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=711019
+ echo "Setting ${GRUB_PACKAGE} debconf configuration for install device to $GRUB"
+ echo "${GRUB_PACKAGE} ${GRUB_PACKAGE}/install_devices multiselect $GRUB" | debconf-set-selections
+
+ if ! dpkg --list ${GRUB_PACKAGE} 2>/dev/null | grep -q '^ii' ; then
+ echo "Notice: grub option set but no ${GRUB_PACKAGE} package, installing it therefore."
+ DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL ${GRUB_PACKAGE}
+ fi
+
+ if ! [ -x "$(command -v grub-install)" ] ; then
+ echo "Error: grub-install not available. (Error while installing grub package?)" >&2
+ return 1
+ fi
+
+ if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
+ for device in $SELECTED_PARTITIONS ; do
+ GRUB="${device%%[0-9]}"
+ echo "Installing grub on ${GRUB}:"
+ grub-install --no-floppy "$GRUB"
+ done
+ rm -f /boot/grub/device.map
+ else
+ echo "Installing grub on ${GRUB}:"
+ case "$RELEASE" in
+ lenny|squeeze|wheezy)
+ grub-install --no-floppy "$(readlink -f "${GRUB}")"
+ rm -f /boot/grub/device.map
+ ;;
+ *)
+ echo "(hd0) ${GRUB}" > /boot/grub/device.map
+ grub-install "(hd0)"
+ rm /boot/grub/device.map
+ ;;
+ esac
+ fi
+
+ echo "Adjusting grub configuration for use on ${GRUB}."
+
+ # finally install grub
+ if [ -x /usr/sbin/update-grub ] ; then
+ UPDATEGRUB='/usr/sbin/update-grub'
+ elif [ -x /sbin/update-grub ] ; then
+ UPDATEGRUB='/sbin/update-grub'
+ else
+ echo "Error: update-grub not available, can not execute it." >&2
+ return 1