Set linux kernel version

Set «older» kernel as default grub entry

I installed a mainline kernel for testing purposes. I would like to set grub to boot from the older kernel by default. I know I can set the GRUB_DEFAULT=0 setting for the first page of grub but how do I set it to boot by default from one kernel in the second page (Advanced page)? I would prefer doing this without installing other software (ex. grub-customizer).

@belacqua: It is not a duplicate. This question is about setting an older kernel that is not present in grub’s first page of options as default.

It seems like this case should be covered in the earlier questions, even if the method needs to be update for 12.10, older kernels, etc..

The question’s use case is different, and the answer is very specific in a way that doesn’t apply to the other claimed duplicates. I came here to solve this particular problem; not to change the boot order; nor to boot Windows. +1 for «not a duplicate».

6 Answers 6

First, make a backup copy of /etc/default/grub . If something goes wrong, you can easily revert to the known-good copy.

sudo cp /etc/default/grub /etc/default/grub.bak 

Then edit the file using the text editor of your choice (e.g. gedit, etc.).

sudo -H gedit /etc/default/grub 

Find the line that contains GRUB_DEFAULT — this is what you’ll want to edit to set the default. You must know the full name of the kernel you want — e.g. Ubuntu, with Linux 3.13.0-53-generic — along with the full name of the «advanced menu» — e.g. Advanced options for Ubuntu .

You then combine those two strings with > and set GRUB_DEFAULT to them as: GRUB_DEFAULT=»Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-53-generic» (including quotes).

Save it, then build the updated grub menu.

Note: There is a method utilizing numbers to access kernels and menus but this is not recommended as it is unreliable when kernel updates occur.

Using a numeric value can be problematic when updates occur. It’s better to use a text default, ie: GRUB_DEFAULT=»Previous Linux versions>Ubuntu, with Linux 3.2.0-18-generic»

This is a good solution, but even better is to open a /boot/grub/grub.cfg and there you will see all the manuentry and all the submenus . If you edit them, you can easy set the default ones, even change the Titles of the options in the grub list when restarting a computer.

It is definitely useful to examine /boot/grub/grub.cfg to determine the exact names to use. But do not change this file as it will be automatically regenerated by update-grub , including on updating packages.

The formatting for GRUB_DEFAULT is slightly outdated (since at least Ubuntu 14.04.2). Running update-grub I encountered a warning: Please don’t use old title Previous Linux versions>Ubuntu, with Linux 3.13.0-53-generic for GRUB_DEFAULT, use Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-53-generic (for versions before 2.00) or gnulinux-advanced-b0ce60c3-184c-453b-af59-419b56a2584f>gnulinux-3.13.0-53-generic-advanced-b0ce60c3-184c-453b-af59-419b56a2584f (for 2.00 or later)

Читайте также:  Linux untar all files

The best solution for me was to set (in /etc/default/grub ):

 GRUB_DEFAULT=saved GRUB_SAVEDEFAULT=true 

With this settings the last selected value is kept for the next boot. If you have a new kernel you don’t have to edit your config.

Don’t forget to re-run sudo update-grub

The solution is from reading: info grub-mkconfig

I can not look into my computer where I used it in this moment, but you are right «;» seems to be wrong or unnecessary!

Now that an Advanced menu is default in Ubuntu, you’ll need to select it before the kernel you want using the > character.

in /etc/default/grub and re-run sudo update-grub .

It is important to note that for the GRUB menu entries numbering starts with 0 . Therefore the 1 above points to the Advanced menu. As a precaution, you may want to initially set GRUB_TIMEOUT=5 . Some may be unable to access GRUB by hitting a key at boot time. This is a safety net in case you accidentally point to something like Memory test instead. It is also necessary to include the above numbers in quotes. It will not work otherwise.

I find this answer very useful, as after a kernel update it still points to the newest kernel. in my setup for example it is 1>0, meaning: advanced-first listing (is always the newest kernel). my system sometime stopped to automatically update the 0 entry of grub with the newest kernel, so i use this method.

Unsure if this has been mentioned — but you can mix the numbers + string to select the Advanced menu AND the kernel version you want. eg GRUB_DEFAULT=»1>gnulinux-5.4.0-121-generic-advanced-e17a595e-18f3-45e3-8f22-e0d1005fbae1″ Currently the newest kernel is borked. This gives the confidence it will pick the right version each time on reboot. So this gets me out of a hole for the moment.

@jsonUK I think I tested the strings versions when preparing this answer and had trouble making them work. Granted, it’s been six years 🙂 Thanks for pointing it out.

To be able to set which boot option to use as default you need to know what there is. so:

To display the menu entries without actually booting, try something like:

$ lsb_release -s -rdc Ubuntu 16.04.4 LTS 16.04 xenial $ update-grub --version grub-mkconfig (GRUB) 2.02~beta2-36ubuntu3.17 $ grep -Ei 'submenu|menuentry ' /boot/grub/grub.cfg | sed -re "s/(.? )'([^']+)'.*/\1 \2/" menuentry Ubuntu submenu Advanced options for Ubuntu menuentry Ubuntu, with Linux 4.4.0-34-generic menuentry Ubuntu, with Linux 4.4.0-34-generic (upstart) menuentry Ubuntu, with Linux 4.4.0-34-generic (recovery mode) menuentry System setup

sed -nre «/submenu|menuentry/s/(.? )'([^’]+)’.*/\1 \2/p» < /boot/grub/grub.cfg - The same effect using only sed

