4

Where does the entry

GRUB_DISTRIBUTOR=lsb_release -i -s 2> /dev/null || echo Debian

take the names from?

Here is why this is not a duplicate of "How to safely change OS name in grub boot menu?":

I know already that the names assigned to the OSs in the GRUB boot menu can be changed by commenting

GRUB_DISTRIBUTOR=lsb_release -i -s 2> /dev/null || echo Debian

and replacing the entry by

GRUB_DISTRIBUTOR="Some other name"

(in inverted commas).

All explanations I have found just say:

GRUB_DISTRIBUTOR=lsb_release -i -s 2> /dev/null || echo Debian -

"This line simply retrieves the name in the menu entry." Fair enough! But I would like to know: Where does this command retrieve the actual name from? The names must be contained in some file in plain text!

Zanna
  • 70,465
  • This variable has nothing to do with the boot entries' names, it only describes which system is providing/managing the GRUB boot menu. And the command lsb_release -i -s will simply output the operating system's name, i.e. "Ubuntu". – Byte Commander Sep 09 '16 at 01:01

2 Answers2

10

If I strace the command lsb_release -i -s...

strace -o strace.out lsb_release -i -s

I find (from output file strace.out) that it is reading /etc/lsb-release

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"

The output of lsb_release -i -s is Ubuntu

The redirection 2> /dev/null sends any errors from the command to data oblivion

The operator || means if (and only if) the first command failed, do the second one:

first command || second command

So if lsb_release -i -s errors out, the errors go to /dev/null and the command echo Debian is executed. The output of that is Debian

So to summarise:

If lsb_release -s -i can give us the name of the current system, then use that and display the output. If not, just call it "Debian"

The file /etc/default/grub is used to generate the config file read by GRUB (/boot/grub/grub.cfg) when update-grub is called, so it is read when the real root filesystem is mounted.

You must run sudo update-grub after editing the file for any changes to take effect.

Zanna
  • 70,465
  • you definitely have the superior answer. – WinEunuuchs2Unix Sep 09 '16 at 10:44
  • ^_^ thanks @user557506 I'm really glad it was helpful for you – Zanna Sep 10 '16 at 09:44
  • I followed the steps you indicated and the output was verbatim the same. In the actual (grub2) boot menu, however, the name differs from those containedd in /etc/lsb-release. It has apparently retained the name of the live DVD and reads: "tuxtrans 16.04 live cd GNU/Linux". So where does that come from? – user557506 Sep 10 '16 at 10:09
  • @user557506 I'm not sure why it has that name, but GRUB's real config file /boot/grub/grub.cfg is only updated using configuration from /etc/default/grub when update-grub is called, so do sudo update-grub and see if it changes – Zanna Sep 10 '16 at 10:35
  • Did the trick! After running update-grub, the name I wanted to change appeared in /etc/default/grub and I managed to change it there. Thanks again for your detailed instructions. – user557506 Sep 10 '16 at 10:46
  • @user557506 made a small update to the end, since obviously that part was not clear enough :) – Zanna Sep 10 '16 at 10:53
2

lsb_release is an internal command to obtain the Linux Distro and version (release number). How the command works and where it gets the information from can be duplicated by you.

In terminal type cat /proc/version:

Linux version 4.7.3-040703-generic (kernel@tangerine) (gcc version 6.2.0 20160901 (Ubuntu 6.2.0-3ubuntu11) ) #201609070334 SMP Wed Sep 7 07:36:45 UTC 2016

Ubuntu appears in /proc/version but not the way it appears on grub menus. So we move on....

Now type cat /etc/issue:

Ubuntu 16.04.1 LTS \n \l

This is where lsb_release is probably getting the Linux Distro, because Ubuntu 16.04.1 LTS is what appears on my grub menu.

Before indirectly affecting the variable $GRUB_DISTRIBUTOR (referenced in your question) by forcing /etc/issue to a different constant, consider this code within /etc/grub.d/05_debian_theme:

set_default_theme(){
    case $GRUB_DISTRIBUTOR in
        Tanglu|Ubuntu|Kubuntu)
            # Set a monochromatic theme for Tanglu/Ubuntu.
            echo "${1}set menu_color_normal=white/black"
            echo "${1}set menu_color_highlight=black/light-gray"

Changing Ubuntu to My Cool Linux might appear on the menu okay but internal grub code for themes and coloring would be broken above. Not to mention all the other "things" that might break inside grub plus outside in your other applications and the OS.

Edit 1:

As I learned this morning at command-to-show-linux-version and then discovered @Zanna has already given an excellent answer above, the command lsb_release retrieves text from /etc/lsb-release.