[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Resolving symllinks in grub-install
From: |
Pavel Roskin |
Subject: |
Resolving symllinks in grub-install |
Date: |
Fri, 8 Feb 2002 18:32:00 -0500 (EST) |
Hello!
I tried to install GRUB (fresh from CVS) on a system which has a
kernel with devfs but uses old-style names in /etc/fstab (/dev/hda1 and so
on). I had no problems with that system except that GRUB refused to
install on it.
It turns out that "df" (from fileutils-4.1) behaves inconsistently
dependent on the arguments - sometimes it returns the symlink name,
sometimes the full name.
This patch fixes the problem by resolving symlinks. A new function,
resolve_links() takes a variable name as an argument. It takes the
filename from the variable, resolves it until it becomes a real file, not
a symlink, and puts the result to the same variable.
I was able to install GRUB on that system after applying this patch.
If anybody wants, I can go one step further to include "df" into that
function, making it a function to determine the block device for the given
file.
==================================
--- ChangeLog
+++ ChangeLog
@@ -1 +1,8 @@
+2002-02-08 Pavel Roskin <address@hidden>
+
+ * util/grub-install.in (resolve_links): New function to resolve
+ symlinks. Use it for root_device, bootdir_device and
+ grubdir_device to fix comparing them on Linux with devfs and old
+ names in /etc/fstab.
+
2002-02-08 Yoshinori K. Okuji <address@hidden>
--- util/grub-install.in
+++ util/grub-install.in
@@ -175,6 +175,30 @@
fi
}
+# Usage: resolve_links variable
+# Resolve symbolic link, make the filename absolute.
+# "variable" holds the filename to be resolved (on input and output).
+resolve_links () {
+ var="$1"
+ eval "fname=\$$var"
+
+ # Normalize filename
+ case $fname in
+ /*) ;;
+ *) fname="`pwd`/$fname"
+ esac
+
+ while test -h $fname; do
+ new_fname=`readlink $fname`
+ # Convert relative symlinks
+ case $new_fname in
+ /*) fname="$new_fname" ;;
+ *) fname="`echo $fname | sed 's%/[^/]*$%%'`/$new_fname" ;;
+ esac
+ done
+ eval "$var=$fname"
+}
+
# Check the arguments.
for option in "$@"; do
case "$option" in
@@ -315,6 +339,9 @@
bootdir_device=`df ${bootdir} | grep /dev/ \
| sed 's%.*\(/dev/[^ ]*\).*%\1%'`
+resolve_links root_device
+resolve_links bootdir_device
+
# Check if the boot directory is in the same device as the root directory.
if test "x$root_device" != "x$bootdir_device"; then
# Perhaps the user has a separate boot partition.
@@ -332,6 +359,9 @@
# directory.
grubdir_device=`df ${grubdir} | grep /dev/ \
| sed 's%.*\(/dev/[^ ]*\).*%\1%'`
+
+resolve_links grubdir_device
+
if test "x$grubdir_device" != "x$root_device"; then
# For now, cannot deal with this situation.
cat <<EOF 1>&2
==================================
--
Regards,
Pavel Roskin
- Resolving symllinks in grub-install,
Pavel Roskin <=