How to update the Linux kernel on a VPS and roll back if it will not boot
A kernel update is the one routine patch that only takes effect after a reboot, and the reboot is where a cheap VPS can fail to come back. Critical kernel fixes tend to arrive in waves, and you want to apply them the same day without gambling the server. The safe pattern is short: take a snapshot, install the kernel, make the boot menu reachable, reboot, check, and know exactly how you would go back. The commands here are for Ubuntu 22.04, 24.04 and 26.04 and Debian 12 and 13, using apt and the GRUB bootloader.
What can go wrong, and what to protect first
Most kernel updates are uneventful. When one goes wrong it is usually one of these: a module your server depends on (ZFS, WireGuard on older releases, a vendor driver built with DKMS) fails to build for the new kernel, /boot runs out of space halfway through, or the new kernel simply does not boot on your provider's virtual hardware. In each case the server stops answering SSH and your app is down until you fix it from a console.
- A full-disk snapshot at your cloud provider. This is the fastest way back to the exact state before the update.
- A recent database dump stored off the server. A snapshot lives at the same provider as the server. A dump in your own bucket survives a lost account or a deleted server. See database backups to S3.
- Any attached block-storage volumes. On Hetzner, backups and snapshots do not include attached Volumes, so back up their contents separately.
First, record what the server runs now, so you can tell later whether the new kernel is the one that booted:
uname -r
dpkg --list 'linux-image-*' | grep '^ii'
df -h /boot
ls /boot/grub/grub.cfguname -r is the running kernel. The dpkg line lists every installed kernel package. If df shows /boot as a separate, nearly full partition, free space before you continue. If /boot/grub/grub.cfg does not exist, your server does not boot with GRUB, and the boot-menu steps below do not apply to it. Use the snapshot rollback instead.
Take a snapshot before the update
Hetzner and DigitalOcean both recommend powering the server off before a snapshot so the disk is consistent. A snapshot of a running server usually works, but a database that was mid-write can need recovery when it starts. For a short planned window, shut down, snapshot, and power back on.
On Hetzner Cloud with the hcloud CLI:
hcloud server shutdown --wait <server-name>
hcloud server create-image --type snapshot --description "before-kernel-$(date +%F)" <server-name>
hcloud server poweron <server-name>On DigitalOcean with doctl:
doctl compute droplet-action shutdown <droplet-id> --wait
doctl compute droplet-action snapshot <droplet-id> --snapshot-name "before-kernel-$(date +%F)" --wait
doctl compute droplet-action power-on <droplet-id> --waitOn other providers, take the snapshot from the console or CLI as described in the guides for Vultr, Linode, AWS EC2, Lightsail, Azure and Google Cloud.
Wait until the snapshot shows as available before you start the update. A snapshot that is still being created is not a rollback point yet.
Make the GRUB menu reachable from the web console
If the new kernel will not boot, the quickest fix is to pick the previous kernel from the GRUB menu in your provider's web console (the browser screen that shows the server's display). Many cloud images hide that menu or set a timeout of zero, so it flashes past before you can press a key. Find where the timeout is set:
grep -rn 'GRUB_TIMEOUT' /etc/default/grub /etc/default/grub.d/ 2>/dev/nullSet these two values in the file that sets them. If a file in /etc/default/grub.d/ sets GRUB_TIMEOUT, change it there, because files in that directory are read after /etc/default/grub and win.
GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=10With GRUB_TIMEOUT_STYLE=menu, GRUB shows the menu and waits GRUB_TIMEOUT seconds before booting the default entry. Regenerate the GRUB configuration so the change takes effect:
sudo grub-mkconfig -o /boot/grub/grub.cfgsudo update-grub runs the same command on Debian and Ubuntu. The 10-second menu adds 10 seconds to every boot. Set the timeout back to its old value once you trust the new kernel, if you prefer.
Install the new kernel
sudo apt update
apt list --upgradeable 2>/dev/null | grep -i linux
sudo apt upgradeapt upgrade installs new packages when an upgrade needs them, which is how a new kernel version arrives, and it never removes installed packages. That keeps your current kernel on disk as a fallback. When it finishes, confirm the new kernel package is there:
dpkg --list 'linux-image-*' | grep '^ii'Do not run sudo apt autoremove until the new kernel has booted and you are happy with it. Autoremove removes packages that were installed automatically and are no longer needed, and older kernel packages fall into that group. Removing the old kernel too early takes away your fallback in the boot menu.
Reboot and check the server
Open your provider's web console in a browser tab before you reboot, so you can watch the boot if SSH does not come back.
sudo rebootWhen you can log in again, check that the new kernel is running and nothing failed to start:
uname -r
systemctl --failed
sudo journalctl -b -p err --no-pager | tail -n 50| Check | Command | What you want to see |
|---|---|---|
| Running kernel | uname -r | The newest version from the dpkg list |
| Failed services | systemctl --failed | 0 loaded units listed |
| Boot errors | journalctl -b -p err | Nothing new compared with before the update |
| Containers | docker ps | Every container you expect, with status Up |
| The app itself | curl -I https://<your-domain> | The same HTTP status as before |
If the server does not come back
You have two ways back. Booting the old kernel is faster and keeps everything written since the snapshot. Restoring the snapshot is the reset button.
- Open the web console and reboot or power-cycle the server from the provider's panel.
- When the GRUB menu appears, choose Advanced options for Ubuntu (or Advanced options for Debian GNU/Linux).
- Pick the entry for the kernel version you recorded with
uname -rbefore the update, not its recovery mode entry. - Log in and check
uname -rshows the old version.
Picking an entry from the menu only lasts for that boot. To stop apt from pulling the broken kernel back in, hold the kernel metapackage until a fixed version ships. Find its name first: it is the linux-image package with no version number in it, such as linux-image-generic or linux-image-virtual on Ubuntu and linux-image-amd64 on Debian.
dpkg --list | grep -E '^ii +linux-(image|generic|virtual)'
sudo apt-mark hold <kernel-metapackage>
apt-mark showholdRun sudo apt-mark unhold <kernel-metapackage> when a newer kernel is out. If you cannot reach the menu at all, restore the snapshot. On Hetzner, list your snapshots and rebuild the server from one:
hcloud image list --type snapshot
hcloud server rebuild --image <snapshot-id> <server-name>On DigitalOcean:
doctl compute snapshot list --resource droplet
doctl compute droplet-action restore <droplet-id> --image-id <snapshot-id> --waitRebuilding or restoring from a snapshot overwrites the server's disk. Anything written after the snapshot was taken, such as new orders, uploads or database rows, is gone unless you have a newer backup of it. Take a fresh database dump first if the server still boots far enough to run one.
Schedule kernel updates with a snapshot in front
On Ubuntu, unattended-upgrades is installed by default and applies security updates automatically. By default it does not reboot, so a new kernel sits installed but not running until someone reboots. To let it reboot at a quiet hour, set these in /etc/apt/apt.conf.d/50unattended-upgrades:
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:30";Then schedule a daily provider snapshot an hour before that reboot time, with a retention window so old snapshots are deleted. Every automatic reboot then has a rollback point that is at most an hour old. Check what a run would do with a dry run, and read past runs in the log:
sudo unattended-upgrade -v --dry-run
sudo less /var/log/unattended-upgrades/unattended-upgrades.logIf you would rather apply kernels by hand while letting other security updates run, exclude them in the same file. Entries are Python regular expressions, so "linux-"; matches every package whose name starts with linux-:
Unattended-Upgrade::Package-Blacklist {
"linux-";
};Prove the rollback works before you need it
The safest kernel update is one you have already done on a copy. Create a temporary server from the snapshot, run the update and reboot there, and delete it when you are done.
# Hetzner
hcloud server create --name kernel-test --type <server-type> --image <snapshot-id> --ssh-key <ssh-key-name>
# DigitalOcean
doctl compute droplet create kernel-test --image <snapshot-id> --size <size-slug> --region <region> --ssh-keys <ssh-key-id>If the copy boots the new kernel and your app works on it, update the real server. If it does not, you have found the problem without any downtime, and you have also proved the snapshot restores into a working server. On Hetzner, a new server must use the same architecture (x86 or Arm) as the snapshot.
A copy built from a snapshot has the same configuration as production. Stop any cron jobs, queue workers or outgoing email on it straight away, so it does not send messages or write to shared services as if it were the real server.
Frequently asked questions
- Do I have to reboot after a kernel update?
- Yes. The new kernel is only used after a reboot. Until then
uname -rshows the old version and the fix is not active. - Should I power off the server for the snapshot?
- Hetzner and DigitalOcean both recommend it for a consistent disk. For a planned kernel update the downtime is a few minutes and worth it. Scheduled daily snapshots of a running server are still useful as a fallback.
- How do I boot the previous kernel on a cloud server?
- Open the provider's web console, reboot, choose Advanced options in the GRUB menu and pick the older kernel. If the menu never appears, set GRUB_TIMEOUT_STYLE=menu and a timeout of a few seconds before your next update.
- Does apt keep my old kernel?
- Yes. Installing a new kernel does not remove the running one. Older kernels are only removed when you run apt autoremove, so wait to do that until the new kernel has proved itself.
How this was checked
Commands, limits and prices were checked against these official pages, on November 2, 2026:
- Hetzner Docs: Backups and snapshots FAQ
- Hetzner Docs: Backups and snapshots overview
- hcloud CLI reference: hcloud server create-image
- hcloud CLI reference: hcloud server rebuild
- hcloud CLI reference: hcloud server create
- DigitalOcean Docs: doctl compute droplet-action snapshot
- DigitalOcean Docs: How to create or restore Droplets from snapshots
- Ubuntu Server docs: Automatic updates
- GNU GRUB Manual: Simple configuration handling
- Ubuntu manpage: apt(8), noble
- Debian manpage: apt-mark(8), stable