linux - Set default kernel in GRUB - Unix & Linux Stack Exchange
Stack Exchange Network
Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Loading…
0
+0
Tour
Start here for a quick overview of the site
Help Center
Detailed answers to any questions you might have
Meta
Discuss the workings and policies of this site
About Us
Learn more about Stack Overflow the company
Business
Learn more about hiring developers or posting ads with us
Log in
Sign up
current community
Unix & Linux
help
chat
Unix & Linux Meta
your communities
Sign up or log in to customize your list.
more stack exchange communities
company blog
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
Sponsored by
Home
Questions
Tags
Users
Unanswered
Jobs
Set default kernel in GRUB
Ask Question
Asked
5 years, 9 months ago
Active
1 month ago
Viewed
212k times
75
43
How can I pick which kernel GRUB2 should load by default? I recently installed a the linux realtime kernel and now it loads by default. I'd like to load the regular one by default.
So far I only managed to pick the default OS.. and for some reason the /boot/grub.cfg already assumes that I want to load the rt-kernel and put it into the generic linux menu entry (in my case Arch Linux).
linux kernel boot grub

Share
Improve this question
Follow
edited Apr 22 '15 at 21:36
TomTom
asked Apr 22 '15 at 21:04
TomTomTomTom
1,70333 gold badges1515 silver badges2121 bronze badges
3
2
grub2-set-default
?
– taliezin
Apr 22 '15 at 21:15
1
But how do I know the number? The numbers in grub.cfg only correspond to the OSs and not the kernels.
– TomTom
Apr 22 '15 at 21:17
In some cases this works: askubuntu.com/questions/216398/… You can find the menu names by looking through this file: /boot/grub/grub.cfg
– TekOps
Oct 4 '18 at 5:18
add a comment
|
8 Answers
8
Active
Oldest
Votes
66
I think most distributions have moved additional kernels into the advanced options sub menu at this point, as TomTom found was the case with his
Arch.
I didn't want to alter my top level menu structure in order to select a previous kernel as the default. I found the answer here:
http://www.humans-enabled.com/2014/08/how-to-set-default-grub-kernel-boot.html
To summarize:
1) Find the $menuentry_id_option for the submenu:
$ grep submenu /boot/grub/grub.cfg
submenu 'Advanced options for Debian GNU/Linux' $menuentry_id_option 'gnulinux-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
2) Find the $menuentry_id_option for the menu entry for the kernel you want to use:
$ grep gnulinux /boot/grub/grub.cfg
menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
submenu 'Advanced options for Debian GNU/Linux' $menuentry_id_option 'gnulinux-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
menuentry 'Debian GNU/Linux, with Linux 4.18.0-0.bpo.1-rt-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-0.bpo.1-rt-amd64-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
menuentry 'Debian GNU/Linux, with Linux 4.18.0-0.bpo.1-rt-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-0.bpo.1-rt-amd64-recovery-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
menuentry 'Debian GNU/Linux, with Linux 4.18.0-0.bpo.1-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-0.bpo.1-amd64-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
menuentry 'Debian GNU/Linux, with Linux 4.18.0-0.bpo.1-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-0.bpo.1-amd64-recovery-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
menuentry 'Debian GNU/Linux, with Linux 4.17.0-0.bpo.1-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.17.0-0.bpo.1-amd64-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
menuentry 'Debian GNU/Linux, with Linux 4.17.0-0.bpo.1-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.17.0-0.bpo.1-amd64-recovery-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
menuentry 'Debian GNU/Linux, with Linux 4.9.0-8-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.9.0-8-amd64-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
menuentry 'Debian GNU/Linux, with Linux 4.9.0-8-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.9.0-8-amd64-recovery-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
3) Comment out your current default grub in /etc/default/grub and replace it with the sub-menu's $menuentry_id_option from step one, and the selected kernel's $menuentry_id_option from step two separated by >.
In my case the modified GRUB_DEFAULT is:
#GRUB_DEFAULT=0
GRUB_DEFAULT="gnulinux-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc>gnulinux-4.18.0-0.bpo.1-amd64-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc"
4) Update grub to make the changes. For Debian this is done like so:
$ sudo update-grub
Done. Now when you boot, the advanced menu should have an asterisk and you should boot into the selected kernel. You can confirm this with uname.
$ uname -a
Linux NAME 4.18.0-0.bpo.1-amd64 #1 SMP Debian 4.18.0-0 (2018-09-13) x86_64 GNU/Linux
Changing this back to the most recent kernel is as simple as commenting out the new line and uncommenting #GRUB_DEFAULT=0:
GRUB_DEFAULT=0
#GRUB_DEFAULT="gnulinux-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc>gnulinux-4.18.0-0.bpo.1-amd64-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc"
then rerunning update-grub.

