repos/kloeckner.com.ar

Backup of part of my webpage
Commits Files Refs README LICENSE
commit 3ca581cd0331d37c87aa391ef8ba800542a1455d
parent f777d750d605e574b73cfd0e686cb56d5b6df647
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Sat,  2 Nov 2024 22:00:21 -0300

add new blog post: `grub-linux-version-fix`

Diffstat:
Ablog/grub-linux-version-fix/grub-linux-version-fix.md | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/blog_index.shtml | 1+
Mcommon/latest_uploads.shtml | 2+-
3 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/blog/grub-linux-version-fix/grub-linux-version-fix.md b/blog/grub-linux-version-fix/grub-linux-version-fix.md
@@ -0,0 +1,61 @@
+%%
+title: "GRUB: Incorrect Linux version `booting Linux linux ...`"
+date: "02-Nov-2024"
+%%
+
+# GRUB: Incorrect Linux version `booting Linux linux ...`
+
+If for some reason your grub installation doesn't detect your Linux version
+properly, and displays it wrong or as `Arch Linux with Linux version linux` like
+in my case, you can solve it modifying the following files.
+
+The problem is cause by the script `grub-mkconfig` which is used to build the
+grub configuration file `grub.cfg` (generally located on `/boot/grub/grub.cfg`).
+
+This script uses other helper scripts located on `/etc/grub.d/`, and in
+particular the file used to detect the Linux version is `/etc/grub.d/10_llinux`.
+This script uses the file name of the kernel for which the menu entry is being
+built (for example `/boot/vmlinuz-6.1.0-25-amd64`) to get the Linux version, but
+there are distributions like Arch Linux that doesn't add the suffix of version
+to the kernel file (for example `/boot/vmlinuz-linux`).
+
+The solution is to to modify the file `/etc/grub.d/10_linux` and make the
+following changes (also as a [diff file](https://gist.githubusercontent.com/mjkloeckner/214a0ee42c920affe572e12e933a1bb0/raw/24bda0dfa02c7baba3b983fb71662c1904645fa8/fix-grub-linux-display-version.diff)):
+
+```patch
+--- /etc/grub.d/10_linux
++++ /etc/grub.d/10_linux
+@@ -144,7 +144,7 @@
+     fi
+     printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
+   fi
+-  message="$(gettext_printf "Loading Linux %s ..." ${version})"
++  message="$(gettext_printf "Loading Linux %s ..." ${display_version})"
+   sed "s/^/$submenu_indentation/" << EOF
+     echo    '$(echo "$message" | grub_quote)'
+     linux    ${rel_dirname}/${basename} root=${linux_root_device_thisversion} rw ${args}
+@@ -217,6 +217,7 @@
+   dirname=`dirname $linux`
+   rel_dirname=`make_system_path_relative_to_its_root $dirname`
+   version=`echo $basename | sed -e "s,vmlinuz-,,g"`
++  display_version=`file $linux | grep -oP '(?<=version )\S*'`
+   alt_version=`echo $version | sed -e "s,\.old$,,g"`
+   linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
+ 
+@@ -290,7 +291,7 @@
+   fi
+ 
+   if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then -    linux_entry "${OS}" "${version}" simple \
++    linux_entry "${OS}" "${display_version}" simple \
+     "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
+ 
+     submenu_indentation="$grub_tab"
+```
+
+This modification makes the command `grub-mkconfig` get the Linux version of the
+kernel file, from the output of the `file` command executed on that kernel file.
+*Note* that the output of the command gets parsed with GNU grep, which has the
+option of enabling Perl regular expressions (`-P` option) this allows the use of
+positive lookbehind (`(?<=version)`).
+
+* [Previous diff file as Github gist](https://gist.github.com/mjkloeckner/214a0ee42c920affe572e12e933a1bb0)
diff --git a/common/blog_index.shtml b/common/blog_index.shtml
@@ -1,3 +1,4 @@
+<li><b-time>02-Nov-2024</b-time> <a href="/blog/grub-linux-version-fix/grub-linux-version-fix.html">GRUB: Incorrect Linux version `booting Linux linux ...`</a></li>
 <li><b-time>14-Oct-2023</b-time> <a href="/blog/spending-money-on-thinkpads/spending-money-on-thinkpads.html">Spending money on thinkpads</a></li>
 <li><b-time>26-Oct-2022</b-time> <a href="/blog/bought-a-thinkpad/bought-a-thinkpad.html">I bought a ThinkPad x200 for $27</a></li>
 <li><b-time>21-Oct-2022</b-time> <a href="/blog/testing-syntax-highlight/testing-syntax-highlight.html">Testing code syntax highlight</a></li>
diff --git a/common/latest_uploads.shtml b/common/latest_uploads.shtml
@@ -1,6 +1,6 @@
+<li><b-time>02-Nov-2024</b-time> <a href="/blog/grub-linux-version-fix/grub-linux-version-fix.html">GRUB: Incorrect linux version `booting Linux linux ...`</a></li>
 <li><b-time>14-Oct-2023</b-time> <a href="/blog/spending-money-on-thinkpads/spending-money-on-thinkpads.html">Spending money on thinkpads</a></li>
 <li><b-time>26-Oct-2022</b-time> <a href="/blog/bought-a-thinkpad/bought-a-thinkpad.html">I bought a ThinkPad x200 for $27</a></li>
 <li><b-time>21-Oct-2022</b-time> <a href="/blog/testing-syntax-highlight/testing-syntax-highlight.html">Testing code syntax highlight</a></li>
 <li><b-time>23-Sep-2022</b-time> <a href="/blog/nerdearla-2022/nerdearla-2022.html">I'm going to Nerdearla 2022</a></li>
 <li><b-time>18-Sep-2022</b-time> <a href="/blog/sav/sav.html">Sorting Algorithms Visualized</a></li>
-<li><b-time>23-Oct-2021</b-time> <a href="/blog/dwm-config/dwm-config.html">dwm: The dynamic window manager</a></li>