diff --git a/rpm/extlinux-config b/rpm/extlinux-config index 31ef37f..a93e21b 100755 --- a/rpm/extlinux-config +++ b/rpm/extlinux-config @@ -30,7 +30,7 @@ show_help() { print_version() { cat <<-EOF - $PROG version 2.0 + $PROG version 2.1 Written by Alexey Gladkov. Copyright (C) 2010-2012 Alexey Gladkov @@ -40,6 +40,13 @@ print_version() { exit } +read_gpt() { + local offset=$(($1 + 512)) len=${2:-1} + local x=$(dd if="$dev" bs=1 skip=$offset count=$len 2>/dev/null | od -A n -t u$len) + echo "${x// /}" +} + + GETOPT_ALLOW_UNKNOWN=1 TEMP=`getopt -n $PROG -o b:,d,r:,v,V,h -l boot:,dry-run,root:,verbose,version,help -- "$@"` || show_help @@ -86,26 +93,40 @@ sysfs_path="$(readlink -ev "/sys/dev/block/$boot_majmin" 2>/dev/null)" || read partition < "$sysfs_path/partition" dev="$(sed -n -e 's,^DEVNAME=,/dev/,p' "${sysfs_path%/*}/uevent")" -partition_table="$(LANG=C parted -ms "$dev" print | grep ^/ |cut -d: -f6)" + +magic="$(dd if="$dev" bs=2 skip=255 count=1 2>/dev/null)" +[ "$magic" = $'\x55\xAA' ] || + fatal "Unknown partition table" + +magic="$(dd if="$dev" bs=8 skip=64 count=1 2>/dev/null)" +if [ "$magic" != "EFI PART" ]; then + partition_table='msdos' + magic=4 +else + partition_table='gpt' + magic=$(read_gpt 80 4) +fi verbose "Partition table: $partition_table" -case "$partition_table" in - gpt) - mbr_bin='gptmbr.bin' - flag='legacy_boot' - ;; - msdos) - mbr_bin='mbr.bin' - flag='boot' - ;; - *) fatal "Unknown partition table: $partition_table" ;; -esac - -bootflags="$(LANG=C parted -ms "$dev" print | grep "^$partition:" |cut -d: -f7)" - -[ -z "${bootflags##*$flag*}" ] || - fatal "partiton not bootable" +[ $partition -ge 1 -a $partition -le $magic ] || + fatal "invalid partition number" + +if [ "$partition_table" = "msdos" ]; then + magic=$(($((partition - 1)) * 16 + 446)) + magic="$(dd if="$dev" bs=1 skip=$magic count=1 2>/dev/null)" + [ "$magic" = $'\x80' ] || + fatal "partiton not bootable" + mbr_bin='mbr.bin' +else + entry_size=$(read_gpt 84 4) + magic=$(($((partition - 1)) * $entry_size + 552)) + magic="$(read_gpt $magic)" + magic=$((magic & 2)) + [ "$magic" = "2" ] || + fatal "partiton not bootable" + mbr_bin='gptmbr.bin' +fi DEVNAME= dir="$(readlink -m "$ROOTDIR/")" diff --git a/rpm/extlinux.spec b/rpm/extlinux.spec index 5fe1fe9..37fa343 100644 --- a/rpm/extlinux.spec +++ b/rpm/extlinux.spec @@ -1,7 +1,7 @@ Summary: The EXTLINUX bootloader, for booting the local system. Name: extlinux Version: 6.03 -Release: alt1 +Release: alt2 License: GPL2 Group: System/Base Url: http://www.syslinux.org/wiki/index.php/The_Syslinux_Project @@ -15,7 +15,7 @@ Source4: extlinux.filetrigger BuildRequires: libe2fs-devel libuuid-devel nasm -Requires: libshell util-linux parted +Requires: libshell util-linux Conflicts: syslinux-extlinux Obsoletes: syslinux4-extlinux @@ -100,6 +100,9 @@ ln -s ../boot/extlinux/extlinux.conf.d . %doc sample %changelog +* Fri Mar 16 2017 Leonid Krivoshein 6.03-alt2 +- Removed dependency to parted (ALT#34481). + * Tue Dec 26 2017 Alexey Gladkov 6.03-alt1 - New release (6.03).