commit 032ee960df920d3f8b77f8ec44e5009cd321ea74 Author: Christoph Gysin Date: Mon Sep 14 22:19:06 2015 +0300 syslinux: fix extracting disk part from partition Partitions like /dev/mmcblk0p1 were not handled correctly. This extracts the logic to a function get_disk(), and uses it where needed. fixes bug #46242 diff --git a/syslinux/trunk/syslinux-install_update b/syslinux/trunk/syslinux-install_update index ef2c6d7..754bfa9 100644 --- a/syslinux/trunk/syslinux-install_update +++ b/syslinux/trunk/syslinux-install_update @@ -51,6 +51,28 @@ check_is_in() { return 1 } +get_disk() { + local part=$1 + if [[ -b "${part}" ]]; then + echo >&2 "error: '$part' is not a valid block device!" + exit 1 + fi + + case "$part" in + *[[:digit:]]p[[:digit:]]*) + local disk="${part%%p$partnum}" # get everything before p1 + ;; + *) + local disk="${part%%[[:digit:]]*}" + ;; + esac + if [[ -b "${disk}" ]]; then + echo >&2 "error: '$disk' is not a valid block device!" + exit 1 + fi + echo $disk +} + # return true when blockdevice is an md raid, otherwise return a unset value # get all devices that are part of raid device $1 device_is_raid() { @@ -194,12 +216,14 @@ get_boot_devices() { slaves=$(mdraid_all_slaves "$bootpart") for slave in ${slaves[@]}; do - local disk="${slave%%[[:digit:]]*}" + local disk + disk=$(get_disk "$slave") device_is_gpt "$disk" && local ptb="GPT" || local ptb="MBR" bootdevs[$slave]="$ptb" done else - local disk="${bootpart%%[[:digit:]]*}" + local disk + disk=$(get_disk "$bootpart") device_is_gpt "$disk" && local ptb="GPT" || local ptb="MBR" bootdevs[$bootpart]="$ptb" fi @@ -220,7 +244,8 @@ set_active() { for dev in "${!bootdevs[@]}"; do local ptb="${bootdevs[$dev]}" if [[ "$ptb" = GPT ]]; then - local disk="${dev%%[[:digit:]]*}" #ex: /dev/sda + local disk + disk=$(get_disk "$dev") clear_gpt_attr2 "$disk" fi done @@ -229,14 +254,8 @@ set_active() { for part in "${!bootdevs[@]}"; do local ptb="${bootdevs[$part]}" local partnum="${part##*[[:alpha:]]}" - case "$part" in - *[[:digit:]]p[[:digit:]]*) - local disk="${part%%p$partnum}" # get everything before p1 - ;; - *) - local disk="${part%%[[:digit:]]*}" - ;; - esac + local disk + disk=$(get_disk "$part") if [[ "$ptb" = MBR ]]; then if sfdisk "$disk" --activate "$partnum" &>/dev/null; then @@ -271,14 +290,8 @@ install_mbr() { for part in "${!bootdevs[@]}"; do local partnum="${part##*[[:alpha:]]}" - case "$part" in - *[[:digit:]]p[[:digit:]]*) - local disk="${part%%p$partnum}" # get everything before p1 - ;; - *) - local disk="${part%%[[:digit:]]*}" - ;; - esac + local disk + disk=$(get_disk "$part") local ptb="${bootdevs[$part]}" # We want to install to the root of the block device