Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Linux

Edit GRUB safely: Grub Customizer or the command line

Change the GRUB default entry, timeout and kernel options from the command line on Debian, Ubuntu and RHEL, and see when Grub Customizer is worth installing.

CloudSat teamNovember 18, 20266 min read
Abstract illustration of a boot menu drawn as a column of glowing horizontal bars, one highlighted, above a stylized circuit board
On this pageBefore you touch the bootloader

GRUB 2 is the bootloader on almost every mainstream Linux distribution: it shows the boot menu, picks a kernel and hands it a command line. Nearly every change you will want (default entry, menu timeout, kernel parameters, serial console) comes down to editing one settings file and regenerating the menu. Grub Customizer is a graphical tool that does the same for desktop users. On a server you have no desktop, so the command line is the tool, and it is not hard once you know which file is which.

Before you touch the bootloader

A typo here can stop a machine from booting, so prepare two things first. Keep a copy of the settings file:

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

Then make sure you can see the boot screen if something goes wrong. On a laptop that is the monitor. On a virtual server it is the provider's console, since SSH is gone the moment the kernel fails to start. On a CloudSat server, ask support for the rescue or VNC console before you begin (recovery tools explains the options).

How the GRUB files fit together

Path Role Edit it?
/etc/default/grub Main settings: default entry, timeout, kernel options Yes
/etc/default/grub.d/*.cfg Drop-in files read after the main file (Debian, Ubuntu) Yes, and check them for overrides
/etc/grub.d/ Scripts that generate the menu entries Rarely; 40_custom holds hand-written entries
/boot/grub/grub.cfg (Debian, Ubuntu) or /boot/grub2/grub.cfg (RHEL family) The generated menu Never by hand
/boot/loader/entries/*.conf One entry per installed kernel (RHEL family) Through grubby

The generated grub.cfg is rebuilt on every kernel update, so hand edits there vanish. Always change the inputs and regenerate.

The settings worth knowing

Open /etc/default/grub with sudo nano /etc/default/grub (or your editor of choice). These are the lines that matter:

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=5
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0,115200n8"
  • GRUB_DEFAULT picks the entry that boots: 0 is the first one, saved remembers a choice made with grub-set-default or grub-reboot, and a title string such as "Advanced options for Ubuntu>Ubuntu, with Linux 6.8.0-45-generic" pins a specific kernel inside a submenu.
  • GRUB_TIMEOUT is the number of seconds the menu waits. GRUB_TIMEOUT_STYLE is menu (show it), countdown or hidden.
  • GRUB_CMDLINE_LINUX_DEFAULT adds kernel options to normal boots only. GRUB_CMDLINE_LINUX adds them to every entry, recovery mode included. Put anything you need to rescue the system, such as a serial console, in the second one.
  • GRUB_DISABLE_OS_PROBER controls whether GRUB looks for Windows or other systems on a dual-boot machine. GRUB 2.06 and later skip the scan by default; set it to false if your other OS disappeared from the menu.

For a serial console, which some virtual servers expose, add these two lines and keep console=ttyS0,115200n8 in GRUB_CMDLINE_LINUX:

GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"

Apply the change on Debian and Ubuntu

Regenerate the menu, then reboot and confirm the kernel received what you asked for:

sudo update-grub
sudo reboot
cat /proc/cmdline

update-grub is a wrapper around grub-mkconfig -o /boot/grub/grub.cfg. If /proc/cmdline does not show your change, look in the drop-in folder. Ubuntu cloud images ship /etc/default/grub.d/50-cloudimg-settings.cfg, which sets GRUB_CMDLINE_LINUX_DEFAULT again after the main file is read, so your edit is silently replaced. Edit that file instead, or move your options to GRUB_CMDLINE_LINUX:

grep -rn "CMDLINE\|TIMEOUT" /etc/default/grub.d/

Apply the change on RHEL, AlmaLinux, Rocky Linux and Fedora

The RHEL family stores one Boot Loader Specification entry per kernel under /boot/loader/entries/, and the kernel options live in those entries. Starting with EL 9.3, grub2-mkconfig no longer rewrites them unless you add --update-bls-cmdline, which is why edits to /etc/default/grub often seem to do nothing. Use grubby, which edits the entries directly:

sudo grubby --update-kernel=ALL --args="console=ttyS0,115200n8"
sudo grubby --update-kernel=ALL --remove-args="rhgb quiet"
sudo grubby --info=DEFAULT

For settings that are not kernel options, such as the timeout, edit /etc/default/grub and run sudo grub2-mkconfig -o /boot/grub2/grub.cfg. On EL 9 and later that path is correct for both BIOS and UEFI machines. The grub.cfg under /boot/efi/EFI/ is a small stub that loads it, so do not overwrite the stub.

Choose which kernel boots

List the menu titles on Debian or Ubuntu:

awk -F\' '/menuentry |submenu /{print $2}' /boot/grub/grub.cfg

To test a kernel for one boot only, set GRUB_DEFAULT=saved, run sudo update-grub once, then:

sudo grub-reboot "Advanced options for Ubuntu>Ubuntu, with Linux 6.8.0-45-generic"
sudo reboot

The next boot uses that kernel and the one after returns to the saved default. grub-set-default makes the choice permanent. On the RHEL family, sudo grubby --default-kernel shows the current default and sudo grubby --set-default=/boot/vmlinuz-VERSION changes it, with the version taken from ls /boot/vmlinuz-*.

Edit an entry once, from the menu

When a bad parameter stops the boot, fix it from the console without touching any file. Highlight the entry, press e, find the line that starts with linux, add or remove options, then press Ctrl+X or F10 to boot. Nothing is saved, so a mistake costs one reboot. Useful one-off options:

  • systemd.unit=rescue.target boots to a root shell with basic services, after asking for the root password.
  • systemd.unit=emergency.target mounts only the root filesystem, read-only.
  • nomodeset gets past a graphics driver that hangs a desktop machine.

If the menu never appears, press Esc (UEFI) or hold Shift (BIOS) as the machine starts.

Where Grub Customizer fits

Grub Customizer is a GTK application that reorders, renames and hides menu entries, sets the default and timeout, edits kernel options and changes the menu background. It needs a graphical session, so it suits desktops and remote desktops, not SSH-only servers. Debian packages it in its main archive:

sudo apt install grub-customizer

It is not in Ubuntu's own archive. Ubuntu users install it from the developer's PPA:

sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt install grub-customizer

Know what it does before you save. To reorder and rename entries, Grub Customizer restructures the scripts in /etc/grub.d/ and moves the originals aside, which can confuse later package updates and anyone else who maintains the machine. Back up /etc/grub.d/ and /etc/default/grub first, and on shared or production systems stick to the command line.

FAQ

Why did my change to /etc/default/grub do nothing?

Three usual causes: the menu was not regenerated (update-grub or grub2-mkconfig), a drop-in under /etc/default/grub.d/ overrides the value, or on the RHEL family the kernel options live in BLS entries that only grubby or --update-bls-cmdline change.

How do I remove old kernels from the menu?

Remove them with the package manager, never by deleting files in /boot. On Debian and Ubuntu, sudo apt autoremove --purge clears kernels that are no longer needed. On the RHEL family, dnf keeps a fixed number of kernels, set by installonly_limit in /etc/dnf/dnf.conf.

Should I password-protect the GRUB menu?

On a virtual server, anyone who can reach the console can already power-cycle the machine, so a GRUB password adds little. On physical machines in shared spaces it is worth it. The RHEL family sets one with a single command, sudo grub2-setpassword, and still boots normally without it. Debian and Ubuntu need a superuser and a password_pbkdf2 line (generated with grub-mkpasswd-pbkdf2) in /etc/grub.d/40_custom, and then ask for the password at every boot unless the entries are marked --unrestricted.

Does editing GRUB need a reboot to test?

Yes. Regenerating the menu only writes files. The new settings take effect at the next boot, so make changes when you can afford a restart and have console access ready.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.