Share
Improve this answer
Follow
edited Mar 5 '20 at 12:56
Cybot
10344 bronze badges
answered Dec 2 '16 at 23:46
William L-KWilliam L-K
78466 silver badges22 bronze badges
0
add a comment
|
79
+150
After struggling for 2 hours, I have found a much easier way to achieve this. I just RTFM. ;)
Add two lines to /etc/default/grub
GRUB_SAVEDEFAULT=true
GRUB_DEFAULT=saved
Do the sudo update-grub, reboot, get into your grub menu and select whichever menu or submenu item you need. The choice will be saved every time and then your computer will boot into it automatically. When you manually choose a different entry, that becomes the new default.

Share
Improve this answer
Follow
edited Dec 26 '20 at 10:31
geekley
13566 bronze badges
answered Feb 3 '18 at 14:48
Jimmy FalconJimmy Falcon
1,04155 silver badges22 bronze badges
5
3
As of 2020, sudo update-grub returns a command not found in Arch. Instead the command sudo grub-mkconfig -o /boot/grub/grub.cfg should be used.
– bela83
Jun 9 '20 at 7:59
1
I had to comment out GRUB_DEFAULT=0
– daslicious
Sep 24 '20 at 18:23
"The choice will be saved and next time your computer will boot into it automatically". So it only saves the default once in the next reboot? Or will it it automatically change the default every time you choose a specific kernel?
– geekley
Dec 26 '20 at 1:53
@geekley what do you think save default means?
– RichieHH
Jan 8 at 6:53
@RichieHH I made that comment before editing the answer. Before, it wasn't so clear if the default would be saved only on the first reboot or every time I choose an option. That's why I rephrased it to better clarify that the default changes every time you manually choose a different entry. Btw, this saved default is not necessarily the first choice (like "Ubuntu"), it can be a sub-entry (like "Ubuntu with linux X.Y.Z generic"). The first choice won't automatically reflect the default, which might get you a bit confused if you have 2 kernels like linux and linux-libre.
– geekley
Jan 8 at 19:30
add a comment
|
22
As mentioned in the comments, you can set the default kernel to boot into using the grub-set-default X command, where X is the number of the kernel you want to boot into. In some distributions you can also set this number by editing the /etc/default/grub file and setting GRUB_DEFAULT=X, and then running update-grub.
The number is the index to an array of kernels/kernel settings shown in the GRUB menu during boot, with 0 being the first (top-most) entry. You can usually find the right number by looking for menuentry lines in /boot/grub/grub.cfg, like so:
grep menuentry /boot/grub/grub.cfg
You'll see each kernel listed with the name that is shown in the GRUB boot menu. The first one is 0, the second is 1, and so on.

