Editing /etc/grub.d/10_linux SOLVED

Chat about Linux in general
Forum rules
Do not post support questions here. Before you post read the forum rules. Topics in this forum are automatically closed 6 months after creation.
Locked
viking777

Editing /etc/grub.d/10_linux SOLVED

Post by viking777 »

It is quite possible I am the only person in the world that wants to do this, but I do want to do it and I don't know how to do it myself, nor can I find anyone else who has done it.
I absolutely detest subfolders in grub and I want to get rid of them permanently and for ever. At the moment I can get rid of them, but only temporarily, by editing /boot/grub/grub.cfg like so:

I only need to comment out line #140:

Code: Select all

}
#submenu "Previous Linux versions" {
menuentry 'Linux Mint 14 Cinnamon 64-bit, 3.5.0-21-generic (/dev/sda6)' --class linuxmint --class gnu-linux --class gnu --class os {
Now grub.cfg is produced by the code in /etc/grub.d/10_linux and thus my edits are removed every time I update a kernel or run update-grub. This is what I would like to prevent happening, but the code in 10_linux is not something I understand, so I wonder if anyone else could tell me how to alter it to permanently rid myself of grub subfolders.

BTW I have already tried commenting out lines 256-266 in 10_linux (which is the bit that mentions subfolders) but when I ran update-grub I got:

Code: Select all

update-grub
Generating grub.cfg ...
/etc/grub.d/10_linux: 257: /etc/grub.d/10_linux: Syntax error: end of file unexpected (expecting "done")
When I typed an indented 'done' at the end of the file update grub just went into some kind of loop and the command had to be force closed. So as you can see, I have tried to work it out myself, but I can't get there.

Incidentally I would also like to be able to do this in Ubuntu as well, but that has a different 10_linux file, and produces a different grub.cfg which is even more annoying to deal with.

Please don't suggest grub-customizer as a solution to this, I consider that program to be faulty at the moment and don't want to use it.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29460
Joined: Wed Jul 06, 2011 3:58 am

Re: Editing /etc/grub.d/10_linux

Post by xenopeek »

I think you need to comment out just a few lines to avoid it putting your older kernels in a submenu. At the very end of the /etc/grub.d/10_linux file (on Linux Mint 14) you will see the following bit:

Code: Select all

  if [ "$list" ] && ! $in_submenu; then
    echo "submenu \"Previous Linux versions\" {"
    in_submenu=:
  fi
done

if $in_submenu; then
  echo "}"
fi
All you need to do is comment out the four top lines in the above, so it becomes:

Code: Select all

#  if [ "$list" ] && ! $in_submenu; then
#    echo "submenu \"Previous Linux versions\" {"
#    in_submenu=:
#  fi
done

if $in_submenu; then
  echo "}"
fi
That will remove the logic that tests if there are more kernels to be found, and if so (and not already done) will add a submenu where these kernels will be added. With that logic removed, it will never add a submenu and should add all kernels at the top level.

Edit: this file will be overwritten when your grub-common package is upgraded.
Image
viking777

Re: Editing /etc/grub.d/10_linux

Post by viking777 »

Well thanks for trying, but that is not it. With those edits I now get 4 entries in the boot menu (two of which are duplicates) and one of those is still inside a subfolder :(
User avatar
xenopeek
Level 25
Level 25
Posts: 29460
Joined: Wed Jul 06, 2011 3:58 am

Re: Editing /etc/grub.d/10_linux

Post by xenopeek »

Yeah, it's a bit obfuscated code :? I'll have another look.
Image
viking777

Re: Editing /etc/grub.d/10_linux

Post by viking777 »

Correction to the above. It did work :D The reason I got all the duplicates before was because in order to keep a working linux_10 file I renamed it to linux_10.good. Surprisingly when update-grub ran it ran both linux_10 and linux_10.good together hence the duplicates and the subfolder. Second time around I removed the executable bit from linux_10.good and all was well.

Do you have any thoughts on what might happen if I copied the Mint linux_10 into Ubuntu and disabled its own version? Or do you have any idea how I could achieve the same effect in the more complicated Ubuntu linux_10 file? (I could copy the code here if you don't have it).

Thanks for that anyway. I take your point about grub-common overwriting, but it is not updated that often. I could even use chattr to make 10_linux unwritable, but that might have consequences that I can't forsee, so I will leave that for now.
User avatar
xenopeek
Level 25
Level 25
Posts: 29460
Joined: Wed Jul 06, 2011 3:58 am

Re: Editing /etc/grub.d/10_linux

Post by xenopeek »

Ubuntu really doesn't run nice from VirtualBox. It's unbelievable slow :? Anyway, I was able to get the file from there and think I know what to edit. But, now we're talking about Ubuntu so I had to move the topic :wink:

This is down at the end of the file again, but you need to make a few more edits. First, from the end of the file scroll back up till you get to this block of comments and code. All our changes will be below this marker (just so you know where to look).

Code: Select all

# Extra indentation to add to menu entries in a submenu. We're not in a submenu
# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
submenu_indentation=""

is_first_entry=true
while [ "x$list" != "x" ] ; do
Then scroll down and find this bit:

Code: Select all

  if [ "x$is_first_entry" = xtrue ]; then
    linux_entry "${OS}" "${version}" simple \
    "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_EXTRA} ${GRUB_CMDLINE_LINUX_DEFAULT}"

    submenu_indentation="\t"
Comment out that submenu_indentation="\t" line.

Then scroll to the end and find this bit just 10 lines up or some from the end of the file:

Code: Select all

  fi

  list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  is_first_entry=false
done
Coment out that is_first_entry=false line.

That should do it. This again removes the logic that adds a submenu if more than one kernel is found, and it prevents indenting the kernels found after the first.
Image
viking777

Re: Editing /etc/grub.d/10_linux

Post by viking777 »

I got this:

Code: Select all

update-grub
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.5.0-22-generic
Found initrd image: /boot/initrd.img-3.5.0-22-generic
Found linux image: /boot/vmlinuz-3.5.0-21-generic
Found initrd image: /boot/initrd.img-3.5.0-21-generic
error: out of memory.
error: syntax error.
error: Incorrect command.
error: syntax error.
Syntax error at line 218
Syntax errors are detected in generated GRUB config file.
Ensure that there are no errors in /etc/default/grub
and /etc/grub.d/* files or please file a bug report with
/boot/grub/grub.cfg.new file attached.done
It did produce a file which it called grub.cfg.new, but I can tell just by looking at it that it is not worth booting from (still has the subfolders).
The code at line 218 is:

Code: Select all

### END /etc/grub.d/41_custom ###
ie the very end of the file.

BTW I have no entries in 41_custom so it is nothing I have done. Although Ubuntu does auto-generate code there:

Code: Select all

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###
I can't work out if that is relevant or not.
Thanks for your time on this, I appreciate it.
User avatar
xenopeek
Level 25
Level 25
Posts: 29460
Joined: Wed Jul 06, 2011 3:58 am

Re: Editing /etc/grub.d/10_linux

Post by xenopeek »

Could you pastebin your linux_10? I might have missed something...
Image
viking777

Re: Editing /etc/grub.d/10_linux

Post by viking777 »

viking777

Re: Editing /etc/grub.d/10_linux

Post by viking777 »

I tried out my idea of copying the modified MInt 10_linux into Ubuntu and disabling its own. In many ways it was successful. It certainly booted well enough, the only problem was that it truncated the menu entries so instead of reading:

Code: Select all

Ubuntu 64-bit, 3.5.0-22-generic
It now reads:

Code: Select all

, 3.5.0-22-generic
Which isn't ideal, but better than subfolders imho.

Not exactly solved, but getting nearer :)
User avatar
xenopeek
Level 25
Level 25
Posts: 29460
Joined: Wed Jul 06, 2011 3:58 am

Re: Editing /etc/grub.d/10_linux

Post by xenopeek »

viking777 wrote:Here you go:
http://pastebin.com/download.php?i=yfxziiGQ
Something has gone wrong; that only has the text "10_linux" in it...
Image
viking777

Re: Editing /etc/grub.d/10_linux

Post by viking777 »

Sorry about that, this one should be better, I tested the download this time :oops:

http://pastebin.com/download.php?i=BszXEMQH
viking777

Re: Editing /etc/grub.d/10_linux

Post by viking777 »

As the amended Mint 10_linux so nearly gives me what I want on Ubuntu, I am working on a way to stop it from truncating the menuentry names. I now see why it does it, but don't know how to alter it to stop it from happening.

Code: Select all

description="`grep GRUB_TITLE /etc/linuxmint/info | awk -F = '{print $2}'`"
  if ${recovery} ; then
    title="${description}, ${version} (${GRUB_DEVICE_BOOT}) -- recovery mode"
  else
    title="${description}, ${version} (${GRUB_DEVICE_BOOT})"
  fi
  printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
  cat << EOF
As you see from the above code, the Mint 10_linux greps /etc/linuxmint/info in order to provide the ${title} element of 'menuentry'. So in order to get the correct ${title} I would need to substitute somewhere else for it to get that information from. I looked in the corresponding section of the Ubunut 10_linux but it is complicated beyond belief and I can't get anything from that.

Any ideas on that thought? Might be easier than trying to figure out whole of the Ubuntu code.
User avatar
xenopeek
Level 25
Level 25
Posts: 29460
Joined: Wed Jul 06, 2011 3:58 am

Re: Editing /etc/grub.d/10_linux

Post by xenopeek »

Okay, let's give that a shot. I'm booting up Ubuntu now to give it a look.

Edit: you can do the following, replace this line:

Code: Select all

description="`grep GRUB_TITLE /etc/linuxmint/info | awk -F = '{print $2}'`"
with:

Code: Select all

description="`cat /etc/issue.net`"
It doesn't give the same information, but at least a title. On Linux Mint the original line gives "Linux Mint 14 Cinnamon 64-bit". On Ubuntu the altered line gives "Ubuntu 12.10". If you want to include the architecture (making it "Ubuntu 12.10 64-bit" for example), then after the above line add this line:

Code: Select all

if [ x`uname -p` = x'x86_64' ]; then description="$description 64-bit"; else description="$description 32-bit"; fi
Image
viking777

Re: Editing /etc/grub.d/10_linux

Post by viking777 »

Well you beat me to it, but I found my own solution anyway. What it did was to change this:

Code: Select all

description="`grep GRUB_TITLE /etc/linuxmint/info | awk -F = '{print $2}'`"
  if ${recovery} ; then
    title="${description}, ${version} (${GRUB_DEVICE_BOOT}) -- recovery mode"
  else
    title="${description}, ${version} (${GRUB_DEVICE_BOOT})"
  fi
  printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
  cat << EOF
To this:

Code: Select all

#  description="`grep GRUB_TITLE /etc/linuxmint/info | awk -F = '{print $2}'`"
  if ${recovery} ; then 
    title="$(gettext_quoted "%s, with Linux %s (recovery mode)")"
#    title="${description}, ${version} (${GRUB_DEVICE_BOOT}) -- recovery mode"
  else
    title="$(gettext_quoted "%s, with Linux %s")"
#  title="${description}, ${version} (${GRUB_DEVICE_BOOT})"
  fi
  printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
  cat << EOF
Now it works perfectly :D

Thanks very much for your help xenopeek, I will mark the topic solved.
Locked

Return to “Chat about Linux”