SSD Nodes Learn Hosting plans →
How to do am Matt ConnorBy Matt Connor · Updated 2026-10-28

How I fit pin the next kernel wey VPS go boot

`GRUB_DEFAULT=1` for Ubuntu dey point to submenu, no be old kernel. See your real GRUB entries, then pin next boot safely without rescue console.

Wetin dey decide which kernel your VPS go boot

Na one generated file, /boot/grub/grub.cfg, dey decide which kernel your VPS go boot next. You no dey edit that file directly. You edit the input files and regenerate am. For Ubuntu cloud image, image vendor fit add some of those inputs. The generated menu fit therefore different from wetin most guides assume. Na why GRUB_DEFAULT=1 followed by update-grub no dey bring back the previous kernel: for Ubuntu, index 1 na submenu, e no be older kernel.

Follow this order. Confirm say na you get authority to choose the kernel. Read every input file, including the ones vendor add. Read the generated output and count the entries wey e really contain. Na after that you go choose pinning method. If you make mistake for machine wey you fit reach only through SSH, you go need rescue console. So, the safest answers dey for the end of this page, and dem often na the correct ones.

Ferst check say na your kernel you fit pin

uname -r
systemd-detect-virt
ls -1 /boot/vmlinuz-*

systemd-detect-virt printing kvm, qemu or xen mean say na your own kernel you dey run, and everything wey follow apply. If e print lxc or openvz, e mean say your server dey share host kernel, so no bootloader dey wey belong to you, and nothing dey wey you fit pin. For that case, uname -r go report version wey no dey appear for /boot/vmlinuz-* at all, because na host own the kernel wey dey run, and no setting for your disk fit change am.

ls -1 /boot/vmlinuz-* na the real list of kernels wey you fit choose from. If e get only one line, dem don already delete the previous kernel, and no bootloader setting fit bring am back. This one usually happen during autoremove, so e good make you understand am before you clean up old kernels on Ubuntu for server wey matter to you.

File wey you edit no be the file GRUB dey read

/etc/default/grub hold plain shell variable assignments. Na input be this. /boot/grub/grub.cfg na output, and e dey open with # DO NOT EDIT THIS FILE plus the reason. Anything wey you write inside the output go disappear next time dem install or remove kernel package, because package scripts go regenerate am.

cat /usr/sbin/update-grub

update-grub na wrapper. E dey run grub-mkconfig -o /boot/grub/grub.cfg, wey dey read the variables, run every script for /etc/grub.d/, then write the result. Two commands, one direction: input dey enter, grub.cfg dey come out.

Wetin go override your setting: /etc/default/grub.d

grep -rn '^[^#]' /etc/default/grub /etc/default/grub.d/

The second path na the part wey people dey miss. grub-mkconfig go source /etc/default/grub first, then every *.cfg file wey dey inside /etc/default/grub.d/ according to glob order. Read the code wey dey do am:

grep -n 'default/grub' /usr/sbin/grub-mkconfig

Sourcing na plain shell, so the last assignment go win. Ubuntu cloud images dey ship files for that directory, and dem dey set things like timeout and kernel command line after dem don already read your file. Your GRUB_TIMEOUT=10 for /etc/default/grub go overwrite a moment later by vendor file wey set am to 0. The grep command above go print the exact assignments for your image, so read those ones instead of trusting this sentence.

The practical rule be say: put your own settings for file wey go sort last, like /etc/default/grub.d/99-local.cfg, instead of editing /etc/default/grub. That way, nothing wey the image ship fit come after your own setting.

Wetin GRUB_FORCE_PARTUUID dey change, and wetin e no dey change

grep -rn GRUB_FORCE_PARTUUID /etc/default/grub /etc/default/grub.d/
grep -n GRUB_FORCE_PARTUUID /etc/grub.d/10_linux
sudo grep -n 'root=PARTUUID' /boot/grub/grub.cfg

GRUB_FORCE_PARTUUID dey change wetin go inside each boot entry. The generator dey write root=PARTUUID=... direct for the kernel command line, add one set partuuid= line, and try booting without initrd first. If that attempt fail, e go fall back to booting with am. The image build dey write am inside /etc/default/grub.d/40-force-partuuid.cfg under the comment Force boot without an initramfs by setting GRUB_FORCE_PARTUUID. As of 2026-10-27, Ubuntu image build scripts dey do that only for minimized images and images wey dem build with replacement kernel. So, for standard image, the first grep fit print nothing. The second grep go show you the code wey dey act on the variable, inside /etc/grub.d/10_linux. That script dey your own disk, and na e be the authority for wetin your image dey do.

