=== modified file 'debian/changelog' --- debian/changelog 2007-04-27 10:23:24 +0000 +++ debian/changelog 2007-08-21 17:45:46 +0000 @@ -1,3 +1,11 @@ +grub-installer (1.24ubuntu2) UNRELEASED; urgency=low + + * Mark the partition to which GRUB is being installed as bootable, or + failing that the first available primary partition on the disk to which + GRUB is being installed (LP: #14244). + + -- Colin Watson Tue, 21 Aug 2007 18:39:13 +0100 + grub-installer (1.24ubuntu1) gutsy; urgency=low * Resynchronise with Debian. Remaining changes: === modified file 'grub-installer' --- grub-installer 2007-04-27 09:31:33 +0000 +++ grub-installer 2007-08-21 18:35:43 +0000 @@ -223,6 +223,10 @@ fi } +findfs () { + mount | grep "on $ROOT${1%/} " | cut -d' ' -f1 +} + findfstype () { mount | grep "on $ROOT${1%/} " | cut -d' ' -f5 } @@ -479,6 +483,84 @@ fi done +split_device () { + disk= + part= + case $1 in + /dev/[hs]d[a-z]*) + disk="$(echo "$bootdev" | sed 's,\(/dev/[a-z]\+\).*,\1,')" + part="$(echo "$bootdev" | sed 's,/dev/[a-z]\+\(.*\),\1,')" + ;; + /dev/*/c*d*) + disk="$(echo "$bootdev" | sed 's,\(/dev/.*/c[0-9]\+d[0-9]\+\).*,\1,')" + part="$(echo "$bootdev" | sed 's,/dev/.*/c[0-9]\+d[0-9]\+p\([0-9]\+\),\1,')" + [ "$part" != "$bootdev" ] || part= + ;; + esac + echo "$disk $part" +} + +bootdisk= +bootpart= +case $bootdev in + /dev/*) + bootdev_split="$(split_device "$bootdev")" + bootdisk="${bootdev_split%% *}" + bootpart="${bootdev_split#* }" + ;; + \([hf]d[0-9]*\)) + bootdev_nopart="$(echo "$bootdev" | sed 's/,[^)]*//')" + bootdisk="$(grep -v '^#' $device_map | grep "^ *$bootdev_nopart" \ + | sed 's/^ *(.*)[[:space:]]*\(.*\)/\1/')" + bootpart="$(echo "$bootdev" | sed 's/.*,\([^)]*\).*/\1/')" + [ "$bootpart" != "$bootdev" ] || bootpart= + ;; + [hf]d[0-9]*) + # The GRUB format with no parenthesis. + bootdisk="$(grep -v '^#' $device_map | grep "^ *(${bootdev%%,*})" \ + | sed 's/^ *(.*)[[:space:]]*\(.*\)/\1/')" + bootpart="${bootdev#*,}" + [ "$bootpart" != "$bootdev" ] || bootpart= + ;; +esac + +# Make sure that there's *some* active partition; some BIOSes reportedly +# don't like it otherwise. +if [ "$bootdisk" ] && ! fdisk -l "$bootdisk" | grep '^/dev/' | grep -q '\*'; then + if [ -z "$bootpart" ]; then + # bootdev must be set to a disk rather than a partition, or + # we'd already have an active partition due to the previous + # check. Try /boot, if it's on the same disk and is primary. + bootfs="$(findfs /boot)" + [ "$bootfs" ] || bootfs="$(findfs /)" + bootfs="$(mapdevfs "$bootfs")" + bootfs_split="$(split_device "$bootfs")" + bootfs_disk="${bootfs_split%% *}" + bootfs_part="${bootfs_split#* }" + if [ "$bootfs_disk" = "$bootdisk" ] && \ + ([ "$bootfs_part" -ge 1 ] && [ "$bootfs_part" -le 4 ]); then + bootpart="$bootfs_part" + fi + fi + + if [ -z "$bootpart" ]; then + # We don't care at this point; just pick the first primary + # partition that exists. + for pnum in 1 2 3 4; do + if fdisk -l "$bootdisk" | grep -q "^$bootdisk$pnum "; then + bootpart="$pnum" + break + fi + done + fi + + if [ "$bootpart" ]; then + echo -n "I: Setting partition $2 of $1 to active..." >&2 + sfdisk -A"$2" "$1" + echo "done." >&2 + fi +fi + db_progress STEP 1 db_progress INFO grub-installer/progress/step_config_loader