v1 -> v2: - Fixed changelog entry and commit message - used existing functions instead of introducing die() - removed unnecessary and not-reachable code parts in nw_select_offs_part()
--- debian/changelog | 1 + debian/grub-installer.templates | 19 ++++++++ grub-installer | 104 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) diff --git a/debian/changelog b/debian/changelog index 6f52346..c19f183 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,7 @@ grub-installer (1.147) UNRELEASED; urgency=medium [ Frank Scheiner ] * Query force-efi-extra-removable only when installing grub-efi* * Install hfsutils in-target for powerpc/ppc64 newworld targets + * Detect and select newworld bootstrap partitions -- Frank Scheiner <frank.schei...@web.de> Thu, 16 Nov 2017 07:20:38 +0100 diff --git a/debian/grub-installer.templates b/debian/grub-installer.templates index 5f82c04..0c0b7f9 100644 --- a/debian/grub-installer.templates +++ b/debian/grub-installer.templates @@ -1,3 +1,22 @@ +Template: grub-installer/nopart_newworld +Type: error +# :sl4: +_Description: No NewWorld boot partition found + No hard disks were found which have a "NewWorld boot partition". + You must create a 10-Megabyte partition of type "NewWorld boot partition". + +Template: grub-installer/bootdev_newworld +Type: select +Choices: ${DEVICES} +Default: invaliddevice +# :sl4: +_Description: Device for boot loader installation: + GRUB needs to be installed on a "NewWorld boot partition" in order for + your system to be bootable. Please choose the destination partition + from among these partitions that have the bootable flag set. + . + Warning: this will erase all data on the selected partition! + Template: grub-installer/apt_install_hfsutils Type: text # :sl2: diff --git a/grub-installer b/grub-installer index eb4d853..10cce04 100755 --- a/grub-installer +++ b/grub-installer @@ -37,6 +37,108 @@ debug () { [ -z "${DEBCONF_DEBUG}" ] || log "debug: $@" } +# taken from yaboot-installer +partitions_with_flag () { + /usr/lib/partconf/find-partitions --colons --flag "$1" 2>/dev/null || true +} + +# taken and adapted from yaboot-installer's `postinst` script +# nw is short for NewWorld +nw_select_offs_part() +{ + local self="nw_select_offs_part" + + # Find the boot partition + + # Telling parted to create an Apple_Bootstrap partition doesn't work as well + # as we might like: parted's probe function isn't intelligent enough to know + # about this, and reports the partition as containing whatever filesystem + # was there beforehand. + # + # As a workaround, we only check for partitions with the boot flag set, and + # don't bother checking the filesystem. However, this means that we *must* + # ask the user to confirm the bootstrap partition, otherwise we might + # mistakenly overwrite some other partition that happened to be flagged as + # bootable. + + PARTITIONS= + DEFAULT= + bootdev_priority=critical + + if db_get partman-newworld/boot_partitions && [ "$RET" ]; then + OLDIFS="$IFS" + IFS=, + for part in $RET; do + IFS="$OLDIFS" + mappart="$(mapdevfs "$part")" + if [ -z "$PARTITIONS" ]; then + DEFAULT="$mappart" + PARTITIONS="$mappart" + else + PARTITIONS="$PARTITIONS, $mappart" + fi + IFS=, + done + IFS="$OLDIFS" + info "$self: partman-supplied bootstrap partitions: $PARTITIONS" + info "$self: partman-supplied default bootstrap partition: $DEFAULT" + if [ "$PARTITIONS" ] && [ "$DEFAULT" = "$PARTITIONS" ]; then + # We have explicit information from partman-newworld that only one + # bootstrap partition is available, so it's safe to bypass this + # question. + bootdev_priority=medium + fi + fi + + if [ -z "$PARTITIONS" ]; then + PARTED_FLAGS='boot' + for part in $(partitions_with_flag "$flag" | cut -d: -f1); do + mappart="$(mapdevfs "$part")" + if [ -z "$PARTITIONS" ]; then + DEFAULT="$mappart" + PARTITIONS="$mappart" + else + PARTITIONS="$PARTITIONS, $mappart" + fi + done + if [ "$PARTED_FLAGS" ]; then + info "$self: guessed bootstrap partitions: $PARTITIONS" + info "$self: guessed default bootstrap partition: $DEFAULT" + fi + fi + + if [ "$PARTED_FLAGS" ] && [ -z "$PARTITIONS" ]; then + # error: no viable boot partitions found; fall over + error 'No NewWorld bootstrap partitions found' 1>&2 + db_input critical grub-installer/nopart_newworld || [ $? -eq 30 ] + db_go || true + db_progress STOP + exit 1 + fi + + if [ "$PARTITIONS" ]; then + db_subst grub-installer/bootdev_newworld DEVICES "$PARTITIONS" + db_set grub-installer/bootdev_newworld "$DEFAULT" + db_input "$bootdev_priority" grub-installer/bootdev_newworld || [ $? -eq 30 ] + if ! db_go; then + db_progress STOP + exit 10 # back up to menu + fi + db_get grub-installer/bootdev_newworld + if [ "$RET" = false ]; then + error 'No bootstrap partition selected (?)' 1>&2 + db_input critical grub-installer/nopart_newworld || [ $? -eq 30 ] + db_go || true + db_progress STOP + exit 1 + fi + # already devfs-mapped + boot="$RET" + fi + + echo "$boot" + return 0 +} ARCH="$(archdetect)" info "architecture: $ARCH" @@ -239,6 +341,7 @@ case $ARCH in ppc64/chrp|ppc64/chrp_rs6k|ppc64/chrp_ibm|ppc64/cell) ;; powerpc/powermac_newworld|ppc64/powermac_newworld) + info "$ARCH selected." if ! apt-install hfsutils; then error "Calling 'apt-install hfsutils' failed" 1>&2 # Hm, unable to install hfsutils into /target/, what should we do? @@ -253,6 +356,7 @@ case $ARCH in exit 1 fi fi + offs_part=$( nw_select_offs_part ) offs=$(findfs /boot/grub) [ -n "$offs" ] || error "GRUB requires that the OF partition is mounted in /boot/grub" 1>&2 ;; -- 1.9.1