Wetin e no dey change na how many entries you go get. The loop for 10_linux wey dey go through the installed kernels, for linux in ${reverse_sorted_list}, no get im own test for the variable. The test dey inside the linux_entry function. The loop dey call that function once for every entry wey e write. So, the variable dey shape wetin go inside each entry, but e never decide whether the entry go get written. The menu shape depend on GRUB_DISABLE_SUBMENU and GRUB_DISABLE_RECOVERY, and the cloud image files no set dem. Count wetin you get.

sudo grep -cE '^\s*(menuentry|submenu) ' /boot/grub/grub.cfg
sudo grep -nE '^\s*(menuentry|submenu) ' /boot/grub/grub.cfg

Even if na only one kernel dey installed, Ubuntu's 10_linux dey write one top-level entry for the newest kernel. The identifier for am dey start with gnulinux-simple-. After that, e go write one submenu 'Advanced options for Ubuntu' wey hold one advanced entry and one recovery entry for every kernel, starting from the newest. So, the count na at least 4 with one kernel. Every extra kernel go add two more lines inside the submenu. Index 0 na the newest kernel. Index 1 na the submenu itself, so GRUB_DEFAULT=1 no dey ever name older kernel. The normal entry for the previous kernel dey inside the submenu, for 1>2 when recovery entries dey present. If the value wey you set no name any entry, GRUB go fall back to the first entry. Na the new kernel you dey try avoid. Either way, the fix na to name the entry wey you mean by identifier, and the next sections go explain am. You no need rebuild anything.

Moving the vendor file aside no dey add entries, so no do am for that reason. E switches every entry from the initrd-less PARTUUID path back to ordinary initrd boot. That one na separate change to how your provider image dey find its root filesystem. If you wan see wetin change to the inputs go produce before e take effect, grub-mkconfig without -o go write to standard output and touch nothing for disk.

sudo grub-mkconfig 2>/dev/null | grep -nE '^\s*(menuentry|submenu) '

Compare am with the same grep for /boot/grub/grub.cfg. Nothing don write yet. Take snapshot before you run update-grub for real.

If your only goal na to survive one bad kernel, stop here and use the safer options wey dey further down. Changing bootloader inputs for remote server to escape one upgrade na more risk than the problem worth.

Why entry numbers no be the correct thing to pin

GRUB_DEFAULT dey accept number, title, or identifier. Numbers dey count top-level entries from 0. Nested entry dey use > as separator, so GRUB_DEFAULT="1>2" mean the entry for index 2 inside submenu for index 1.

Indices dey change. 10_linux dey list kernels with the newest one first, and e dey put two entries for each kernel inside the submenu: one normal entry and one recovery entry. So when you install kernel, every older submenu entry dey move down by two. When you remove kernel, dem dey move up by two. Your carefully selected 1>2 still dey resolve after that. But e don dey point to different kernel, and the one wey you mean don move to 1>4. For top level, nothing dey shift: 0 still be whichever kernel be the newest, and 1 still be the submenu. No error go show, no warning go show, and you go only discover am after reboot.

Identifiers inside the submenu no dey move, because each one contain the kernel version, in the form gnulinux-<version>-advanced-<id> or gnulinux-<version>-recovery-<id>. The top-level gnulinux-simple- identifier na the exception. E no get version inside am, so e always dey resolve to whichever kernel be the newest. If you pin am, e go quietly follow the next kernel wey you install. Read your own one:

sudo awk -F"'" '/menuentry_id_option/ {print $2, "==>", $4}' /boot/grub/grub.cfg

Ignore the first few lines for the output. Dem na the variable wey dey define for the header. After that, the left side na the title wey reader dey see, and the right side na the identifier wey you pass to the tools. For entry inside submenu, join the submenu identifier and the entry identifier with >, for that order, exactly as the numeric form dey do.

Boot the previous kernel one time with grub-reboot

One-time selection na the correct move for remote server, because e go undo itself. grub-reboot dey write next_entry inside /boot/grub/grubenv. GRUB dey read that variable, clear am, then save the cleared value before e boot anything. So if kernel panic, e no go try that kernel again for the next boot. You get one attempt, then the machine go return to the normal default by itself.

First confirm say your generated config dey read that variable at all:

sudo grep -n -B2 -A5 'next_entry' /boot/grub/grub.cfg

