All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Born <futur.andy@googlemail.com>
To: GRUB2 Devel <grub-devel@gnu.org>
Subject: [PATCH] prevent duplicated entries due to symlinks
Date: Fri, 01 May 2009 22:51:10 +0200	[thread overview]
Message-ID: <49FB60BE.7090806@googlemail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1438 bytes --]

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


[-- Attachment #2: 10_linux.diff --]
[-- Type: text/plain, Size: 2837 bytes --]

diff --git a/ChangeLog b/ChangeLog
index 9097f25..ddf1c3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-05-01  Andreas Born  <futur.andy@googlemail.com>
+
+    * 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  <davem@davemloft.net>
 
 	* 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	other threads:[~2009-05-01 20:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-01 20:51 Andreas Born [this message]
2009-05-04  4:32 ` [PATCH] prevent duplicated entries due to symlinks Pavel Roskin
2009-05-04 16:45   ` Andreas
2009-05-04 21:13     ` Pavel Roskin
2009-05-05 21:11       ` Andreas Born
2009-05-09 22:20         ` Andreas
2009-08-18 18:01           ` Pavel Roskin
2009-08-18 19:19     ` Michal Suchanek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49FB60BE.7090806@googlemail.com \
    --to=futur.andy@googlemail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.