Install a recent kernel on Debian with backports
Install a recent Linux kernel on Debian 13 from the official backports, boot it once to test it, then confirm it or go back to the stable kernel.
On this page
This guide explains how to install a more recent Linux kernel on Debian 13 (Trixie) from the official backports. The method includes a way back: the new kernel is booted only once for testing, and the old one remains the default until you have confirmed the new one.
At the time of writing, Debian 13 provides a 6.12 kernel in its stable repositories and a 7.2 kernel in its backports. These numbers will change: rely on what your commands display.
Prerequisites
- Debian 13 (Trixie) with GRUB as the boot loader
- SSH access with
sudoprivileges - A maintenance window, as the server must restart
- A recent backup
- Access to your client area, to restart the VPS and open the VNC console
Step 1: check the current state
grep '^PRETTY_NAME=' /etc/os-release
uname -r
dpkg --print-architecture
dpkg -l 'linux-image*' | awk '/^ii/ {print $2, $3}'
df -h /boot
ls -l /boot/grub/grub.cfg
sudo grub-probe --target=abstraction /boot/grub
command -v dkms && dkms statusCheck the following points:
| Check | Expected result |
|---|---|
| System | Debian GNU/Linux 13 (trixie) |
/boot |
Several hundred MB free |
/boot/grub/grub.cfg |
The file exists |
grub-probe --target=abstraction |
No output |
dkms status |
Note the listed modules: they will have to be compiled for the new kernel |
Next, identify the installed metapackage, then save it. This is the package that will track future kernel versions:
| Package present | Value to use |
|---|---|
linux-image-amd64 |
linux-image-amd64 |
linux-image-cloud-amd64 |
linux-image-cloud-amd64 |
linux-image-arm64 |
linux-image-arm64 |
linux-image-cloud-arm64 |
linux-image-cloud-arm64 |
META=linux-image-amd64Step 2: back up
Create a snapshot from your client area if your plan allows it, or back up the VPS with Clonezilla. Going back to the previous kernel does not replace a backup of your data.
Step 3: keep the current kernel as the default
Check where GRUB_DEFAULT is defined:
grep -rs '^GRUB_DEFAULT' /etc/default/grub /etc/default/grub.d/If the setting is in /etc/default/grub, change it to saved. If it is in /etc/default/grub.d/, edit that file instead.
sudo cp /etc/default/grub /etc/default/grub.bak
sudo sed -i 's/^GRUB_DEFAULT=.*/GRUB_DEFAULT=saved/' /etc/default/grub
sudo update-grub
sudo grep -c 'set default="${saved_entry}"' /boot/grub/grub.cfgThe last command must display 1 or more.
The title of a GRUB entry varies with the language and the system. This function finds it from the kernel version:
entree_grub() {
sudo awk -F"'" -v v="$1" '
/^submenu / { parent = $2 ">" }
/^[[:space:]]*menuentry / && index($2, v) { print parent $2; exit }
' /boot/grub/grub.cfg
}Set the current kernel as the default choice, then protect it from automatic removal:
ANCIEN=$(uname -r)
entree_grub "$ANCIEN"
sudo grub-set-default "$(entree_grub "$ANCIEN")"
sudo grub-editenv list
sudo apt-mark manual "linux-image-$ANCIEN"The saved_entry= line must mention your current kernel. If entree_grub displays nothing, stop here and check /boot/grub/grub.cfg.
Step 4: enable backports
sudo tee /etc/apt/sources.list.d/debian-backports.sources > /dev/null <<'EOF'
Types: deb
URIs: http://deb.debian.org/debian
Suites: trixie-backports
Components: main
Enabled: yes
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
EOF
sudo apt update
apt policy "$META"The backports version appears with a priority of 100 and contains ~bpo13. This priority prevents Debian from installing backports unless you ask for them.
Step 5: install the kernel
sudo apt install -t trixie-backports "$META"Read the displayed list before confirming: it must only contain the kernel and its dependencies. If you use DKMS modules, also install the matching headers, linux-headers-amd64 or linux-headers-cloud-amd64:
sudo apt install -t trixie-backports linux-headers-amd64Then update GRUB and identify the new kernel:
sudo update-grub
ls /boot/vmlinuz-*
NOUVEAU=$(ls /boot/vmlinuz-* | sed 's#.*/vmlinuz-##' | sort -V | tail -n 1)
echo "$NOUVEAU"The kernel name does not contain bpo, for example 7.2.12+deb13-amd64. Only the package version contains it.
Step 6: boot the new kernel once
entree_grub "$NOUVEAU"
sudo grub-reboot "$(entree_grub "$NOUVEAU")"
sudo grub-editenv listYou should see saved_entry= with the old kernel and next_entry= with the new one. Restart:
sudo systemctl rebootGRUB consumes next_entry at boot. If the new kernel hangs, a simple restart therefore brings back the old one.
Step 7: check the new kernel
Log back in, then check the system and your services:
uname -r
systemctl --failed
sudo journalctl -b -p err --no-pager | tail -n 30
ip -br address
sudo ss -tulpn
command -v dkms && dkms statusAlso test your applications: website, database, containers, backups and monitoring. Some messages may be harmless, but a failed service or a missing module must be understood before you confirm.
Step 8: confirm the new kernel
If everything works, tell GRUB to boot the first entry, which is the most recent kernel:
sudo grub-set-default 0
sudo grub-editenv listKeep the old kernel for a while. It remains available in the GRUB menu if needed.
Updates
Once installed, the backports kernel receives its updates with the usual commands:
sudo apt update
sudo apt upgradeThese updates can move to a new major kernel branch. Security fixes arrive on a best-effort basis, sometimes later than in the stable release: the debian-backports-announce list lets you follow them.
Go back to the stable kernel
If the new kernel does not boot
- Wait a few minutes, then restart the VPS with the restart icon on your instance page.
- Log back in over SSH and check that
uname -rdisplays the old kernel. - If the server remains unreachable, click Accéder à la console VNC (Access the VNC console), then NoVNC Console graphique (NoVNC graphical console). Restart and, in the GRUB menu, choose the advanced options, then the old kernel.
Remove the backports kernel
1. First boot the old kernel. If uname -r still displays the new one, list the kernels, then replace the version in this example. After a restart, define the entree_grub function from step 3 again:
ls /boot/vmlinuz-*
sudo grub-reboot "$(entree_grub "6.12.117+deb13-amd64")"
sudo systemctl reboot2. Go back to the stable versions. For each package from backports, this command looks for the most recent version outside backports. This way, it keeps Debian's security fixes:
A_RETROGRADER=$(for p in $(dpkg-query -W -f='${Package} ${Version}\n' | awk '/~bpo/ {print $1}'); do
v=$(apt-cache madison "$p" | awk '$3 !~ /~bpo/ {print $3; exit}')
[ -n "$v" ] && echo "$p=$v"
done)
echo "$A_RETROGRADER"Read the list. Remove from it any package you deliberately installed from backports that has nothing to do with the kernel. Then run:
sudo apt install --allow-downgrades $A_RETROGRADER3. Remove the remaining packages:
A_SUPPRIMER=$(dpkg-query -W -f='${Package} ${Version}\n' | awk '/~bpo/ {print $1}')
echo "$A_SUPPRIMER"
sudo apt purge $A_SUPPRIMER
sudo apt autoremove --purgeCheck the list again before confirming. It must not contain the kernel displayed by uname -r. If it does, or if a warning reports that the running kernel is being removed, cancel and go back to point 1.
4. Restore GRUB and remove the repository:
sudo update-grub
sudo grub-set-default 0
sudo rm /etc/apt/sources.list.d/debian-backports.sources
sudo apt update5. Check the result:
uname -r
dpkg-query -W -f='${Package} ${Version}\n' | grep -F '~bpo'
apt policy "$META"The second command must display nothing, apart from any packages you chose to keep.
Troubleshooting
The value 'trixie-backports' is invalid for APT::Default-Release
E: The value 'trixie-backports' is invalid for APT::Default-Release as such a release is not available in the sourcesThe repository is not active. Check /etc/apt/sources.list.d/debian-backports.sources, then run sudo apt update again.
APT announces the removal of many packages
Answer n. A kernel installation must not remove your applications. Check your repositories with apt policy, finish any pending updates, then try again.
No space left on device during installation
/boot is probably full. Check df -h /boot and dpkg -l 'linux-image*'. Remove an old, unneeded kernel with sudo apt purge, never the one displayed by uname -r.
A DKMS module does not compile
Check dkms status and make sure the installed headers match the kernel. An external module may not support this kernel version yet. In that case, stay on the stable kernel or wait for a compatible version of the module.
uname -r still displays the old kernel
Check that the new kernel appears in GRUB and that next_entry did contain a full title before the restart:
sudo update-grub
entree_grub "$NOUVEAU"
sudo grub-editenv listThe server always restarts on the new kernel
GRUB may not have been able to clear next_entry, particularly with LVM or RAID. From the booted system, delete the variable and choose the kernel you want:
sudo grub-editenv /boot/grub/grubenv unset next_entry
sudo grub-set-default "$(entree_grub "$(uname -r)")"If you want to go back to the old kernel, enter its version instead of $(uname -r).
The network does not come back after the restart
Open the VNC console, then check ip -br address and sudo journalctl -b -p err. If the problem comes from the new kernel, restart on the old one and follow the rollback procedure.
References
- Official Debian backports instructions
- Debian releases
- GRUB environment block
- Ubuntu HWE kernels
- Manual pages:
man grub-reboot,man grub-set-default,man apt_preferences