You need see one load_env line and one block wey set default from next_entry. Ubuntu's /etc/grub.d/00_header dey write that block inside every config wey update-grub generate, whether GRUB_FORCE_PARTUUID dey set or not. For boot time, e dey load grubenv only when that file dey exist and e no empty. If grep no print anything, e mean say the grub.cfg wey dey disk no come from update-grub. Somebody fit don edit am by hand, or another tool fit don write am. Because of that, grub-reboot go work for the shell but the bootloader go ignore am. Regenerate the config with sudo update-grub, then run the grep again.

sudo grub-reboot '<the identifier you copied>'
sudo grub-editenv list

grub-editenv list suppose print one next_entry= line wey hold exactly wetin you pass. Open your provider's console for browser tab, then reboot and check the result.

sudo reboot
uname -r

If uname -r report the older version, e mean say the pin work. If e report the new version, either the identifier no resolve or grubenv no dey read. The machine still come up either way, and na that be the reason to use the one-shot form.

Make the choice stick with GRUB_DEFAULT=saved

GRUB_DEFAULT=saved dey make the default come from saved_entry for grubenv, and you set that value with grub-set-default. E dey survive kernel installation, because update-grub dey rewrite grub.cfg and e no dey touch grubenv.

echo 'GRUB_DEFAULT=saved' | sudo tee /etc/default/grub.d/99-local.cfg
sudo update-grub
sudo grub-set-default '<the identifier you copied>'
sudo grub-editenv list
sudo grep -n 'set default' /boot/grub/grub.cfg

The last command suppose print set default="${saved_entry}". If e print set default="0", something wey source after your file don set GRUB_DEFAULT back to literal value, so list /etc/default/grub.d/ again and check say 99-local.cfg really dey sort last.

GRUB_SAVEDEFAULT=true na different setting, and e easy to mix am up with this one. E dey save anything wey you just boot as the new default, so the default dey follow the last successful boot. For server, unattended reboot fit quietly change your pin. Leave am off unless na wetin you want.

Pin by identifier still fit fail one way. If you remove the kernel wey e name, the identifier no go resolve again, and e go return you to the first entry. So hold the package too, or make sure autoremove no fit remove that kernel.

Put the menu for provider console

To choose interactively, the menu must show for screen, but cloud images dey hide am. Put these ones inside the file wey get the last name, then run sudo update-grub.

GRUB_TIMEOUT=10
GRUB_TIMEOUT_STYLE=menu
GRUB_RECORDFAIL_TIMEOUT=10

GRUB_TIMEOUT_STYLE=hidden together with GRUB_TIMEOUT=0 no dey show anything, so person wey dey watch the console go see kernel messages start immediately and conclude say bootloader skip. GRUB_RECORDFAIL_TIMEOUT na the separate timeout wey dem use after boot wey no complete. Cloud images set am to 0 too. Na why server wey just fail to boot still no go stop and wait for you.

If your provider dey give serial console instead of graphical one and you still no see anything, GRUB dey write to terminal wey you no fit see. Add both lines together, because the first one selects the outputs and the second one configures the port:

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

From now on, dem go add ten seconds to every boot. Set the timeout back to 0 when you don finish.

A safer options pass editing the bootloader

To change bootloader input for machine wey you fit reach only through SSH, na the option with the highest risk for this page. Cheaper solutions dey, and dem usually solve the real problem.

Hold the kernel packages. If wetin you want be “make newer kernel no come meet me”, tell the package manager instead of telling the bootloader.

apt list --installed 2>/dev/null | grep -E '^linux-(image|headers|generic|virtual|kvm|aws|azure|gcp|oracle)'
sudo apt-mark hold linux-image-virtual linux-headers-virtual
apt-mark showhold

Use the names wey the first command print, because cloud images often install the virtual or kvm flavour instead of generic. If the newer kernel show up around image refresh and you suspect say the release itself change under you, e no change, because a point release na the updates wey you already get, bundled inside new install media and e no give server wey already patched anything wey dem no offer am weeks before. apt upgrade dey skip held package. Before apt 3.0, like the 2.8 series for Ubuntu 24.04, e announce the skip with The following packages have been kept back:. From apt 3.0 onward, including apt 3.2.0 wey Ubuntu 26.04 ship, apt upgrade list the same packages under Not upgrading: instead, and na only apt-get upgrade still print the old header. unattended upgrades for Ubuntu dey skip held package too. The cost dey real: held kernel no dey receive security fixes, so treat am as temporary pause with a date, then release am with sudo apt-mark unhold. If you dey avoid kernel updates because reboot dey cause downtime, and not because one kernel bad, live kernel patching for a VPS go solve that one instead.

Take snapshot before the upgrade. Snapshot fit restore within minutes, without typing for console and without risk of bootloader change wey apply halfway. Take snapshot, upgrade, reboot, then verify. If the new kernel get problem, roll back, and the boot path go be exactly as e be before.