Share
Improve this answer
Follow
answered Apr 22 '15 at 23:37
jkt123jkt123
47122 silver badges66 bronze badges
3
1
In Fedora 21 it's /boot/grub2/grub.cfg.
– somethingSomething
Apr 23 '15 at 0:01
3
This is not working for me. The latest kernel in my installation is 4.4.0-64-generic (menuentry 0) but I want 4.4.0-59-generic (menuentry 9) to be the default boot kernel. I ran grub-set-default 9 and then grub-update and rebooted. I let grub boot with the default kernel and it still boots with 4.4.0-64-generic. I also tried editing /etc/default/grub and set GRUB_DEFAULT=9 and ran grub-update. On rebooting nothing changes, system still boots with 4.4.0-64-generic. Maybe I missed something, can anyone help me?
– Dronacharya
Feb 27 '17 at 14:40
This did not work for me either. I deleted the unwanted kernel like explained here: askubuntu.com/a/764242/456247
– Luis
Jan 11 '18 at 10:52
add a comment
|
12
Simply doing grep 'menuentry' /boot/grub/grub.cfg lists additional entries that are not related to the actual kernel or OS versions. For instance, it lists
if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
menuentry_id_option=""
export menuentry_id_option
I would like to propose a small improvement to the method of searching that file: use awk
$ awk '/menuentry/ && /class/ {count++; print count-1"****"$0 }' /boot/grub/grub.cfg
0****menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-86df21bf-d95f-435c-9292-273bdbcba056' {
1**** menuentry 'Ubuntu, with Linux 3.19.0-26-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-26-generic-advanced-86df21bf-d95f-435c-9292-273bdbcba056' {
2**** menuentry 'Ubuntu, with Linux 3.19.0-26-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-26-generic-recovery-86df21bf-d95f-435c-9292-273bdbcba056' {
3**** menuentry 'Ubuntu, with Linux 3.13.0-62-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-62-generic-advanced-86df21bf-d95f-435c-9292-273bdbcba056' {
4**** menuentry 'Ubuntu, with Linux 3.13.0-62-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-62-generic-recovery-86df21bf-d95f-435c-9292-273bdbcba056' {
With the command bellow and its output, you can see the awk code match actual OS version, and give you the number which you then may use in /etc/default/grub file.
In addition to editing the /etc/default/grub file by hand, I suggest using sed. In the command bellow, replace X with appropriate number you got from the awk command above:
sudo sed -i 's/GRUB_DEFAULT=0/GRUB_DEFAULT=X/g' /etc/default/grub; sudo update-grub

Share
Improve this answer
Follow
answered Aug 21 '15 at 18:55
Sergiy KolodyazhnyySergiy Kolodyazhnyy
14.2k66 gold badges4040 silver badges8181 bronze badges
2
2
This isn't an answer. It reads like a comment. An answer should say, "This is how to set the default entry in GRUB", not "let me make an addendum to another answer". You can easily edit this into a proper answer, but it might be smarter to just leave a comment on jkt123's answer about using awk instead of grep.
– Aleksandr Dubinsky
Sep 28 '16 at 8:50
1
I think this answer does improve signifcantly on the answer proposing grep, if you compare the output of the two, the awk output is much easier to use (includes number, easier to read). But, the introduction should probably be re-written so this answer stands alone, and doesn't read like a comment to the grep answer.
– Cameron
Jan 30 '20 at 1:47
add a comment
|
2
jkt123's will work for most distributions I guess. However for Arch Linux it didn't work, at least not with the packages I have available.
The indices you can set with grub-set-default only correspond to the main menu entries. The kernel options are however in a submenu. So either you move the kernel entry out of the submenu into the main menu or you put the entry on top of the submenu list and select the submenu.
My Grub Menu
Arch Linux
Advanced options for Arch Linux
Kernel 1
Kernel 2
Windows
To be able to boot Kernel 2 you have to either swap it with Kernel 1 or you put it outside the submenu on the same level as Arch Linux or Windows. And then set the default number to one of the main menu indices. For example in the menu above "0" boots "Arch Linux" and "1" boots Kernel 1.
To change the hierarchy and swap, open /boot/grub/grub.cfg and move the entry you wish to move. An entry could look like this
menuentry 'ENTRY NAME'
... some code ...
}
Then you need to apply your changes. In my case with grub-mkconfig. But this might vary from system to system.

Share
Improve this answer
Follow
answered Apr 23 '15 at 8:30
TomTomTomTom
1,70333 gold badges1515 silver badges2121 bronze badges
add a comment
|
1
As recently as CentOS-6.6 grub.conf looked like this can could be manually edited to change the default selection:
default=1
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz

Share
Improve this answer
Follow
edited May 19 '17 at 20:23
Jeff Schaller♦
57.9k3030 gold badges9090 silver badges201201 bronze badges
answered May 19 '17 at 20:14
MikeMike
1111 bronze badge
add a comment
|
0
Debian Stretch:
Rather than messing around with config files, create a folder in /noot (call it what you want), leave the kernel you want, along with the matching config and system files, in /boot and move the rest to this new folder.
Run update-grub.
Double check the /boot folder that your kernel version and matching config and system files are are still there (in case you copied something you shouldn't have) and reboot.

Share
Improve this answer
Follow
edited Jul 23 '19 at 8:17
Stephen Kitt
284k3737 gold badges705705 silver badges793793 bronze badges
answered Jul 23 '19 at 7:09
Pinkie PeriePinkie Perie
1
add a comment
|
0
In order to do it with a GUI, I use Grub Customizer (I'm in Mint and have installed it like this.).
The idea is to keep the Advanced options in the grub list in case the default list is changed within Grub Customizer.
Then, under General settings select the default entry: previous booted entry.
Then, reboot, and during boot select the "Advanced options" entry in the grub list:
and select the desired kernel
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.

Share
Improve this answer
Follow
edited Dec 23 '20 at 11:10
answered Dec 23 '20 at 11:05
cipricuscipricus
37711 silver badge1919 bronze badges
add a comment
|
Highly active question. Earn 10 reputation in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.
Not the answer you're looking for? Browse other questions tagged linux kernel boot grub or ask your own question.
The Overflow Blog
Sequencing your DNA with a USB dongle and open source code
Podcast 310: Fix-Server, and other useful command line utilities
Featured on Meta
Opt-in alpha test for a new Stacks editor
Visual design changes to the review queues
IBM will soon be sponsoring Unix & Linux!
Linked
2
How do I run the Linux kernel?
-1
Kali Linux Virtual Box 5.8.0 stuck on loading screen
0
How to set default kernel to boot from?
Related
5
Automatically include N latest kernel versions in GRUB / GRUB2 menu on kernel upgrade
3
Booting into a kernel image
2
Linux kernel GRUB/boot issue?
12
How to change default boot partition?
0
Is it possible to boot a grub-mkstandalone created img file from cfg?
0
GRUB booting issue
Hot Network Questions
How can 3 queens control the white squares?
Why is it "crouching tiger hidden dragon" but not "crouching tiger hiding dragon"?
What software should I buy to have a macOS VM on my Linux machine?
Looking for a combinatorial proof for a Catalan identity
How are there two C3 rotation axes in ammonia?
In Tolkien's universe, what happens if a Ring of Power is worn by a member of a race other than the one the ring was made for?
A battery is not connected to anything. Is there a voltage between its plus and minus poles?
How to deal with students who try to steer a course (in the online setting)?
Equivalent of numpy's newaxis
A major on all 6 strings of the guitar
Evaluate left-or-right
Why do AST SpaceMobile satellites have antennas much larger than Starlink, whereas they both aim at providing network coverage anywhere on earth?
How to show this symmetric function inequality
Periodic von Neumann neighbours
Is Seiryu Miharashi Station the only train station where passengers cannot enter or exit the platform?
Short story about aliens who came to Earth using vacuum tube technology?
How can I use a driver for multiple objects?
Can one purchase train passes in China, or is one supposed to buy tickets one by one?
There is a space between label and punctuation/comma when I used \ref{label} command
Why does adding one character to my MySQL password lock me out?
Good alternative to a slider for a long list of numeric values
Add ribbon of most used commands-How it could be implemented?
VRP book recommendations
Is this encounter in Ghosts of Saltmarsh ridiculously deadly?
more hot questions
Question feed
Subscribe to RSS
Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Unix & Linux
Tour
Help
Chat
Contact
Feedback
Mobile
Company
Stack Overflow
For Teams
Advertise With Us
Hire a Developer
Developer Jobs
About
Press
Legal
Privacy Policy
Terms of Service
Stack Exchange
Network
Technology
Life / Arts
Culture / Recreation
Science
Other
Stack Overflow
Server Fault
Super User
Web Applications
Ask Ubuntu
Webmasters
Game Development
TeX - LaTeX
Software Engineering
Unix & Linux
Ask Different (Apple)
WordPress Development
Geographic Information Systems
Electrical Engineering
Android Enthusiasts
Information Security
Database Administrators
Drupal Answers
SharePoint
User Experience
Mathematica
Salesforce
ExpressionEngine® Answers
Stack Overflow em Português
Blender
Network Engineering
Cryptography
Code Review
Magento
Software Recommendations
Signal Processing
Emacs
Raspberry Pi
Stack Overflow на русском
Code Golf
Stack Overflow en español
Ethereum
Data Science
Arduino
Bitcoin
Software Quality Assurance & Testing
Sound Design
Windows Phone
more (28)
Photography
Science Fiction & Fantasy
Graphic Design
Movies & TV
Music: Practice & Theory
Worldbuilding
Video Production
Seasoned Advice (cooking)
Home Improvement
Personal Finance & Money
Academia
Law
Physical Fitness
Gardening & Landscaping
Parenting
more (10)
English Language & Usage
Skeptics
Mi Yodeya (Judaism)
Travel
Christianity
English Language Learners
Japanese Language
Chinese Language
French Language
German Language
Biblical Hermeneutics
History
Spanish Language
Islam
Русский язык
Russian Language
Arqade (gaming)
Bicycles
Role-playing Games
Anime & Manga
Puzzling
Motor Vehicle Maintenance & Repair
Board & Card Games
Bricks
Homebrewing
Martial Arts
The Great Outdoors
Poker
Chess
Sports
more (16)
MathOverflow
Mathematics
Cross Validated (stats)
Theoretical Computer Science
Physics
Chemistry
Biology
Computer Science
Philosophy
Linguistics
Psychology & Neuroscience
Computational Science
more (10)
Meta Stack Exchange
Stack Apps
API
Data
Blog
Facebook
Twitter
LinkedIn
Instagram
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.2.5.38499
Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.
This site is not affiliated with Linus Torvalds or The Open Group in any way.
Unix & Linux Stack Exchange works best with JavaScript enabled