grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] prevent duplicated entries due to symlinks


From: Andreas Born
Subject: [PATCH] prevent duplicated entries due to symlinks
Date: Fri, 01 May 2009 22:51:10 +0200
User-agent: Thunderbird 2.0.0.21 (X11/20090325)

If there's both a symlink and a kernel at which the symlink is pointing in the list of detected kernels of 10_linux, two entries are created for actually the same kernel. This patch checks for this condition and only uses the symlink (usually the wanted behaviour), in case the target of the symlink doesn't exist, it uses neither.

Furthermore there may be kernel images named e.g. /boot/vmlinuz, so to detect those the patch doesn't require a hyphen in the kernel name. In this case the sed used to determine the kernel version, won't return as expected an empty string. Therefore I replaced it by another one with the wanted behaviour. If the kernel version can be empty we don't want to have a "GNU/Linux, linux " menuentry. Accordingly this patch adds a check for empty kernel version, so that only "GNU/Linux" will be displayed.

Finally there's quite a bunch of other names for initrds. This patch adds support for initrd.gz and initrd.splash. Both initrd.img and initrd.gz become or were yet supported with two different version positions and without version at all. For initrd.splash this isn't needed because it's not kernel version dependent.

This is my first contribution and although I tried to inform myself as good as possible and double-checked everything, I could have missed something to you probably obvious. If there are any such problems, let me know, I'll do my best to get it sorted out.

Andreas

diff --git a/ChangeLog b/ChangeLog
index 9097f25..ddf1c3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-05-01  Andreas Born  <address@hidden>
+
+    * util/grub.d/10_linux.in: Prevent duplicated entries because both
+       symlink and symlinked kernel are detected, only use the symlink
+       then. Detect also kernels without a hyphen in a name and use an
+       empty version for those kernels. Don't display linux <kernelver> in
+       the     menuentry title if version is empty. Detect more initrds e.g.
+       initrd.gz.
+
 2009-04-30  David S. Miller  <address@hidden>
 
        * util/hostdisk.c (device_is_wholedisk): New function.
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index c2da413..66768eb 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -112,9 +112,18 @@ EOF
 EOF
 }
 
-list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do
+list=`for i in /boot/vmlinu[xz]* /vmlinu[xz]* ; do
         if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
       done`
+for i in $list ; do
+  if test -h $i ; then
+    target="`readlink -f $i`"
+    list=`echo $list | tr ' ' '\n' | grep -vx $target | tr '\n' ' '`
+    if test ! -f $target ; then
+      list=`echo $list | tr ' ' '\n' | grep -vx $i | tr '\n' ' '`
+    fi
+  fi
+done
 
 while [ "x$list" != "x" ] ; do
   linux=`find_latest $list`
@@ -122,13 +131,16 @@ while [ "x$list" != "x" ] ; do
   basename=`basename $linux`
   dirname=`dirname $linux`
   rel_dirname=`make_system_path_relative_to_its_root $dirname`
-  version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
+  version=`echo $basename | sed -e "s,^[^\-]*-*,,"`
   alt_version=`echo $version | sed -e "s,\.old$,,g"`
   linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
 
   initrd=
   for i in "initrd.img-${version}" "initrd-${version}.img" \
-          "initrd.img-${alt_version}" "initrd-${alt_version}.img"; do
+       "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
+       "initrd.gz-${version}" "initrd-${version}.gz" \
+       "initrd.gz-${alt_version}" "initrd-${alt_version}.gz" \
+       "initrd.img" "initrd.gz" "initrd.splash"; do
     if test -e "${dirname}/${i}" ; then
       initrd="$i"
       break
@@ -140,10 +152,16 @@ while [ "x$list" != "x" ] ; do
     # "UUID=" magic is parsed by initrds.  Since there's no initrd, it can't 
work here.
     linux_root_device_thisversion=${GRUB_DEVICE}
   fi
+  
+  if test -n "${version}" ; then
+    title="${OS}, linux ${version}"
+  else
+    title="${OS}"
+  fi
 
-  linux_entry "${OS}, linux ${version}" \
+  linux_entry "${title}" \
       "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
-  linux_entry "${OS}, linux ${version} (recovery mode)" \
+  linux_entry "${title} (recovery mode)" \
       "single ${GRUB_CMDLINE_LINUX}"
 
   list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`

reply via email to

[Prev in Thread] Current Thread [Next in Thread]