Use the console or rescue image for a box wey don already go down. Once the server no fit boot, na not inside bootloader config you go fix am, and that recovery path get its own procedure: wetin to do when VPS no fit boot after kernel update.

Wetin fit break, and the message wey you go see

Your edit to /boot/grub/grub.cfg disappear. Dem install or remove kernel package, e maintainer script run update-grub, and e regenerate the file from the input files. The # DO NOT EDIT THIS FILE header show the two input locations. Edit those ones.

grub-editenv: error: environment block too small. /boot/grub/grubenv no dey, or e no complete. Recreate am with sudo grub-editenv /boot/grub/grubenv create, set your value again, then confirm with sudo grub-editenv list.

Pinned kernel dey panic with VFS: Unable to mount root fs on unknown-block(0,0). The entry wey you pin point to kernel or initrd wey no dey disk again. E usually happen because dem remove the package while the identifier remain for grubenv. To recover, boot a working entry from console, then clear the stale value.

uname -r no change after reboot wey you expect say go change am. Check these three things in order: grub-editenv list still dey show your value, or system don consume am; the identifier wey you set dey inside current grub.cfg; and grub.cfg get set default line wey dey read the variable wey you set. One of these three go explain the matter every time.

Menu show by itself after crash. GRUB record boot wey no complete inside grubenv as recordfail=1. For the next boot, e replace the normal timeout with GRUB_RECORDFAIL_TIMEOUT. Stock cloud image set am to 0, so system boot straight without showing menu. This mean menu go wait for you after crash only when that timeout pass 0, for example because you set GRUB_RECORDFAIL_TIMEOUT=10 as we explain for the console section above. Clear am with sudo grub-editenv /boot/grub/grubenv unset recordfail after the machine don become healthy.


The one sentence wey worth keeping be this: the file wey you edit no be the file wey GRUB dey read, and for cloud image, na the gap between both files dey cause the confusion. Read the generated config first. Everything for this page follow from wetin the file actually talk.

FAQ

GRUB_DEFAULT=1 change VPS wey kernel e dey boot why?

Na because for Ubuntu, index 1 no be old kernel. 10_linux dey write the newest kernel as entry 0 and Advanced options for Ubuntu submenu as entry 1, even when na only one kernel dey installed. Normal and recovery entries for every kernel dey inside that submenu. Nothing for Ubuntu cloud image dey override GRUB_DEFAULT itself: 00_header dey write your value into grub.cfg, wey you fit see with sudo grep -n 'set default' /boot/grub/grub.cfg. List the real entries with sudo grep -nE '^\s*(menuentry|submenu) ' /boot/grub/grub.cfg, then pin am by identifier. Join the submenu and entry identifiers with >. GRUB_FORCE_PARTUUID, if your image set am, only change how each entry dey find its root filesystem. E no change the number of entries.

How I fit boot the previous kernel just once?

Run sudo grub-reboot '<identifier>' with an identifier wey you copy from your own grub.cfg, then reboot while provider console don already open. GRUB dey clear next_entry before e boot, so the choice go apply for exactly one attempt. If the kernel panic, e no go retry am. Confirm say the value enter with sudo grub-editenv list. Before you depend on am, run sudo grep -n next_entry /boot/grub/grub.cfg. A config wey update-grub no generate fit never load grubenv, and e go ignore the command without any error.

I suppose pin by entry number or by identifier?

Use identifier. Entry numbers na positions for a list wey 10_linux dey rebuild with newest first. Each kernel get two entries inside the submenu. So, when you install or remove any kernel, every submenu entry shift by two. A stale 1>2 still fit resolve to a real but wrong entry, and nothing go print to warn you. Identifiers for entries inside the submenu contain the kernel version. So, dem either match the kernel wey you mean or fail to resolve. Skip the top-level gnulinux-simple- identifier. E no get version, and e always follow the newest kernel. List dem with sudo grep -n menuentry_id_option /boot/grub/grub.cfg, then copy the quoted string wey follow each entry line.

Holding the kernel package safer pass changing the bootloader?

For the usual goal, yes. sudo apt-mark hold linux-image-virtual linux-headers-virtual dey stop newer kernel from arriving at all. So the boot path no go change, and nothing go spoil because of a console wey you fit no get access to. First check the flavour names wey dey installed for your own box with apt list --installed. Then confirm the hold with apt-mark showhold. The trade-off be say held kernel no go receive security fixes. So decide when you go run sudo apt-mark unhold before you run the hold.

Dis article help you?