This tutorial explains how to change the grub boot order in Debian from the command line in a few easy steps. The steps described in this article are useful for other Debian-based Linux distributions, including Ubuntu.

GRUB is a boot loader that allows users to boot multiple operating systems and kernel configurations. After reading this tutorial, you’ll know how to define a different OS or kernel to boot by default and how to customize some boot options.

In the image below, you can see a grub menu with 3 items: Debian GNU/Linux, Advanced options for Debian GNU/Linux, and Windows 10. Because the counting starts from zero, the first item (Debian) is 0, the second item (Advanced options) is 1, and the third item (Windows) is 2.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/Change-grub-boot-order-Debian-Linux-01.png" data-lazy- height="668" src="data:image/svg xml,” width=”939″>

By default, grub will boot item 0. Thus to change the boot order, you need to define the number of items you want to boot by default in the grub configuration file /etc/default/grub.

Change grub boot order

To change the boot order, prioritize a different OS or kernel configuration edit the file /etc/default/grub using any text editor you want. You can edit it using nano, as shown in the example below. Remember, you need superuser privileges to edit the grub configuration file.

sudo nano /etc/default/grub

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/Change-grub-boot-order-Debian-Linux-02.png" data-lazy- height="224" src="data:image/svg xml,” width=”939″>

Find the following line

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/Change-grub-boot-order-Debian-Linux-03.png" data-lazy- height="516" src="data:image/svg xml,” width=”939″>

Edit the line replacing 0 by the item number you want to boot by default. In my case, I want to change the default boot to Windows. Thus I set the third item, 2 (because the count starts from 0).

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/Change-grub-boot-order-Debian-Linux-04.png" data-lazy- height="516" src="data:image/svg xml,” width=”939″>

If you are editing the file using nano, exit saving the change by pressing CTRL X and Y.

Then update grub by executing sudo update-grub as shown below.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/Change-grub-boot-order-Debian-Linux-05.png" data-lazy- height="404" src="data:image/svg xml,” width=”939″>

As you can see now, Windows will boot by default.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/Change-grub-boot-order-Debian-Linux-06.png" data-lazy- height="700" src="data:image/svg xml,” width=”939″>

Additional settings you can edit from /etc/default/grub

You can edit additional settings defined in the /etc/default/grub configuration file.


As you can see in the following image, below the line GRUB_DEFAULT=0, there is the line GRUB_TIMEOUT=5. This line defines the time grub will wait until booting automatically. Replace the 5 for the number of seconds you want grub to wait. For example, for grub to wait 10 seconds to boot the GRUB_DEFAULT=0, replace that line with the following line.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/Change-grub-boot-order-Debian-Linux-07.png" data-lazy- height="516" src="data:image/svg xml,” width=”939″>

The line GRUB_CMDLINE_LINUX_DEFAULT=”quiet” is used to pass kernel boot options. In the screenshot above, the option is “quiet”, which means the boot process will be shown in text mode as in the screenshot below.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/Change-grub-boot-order-Debian-Linux-08.png" data-lazy- height="704" src="data:image/svg xml,” width=”939″>

The quiet option provides additional transparency to the boot process allowing the user to see steps and succeed or fail.

Another option you can pass to the line GRUB_CMDLINE_LINUX_DEFAULT=  is the option “splash”. If you replace “quiet” with “splash” like in the line below, the boot process won’t be displayed in text mode; you will see a logo loading instead, as shown in the following image.

GRUB_CMDLINE_LINUX_DEFAULT=”splash”

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/Change-grub-boot-order-Debian-Linux-09.png" data-lazy- height="702" src="data:image/svg xml,” width=”939″>

Even if some people consider this option a better format (you can customize it), this option doesn’t give users a live view of the boot process.

The line GRUB_CMDLINE_LINUX_DEFAULT= can also be used to boot the system in text mode. To boot in text mode, instead of quiet or splash, you need to use the option text as shown in the screenshot below.

GRUB_CMDLINE_LINUX_DEFAULT=”text”

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/Change-grub-boot-order-Debian-Linux-10.png" data-lazy- height="545" src="data:image/svg xml,” width=”939″>

Exit saving the change and run:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/Change-grub-boot-order-Debian-Linux-11.png" data-lazy- height="270" src="data:image/svg xml,” width=”939″>

Disable the display manager using systemctl. In my case, my display manager is LightDM. Replace lightdm with your current display manager and run the command below.

sudo systemctl disable lightdm

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/Change-grub-boot-order-Debian-Linux-12.png" data-lazy- height="191" src="data:image/svg xml,” width=”939″>

Reboot in text mode.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/Change-grub-boot-order-Debian-Linux-13.png" data-lazy- height="191" src="data:image/svg xml,” width=”531″>

Now you can log in in text mode. If you want to launch a graphical session, run:

sudo systemctl start

Where must be replaced by your display manager name (e.g., gdm3).

Conclusion

As you can see, dealing with grub is very easy, and you can control the way your system boots in a few steps any Linux user level can learn. When dealing with it, the most common mistake is not remembering to run update-grub every time the file is edited. Remember, when selecting the boot order, the counting starts from zero; if you type a wrong order number, your system will not boot as expected.

The quiet option at line GRUB_CMDLINE_LINUX_DEFAULT= may be better than splash because it allows the user to see the boot process transparently.

The last section of this tutorial showing how to boot from a terminal or console is useful if your graphical environment fails to prevent you from booting the system. Also, there are associated security bugs to the graphical boot process; that’s why some users prefer to boot their systems in text mode. This would be the proper configuration for servers or devices which need to save or optimize resources. Once logged in text mode, users can start X manually with commands startx or systemctl.

I hope this tutorial was useful. Keep following Linux Hint for more Linux tips and tutorials.

About the author

<img alt="" data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/linuxinstitute_icono-150×150.png" height="112" src="data:image/svg xml,” width=”112″>

Ivan Vanney

Ivan Vanney has over 2 years as writer for LinuxHint, he is co-founder of the freelance services marketplace GIGopen.com where he works as a sysadmin.