Skip to content
Snippets Groups Projects
Commit f97462fc authored by Colin Watson's avatar Colin Watson
Browse files

* Merge from Ubuntu:

  - Use grub-probe to convert device names rather than relying on
    device.map.

r62595
parent a763f28f
No related branches found
No related tags found
No related merge requests found
grub-installer (1.51) UNRELEASED; urgency=low
* Merge from Ubuntu:
- Use grub-probe to convert device names rather than relying on
device.map.
-- Colin Watson <cjwatson@debian.org> Mon, 08 Mar 2010 17:40:05 +0000
grub-installer (1.50) unstable; urgency=low
[ Frans Pop ]
......
......@@ -75,126 +75,17 @@ grub_serial_console() {
serial="$(get_serial_console)"
## This is copied from update-grub; we've requested that it be moved
## to a utility or shell library
## TODO: replace this with grub-probe
device_map=$ROOT/boot/grub/device.map
# Usage: convert os_device
# Convert an OS device to the corresponding GRUB drive
# This part is OS-specific
convert () {
## First, check if the device file exists
# if test -e "$1"; then
# :
# else
# echo "$1: Not found or not a block device." 1>&2
# exit 1
# fi
host_os=$(uname -s | tr 'A-Z' 'a-z')
# Break the device name into the disk part and the partition part
case "$host_os" in
linux*)
tmp_disk=$(echo "$1" | sed -e 's%\(\(s\|h\|v\|xv\)d[a-z]\)[0-9]*$%\1%' \
-e 's%\(fd[0-9]*\)$%\1%' \
-e 's%/part[0-9]*$%/disc%' \
-e 's%\(c[0-7]d[0-9]*\).*$%\1%' \
-e 's%\(mmcblk[0-9]d[0-9]*\).*$%\1%' \
-e 's%\(/mapper/mpath[0-9]\+\)-part[0-9]\+$%\1%')
tmp_part=$(echo "$1" | sed -e 's%.*/\(s\|h\|v\|xv\)d[a-z]\([0-9]*\)$%\2%' \
-e 's%.*/fd[0-9]*$%%' \
-e 's%.*/floppy/[0-9]*$%%' \
-e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
-e 's%.*c[0-7]d[0-9]*p*%%' \
-e 's%.*mmcblk[0-9]d[0-9]*p%%' \
-e 's%.*/mapper/mpath[0-9]\+-part\([0-9]\+\)%\1%')
;;
gnu*)
tmp_disk=$(echo "$1" | sed 's%\([sh]d[0-9]*\).*%\1%')
tmp_part=$(echo "$1" | sed "s%$tmp_disk%%")
;;
freebsd*)
tmp_disk=$(echo "$1" | sed 's%r\{0,1\}\([saw]d[0-9]*\).*$%r\1%' | \
sed 's%r\{0,1\}\(da[0-9]*\).*$%r\1%')
tmp_part=$(echo "$1" | \
sed "s%.*/r\{0,1\}[saw]d[0-9]\(s[0-9]*[a-h]\)%\1%" | \
sed "s%.*/r\{0,1\}da[0-9]\(s[0-9]*[a-h]\)%\1%")
;;
netbsd*)
tmp_disk=$(echo "$1" | sed 's%r\{0,1\}\([sw]d[0-9]*\).*$%r\1d%' | \
sed 's%r\{0,1\}\(fd[0-9]*\).*$%r\1a%')
tmp_part=$(echo "$1" | \
sed "s%.*/r\{0,1\}[sw]d[0-9]\([abe-p]\)%\1%")
;;
*)
echo "update-grub does not support your OS yet." 1>&2
exit 1
;;
esac
# Get the drive name
tmp_drive=$(grep -v '^#' $device_map | grep "$tmp_disk *$" | \
sed 's%.*\(([hf]d[0-9][a-g0-9,]*)\).*%\1%')
# If not found, print an error message and exit
if [ -z "$tmp_drive" ]; then
echo "$1 does not have any corresponding BIOS drive." 1>&2
exit 1
fi
if [ -n "$tmp_part" ]; then
# If a partition is specified, we need to translate it into the
# GRUB's syntax
case "$host_os" in
linux*)
echo "$tmp_drive" | sed "s%)$%,`expr $tmp_part - $partition_offset`)%"
;;
gnu*)
if echo $tmp_part | grep "^s" >/dev/null; then
tmp_pc_slice=$(echo $tmp_part | \
sed "s%s\([0-9]*\)[a-g]*$%\1%")
tmp_drive=$(echo "$tmp_drive" | \
sed "s%)%,\`expr "$tmp_pc_slice" - $partition_offset\`)%")
fi
if echo $tmp_part | grep "[a-g]$" >/dev/null; then
tmp_bsd_partition=$(echo "$tmp_part" | \
sed "s%[^a-g]*\([a-g]\)$%\1%")
tmp_drive=$(echo "$tmp_drive" | \
sed "s%)%,$tmp_bsd_partition)%")
fi
echo "$tmp_drive"
;;
freebsd*)
if echo $tmp_part | grep "^s" >/dev/null; then
tmp_pc_slice=$(echo $tmp_part | \
sed "s%s\([0-9]*\)[a-h]*$%\1%")
tmp_drive=$(echo "$tmp_drive" | \
sed "s%)%,\`expr "$tmp_pc_slice" - $partition_offset\`)%")
fi
if echo $tmp_part | grep "[a-h]$" >/dev/null; then
tmp_bsd_partition=$(echo "$tmp_part" | \
sed "s%s\{0,1\}[0-9]*\([a-h]\)$%\1%")
tmp_drive=$(echo "$tmp_drive" | \
sed "s%)%,$tmp_bsd_partition)%")
fi
echo "$tmp_drive"
;;
netbsd*)
if echo $tmp_part | grep "^[abe-p]$" >/dev/null; then
tmp_bsd_partition=$(echo "$tmp_part" | \
sed "s%\([a-p]\)$%\1%")
tmp_drive=$(echo "$tmp_drive" | \
sed "s%)%,$tmp_bsd_partition)%")
fi
echo "$tmp_drive"
;;
esac
else
# If no partition is specified, just print the drive name
echo "$tmp_drive"
tmp_drive="$($chroot $ROOT grub-probe -d -t drive "$1")" || exit $?
if [ "$partition_offset" != 0 ]; then
tmp_part="$(echo "$tmp_drive" | sed 's%.*,\([0-9]*\)).*%\1%')"
if [ "$tmp_part" ] && [ "$tmp_part" != "$tmp_drive" ]; then
tmp_drive="$(echo "$tmp_drive" | sed "s%\(.*,\)[0-9]*\().*\)%\1`expr $tmp_part - $partition_offset`\2%")"
fi
fi
echo "$tmp_drive"
}
# Convert a linux non-devfs disk device name into the hurd's syntax
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment