From a751da838ca666064e7cc388ef8c0337467b3a37 Mon Sep 17 00:00:00 2001 From: proski Date: Mon, 11 Feb 2002 08:10:57 +0000 Subject: [PATCH] * util/grub-install.in (find_device): New function - find block device for given file or directory. Resolve symlinks to fix problem on Linux with devfs and old device names in /etc/fstab. Use find_device() for root_device, bootdir_device and grubdir_device. --- ChangeLog | 8 ++++++++ util/grub-install.in | 41 +++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index e42573e55..7f2b10a6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2002-02-11 Pavel Roskin + + * util/grub-install.in (find_device): New function - find block + device for given file or directory. Resolve symlinks to fix + problem on Linux with devfs and old device names in /etc/fstab. + Use find_device() for root_device, bootdir_device and + grubdir_device. + 2002-02-08 Yoshinori K. Okuji * grub/main.c (OPT_NO_PAGER): New macro. diff --git a/util/grub-install.in b/util/grub-install.in index c95c16efb..a04d8bf5e 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -175,6 +175,35 @@ convert () { fi } +# Usage: find_device file +# Find block device on which the file resides. +find_device () { + # For now, this uses the program `df' to get the device name, but is + # this really portable? + tmp_fname=`df $1/ | sed -n 's%.*\(/dev/[^ ]*\).*%\1%p'` + + if test -z "$tmp_fname"; then + echo "Could not find device for $1" 2>&1 + exit 1 + fi + + # Resolve symlinks + while test -L $tmp_fname; do + tmp_new_fname=`ls -al /dev/hda1 | sed -n 's%.*-> %\1%p'` + if test -z "$tmp_new_fname"; then + echo "Unrecognized ls output" 2>&1 + exit 1 + fi + + # Convert relative symlinks + case $tmp_new_fname in + /*) tmp_fname="$tmp_new_fname" ;; + *) tmp_fname="`echo $tmp_fname | sed 's%/[^/]*$%%'`/$tmp_new_fname" ;; + esac + done + echo "$tmp_fname" +} + # Check the arguments. for option in "$@"; do case "$option" in @@ -308,12 +337,8 @@ case "$install_device" in esac # Get the root drive. -# For now, this uses the program `df' to get the device name, but is -# this really portable? -root_device=`df ${rootdir}/ | grep /dev/ \ - | sed 's%.*\(/dev/[^ ]*\).*%\1%'` -bootdir_device=`df ${bootdir} | grep /dev/ \ - | sed 's%.*\(/dev/[^ ]*\).*%\1%'` +root_device=`find_device ${rootdir}` +bootdir_device=`find_device ${bootdir}` # Check if the boot directory is in the same device as the root directory. if test "x$root_device" != "x$bootdir_device"; then @@ -330,8 +355,8 @@ fi # Check if the root directory exists in the same device as the grub # directory. -grubdir_device=`df ${grubdir} | grep /dev/ \ - | sed 's%.*\(/dev/[^ ]*\).*%\1%'` +grubdir_device=`find_device ${grubdir}` + if test "x$grubdir_device" != "x$root_device"; then # For now, cannot deal with this situation. cat <&2