All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Born <futur.andy@googlemail.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH] prevent duplicated entries due to symlinks
Date: Tue, 05 May 2009 23:11:00 +0200	[thread overview]
Message-ID: <4A00AB64.3040904@googlemail.com> (raw)
In-Reply-To: <1241471594.9047.28.camel@mj>

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

Pavel Roskin schrieb:
> Suppose I have Linux 2.6.29 and 2.6.28.  Your script makes entries for
> "Linux default" and "Linux 2.6.28".  Then I install Linux 2.6.30 and
> don't run grub-mkconfig.  Then I can boot Linux 2.6.30 and 2.6.28 form
> the menu, but not 2.6.29.
>
> Even if I run grub-mkconfig, there is still something I lose.  By
> selecting "Linux default" I still don't know it it's Linux 2.6.30 or
> something else.
>
> For me, the convenience of not having to rerun grub-mkconfig doesn't
> outweigh the convenience of knowing what I'm loading.
>
> I know, it's have to argue about preferences, but if you want you
> changes to be accepted, you need to present a good case.
>   
It's also that kind of discussion which eventually separates the wheat 
from the chaff. Thus I welcome it.
> I would consider placing the kernel pointed to by the vmlinuz link to
> the first position of the Linux kernels.  Another approach would be to
> have an entry for the link without suppressing any versioned entries.
>   
Ok, I understand and if it is a preference why don't make it a 
preference. :)
You can find attached a new version of the patch, which per default will 
read the symlink and create an entry for the target, not the symlink. 
You can change this behaviour with "GRUB_USE_LINUX_SYMLINK=yes". If you 
define this environment variable with that value, it will use the 
behaviour I implemented before. This means it uses the symlink and 
ignores the kernel the symlink is currently pointing at.
I think this is the best solution, because it prevents duplicated 
entries (only one entry for symlink or symlink target) and it gives the 
user the choice which behaviour he wants (rerun of grub-mkconfig needed 
or not needed).
Is that solution all right?

>>> Please specify where those names are used.  Can you give the
>>> distribution name and version where such names are used?
>>>   
>>>       
>> Zenwalk, Slackware for example. I think more Slackware derivates are 
>> using it too.
>>     
>
> Let's add support for more versioned names first.  That should be rather
> non-controversial.
I see no more versioned names which could be added for the existing 
extension(s). There is initrd-<version>.<ext> and 
initrd.<ext>-<version>. Whereas <version> can either be $version or 
$alt_version and <ext> can be "img" or "gz" ("gz" is new) and at the 
very end as a last resort initrd.img initrd.gz and initrd.splash are 
tried in that order (that's also new). Roughly speaking only new 
fallback options.
Do you see a problem there or do you have a concrete versioned name to add?

Andreas

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

diff --git a/ChangeLog b/ChangeLog
index 2203b68..f1606ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -0,0 +1,12 @@
+2009-05-05  Andreas Born  <futur.andy@googlemail.com>
+
+    * util/grub.d/10_linux.in: Prevent duplicated entries because both
+    symlink and symlinked kernel are detected.
+    Default: use only target of the symlink
+    GRUB_USE_LINUX_SYMLINK=yes: use only the symlink
+    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.
+
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index c2da413..f2649be 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -112,9 +112,32 @@ 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
+    continue # no symlink
+  fi
+  target="`readlink -f $i`"
+  if test ! -f $target ; then
+    # inexistent target
+    list=`echo $list | tr ' ' '\n' | grep -vx $i | grep -vx $target \
+           | tr '\n' ' '`
+    continue
+  fi
+  
+  # default: use the target, not the symlink
+  if [ "${GRUB_USE_LINUX_SYMLINK}" = "yes" ] ; then
+    list=`echo $list | tr ' ' '\n' | grep -vx $target | tr '\n' ' '`
+  else
+    list=`echo $list | tr ' ' '\n' | grep -vx $i | tr '\n' ' '`
+    if ! echo $list | grep -qw $target ; then
+      list="$list $target"
+    fi
+  fi
+done
 
 while [ "x$list" != "x" ] ; do
   linux=`find_latest $list`
@@ -122,13 +145,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 +166,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-05 21:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-01 20:51 [PATCH] prevent duplicated entries due to symlinks Andreas Born
2009-05-04  4:32 ` Pavel Roskin
2009-05-04 16:45   ` Andreas
2009-05-04 21:13     ` Pavel Roskin
2009-05-05 21:11       ` Andreas Born [this message]
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=4A00AB64.3040904@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.