Читайте также:  Netcat install kali linux

When I have initially posted this I haven’t noticed the OP’s specific requirement not to propose grub-customizer . Sorry.

For what it’s worth I’ll leave it here but also confirm that the best solution is indeed the most up-voted one HERE, with variables that can be found as indicated in THIS complementary answer.

In order to do it with a GUI, I use Grub Customizer (I’m in Mint but that doesn’t count here).

The simplest and most direct way (thanks @eMKi for the suggestion in comment) — best suited for a permanent setting, in General Settings > default entry > predifined, simply select the desired kernel in the drop-down list.

enter image description here

Or, in case one needs the «previous booted entry» to be the one selected (might be useful in dual boot with Windows when doing an Windows update that requires restart, for example) — keeping the Advanced options in the grub list in case the default list is changed within Grub Customizer:

enter image description here

under General settings select the default entry: previous booted entry.

enter image description here

Then, reboot, and during boot select the «Advanced options» entry in the grub list:

enter image description here

and select the older kernel

enter image description here

On the next reboot, the «Advanced options» item will be the one selected by default in the grub list and the last selected kernel from under there will be booted (without opening the full list of kernels).

In case Windows is used, or other option in the grub list, remember to re-do the previous procedure.

Источник

How to set default boot kernel on Linux ( CentOS / RHEL 7 )

How to set default boot kernel in linux? How to change the default boot entry for kernel ? How to boot with old kernel version ? How to revert to previous kernel version ?

How to set default boot kernel on Linux ( CentOS / RHEL 7 )

In my last article I had shared the commands to check if server is physical or virtual in Linux or Unix . GRUB2 is the version of GRUB currently in use. The software was rewritten to allow plugins and expand features available in the menu system. GRUB legacy and GRUB2 are otherwise fairly similar.

By default, the saved_entry value is set to the name of latest installed kernel of package type kernel. This is defined in /etc/sysconfig/kernel by the UPDATEDEFAULT and DEFAULTKERNEL directives. The file can be viewed by the root user as follows:

# cat /etc/sysconfig/kernel # UPDATEDEFAULT specifies if new-kernel-pkg should make # new kernels the default UPDATEDEFAULT=yes # DEFAULTKERNEL specifies the default kernel package type DEFAULTKERNEL=kernel

When new kernels are installed, they should include a new stanza in the bootloader configuration file, /boot/grub2/grub.conf . The default stanza is based on the saved_entry directive in the /boot/grub2/grubenv file.

For example currently my system is configured is to boot from 3.10.0-957.1.3.el7.x86_64

# grep saved /boot/grub2/grubenv saved_entry=CentOS Linux (3.10.0-957.1.3.el7.x86_64) 7 (Core)

Now currently I have a different kernel loaded on my system

Читайте также:  Linux disk space utility

This is because I just installed a newer kernel on my system but since I have not rebooted my node, still old kernel is loaded.

So after reboot the kernel version provided in » saved_entry » will be loaded. Now after reboot as expected my loaded kernel has changed

# uname -r 3.10.0-957.1.3.el7.x86_64

How to set default boot kernel?

The boot configuration when using GRUB 2 is in the /boot/grub2/grub.cfg file. You can also refer to it by the /etc/grub2.cfg file which is a symbolic link. To force a system to always use a particular menu entry and to set default boot kernel, use the menu entry name as the key to the GRUB_DEFAULT directive in the /etc/default/grub file.

To list the available menu entries, run the following command as root:

# awk -F\' '$1=="menuentry " ' /etc/grub2.cfg CentOS Linux (3.10.0-957.1.3.el7.x86_64) 7 (Core)  CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)  CentOS Linux (0-rescue-4c3582b97843401fbc3c8e68c07e553c) 7 (Core)

GRUB 2 supports using a numeric value as the key for the saved_entry directive to change the default order in which the kernel or operating systems are loaded. To specify which kernel or operating system should be loaded first i.e. to set default boot kernel, pass its number to the grub2-set-default command which sets the default boot menu entry for all subsequent boots.

NOTE:
grub2-set-default command only works for GRUB configuration files created with GRUB_DEFAULT=saved in /etc/default/grub .

# grep GRUB_DEFAULT /etc/default/grub GRUB_DEFAULT=saved

For example to set default boot kernel let us use numeric value. Now as per our /etc/grub2.cfg we have two menuentry for kernel

# awk -F\' '$1=="menuentry " ' /etc/grub2.cfg CentOS Linux (3.10.0-957.1.3.el7.x86_64) 7 (Core)  CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)  CentOS Linux (0-rescue-4c3582b97843401fbc3c8e68c07e553c) 7 (Core)

where » entry 0 » is loaded currently (3.10.0-957.1.3.el7.x86_64) .

Let us change it to old or previous kernel version (3.10.0-693.el7.x86_64)

# grep saved /boot/grub2/grubenv saved_entry=1

Next rebuild your GRUB2 configuration

# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file . Found linux image: /boot/vmlinuz-3.10.0-957.1.3.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-957.1.3.el7.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-4c3582b97843401fbc3c8e68c07e553c Found initrd image: /boot/initramfs-0-rescue-4c3582b97843401fbc3c8e68c07e553c.img done

Now after rebooting the node, we see the old kernel has successfully loaded

Lastly I hope the steps from the article to set default boot kernel on Linux was helpful. So, let me know your suggestions and feedback using the comment section.

Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Источник

Оцените статью
Adblock
detector