Read the kernel log on a VPS with dmesg
A process vanished with no error of its own. Find the OOM kill in dmesg and journalctl, and read the disk and network messages a guest kernel sends.
What the kernel log on a VPS holds
The kernel log on a VPS is the record your guest kernel keeps about its own work, and for some failures it is the only record that exists. Two commands read it. dmesg reads the kernel ring buffer directly, and journalctl -k reads the copy that systemd's journal stored. Go to one of them whenever a process died without leaving anything in its own log.
Most dmesg guides on the web are about hardware you do not have. A VPS has no USB device to unplug and no network card firmware to reload. What a guest kernel reports instead is memory pressure, plus the errors that come back from the host's virtual disk and virtual network devices. Those errors reach your application as timeouts, so they are easy to blame on the application.
Start with the newest complaints and nothing else:
sudo dmesg -T --level=err,warn | tail -40
sudo journalctl -k -p warning --no-pager | tail -40--level=err,warn and -p warning both drop the routine boot chatter, so what is left is the kernel objecting to something. If both come back empty, there may simply be no retained messages at those priorities; the last section covers missing records and blocked reads.
Why did my process disappear with no error?
A process that vanished without writing a shutdown line could have been killed by the kernel out-of-memory killer (OOM killer). The kill is delivered as SIGKILL, which no program can catch or handle, so the application never gets a chance to log anything. The kernel writes the record instead.
sudo dmesg -T | grep -iE 'out of memory|oom-kill|invoked oom-killer'
sudo journalctl -k | grep -iE 'out of memory|oom-kill'
sudo journalctl -k -b -1 | grep -iE 'out of memory|oom-kill'The third command reads the boot before this one, which matters when the box rebooted after the incident. journalctl -k implies the current boot, so without -b -1 it will look clean no matter how bad the previous boot was.
A match looks like this. The names and numbers will be yours:
mysqld invoked oom-killer: gfp_mask=0x140cca(GFP_HIGHUSER_MOVABLE|__GFP_COMP), order=0, oom_score_adj=0
oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/system.slice/mysql.service,task=mysqld,pid=1234,uid=110
Out of memory: Killed process 1234 (mysqld) total-vm:1596768kB, anon-rss:512300kB, file-rss:0kB, shmem-rss:0kB, UID:110 pgtables:1580kB oom_score_adj:0Read those lines in order:
- The
invoked oom-killerline names the process that asked for memory and could not get it. This is often not the process that died. - The
oom-kill:line says where the limit was hit.global_oommeans a system OOM rather than a cgroup OOM; allocation constraints can still restrict which memory is available.task_memcg=names the control group the victim was sitting in. - The
Out of memory: Killed processline names the victim and the memory it held when it died.anon-rssis anonymous resident memory; the badness score also counts other resident memory, swap use and page tables, and appliesoom_score_adj.
The kernel does not identify which process leaked. By default, it selects a victim using a badness score based on memory use and oom_score_adj. A 200 MB script that allocates in a loop can push a 2 GB database over the edge, and the database is what dies, because the database is bigger. That is why the log so often points at software that was behaving perfectly.
With the default vm.oom_dump_tasks=1, the kernel prints eligible tasks under Tasks state (memory values in pages):. It is long, and it is worth keeping, because it is a snapshot of memory during the OOM report.
Reading the task state table
On kernel 6.8 and newer the table header is [ pid ] uid tgid total_vm rss rss_anon rss_file rss_shmem pgtables_bytes swapents oom_score_adj name. Older kernels print the same table without the rss_anon, rss_file and rss_shmem columns. Pull it out of the ring buffer with the lines that follow it:
sudo dmesg -T | grep -A 40 'Tasks state'total_vm and rss are counted in pages, not kilobytes. On x86-64 a page is 4 KiB, so multiply rss by 4 to get KiB. A row with a large rss and an oom_score_adj of 0 was a candidate for the kill. A row at -1000 was exempt, which is what OOMScoreAdjust=-1000 in a systemd unit sets.
If the oom-kill: line carries oom_memcg= and a control group path where the example shows global_oom, and the kill line begins Memory cgroup out of memory instead of Out of memory, one control group reached its memory limit and reclaim could not reduce its usage enough. That does not establish whether the machine had free RAM. This is the confusing case, because free -h can look fine afterwards. It happens when a systemd unit carries MemoryMax=, which is how you cap memory and CPU for one service, and it happens to containers that were started with memory limits set in a Compose file. Check the group's limit and the workload's memory use.
On the service side, the same event appears in the unit's own log:
systemd[1]: app.service: A process of this unit has been killed by the OOM killer.
systemd[1]: app.service: Main process exited, code=killed, status=9/KILL
systemd[1]: app.service: Failed with result 'oom-kill'.status=9/KILL on its own only says that something sent signal 9. The kernel log is what tells you who sent it and why. Other codes point somewhere else entirely, and reading systemd exit codes is a separate skill worth having.
One case leaves no kernel message at all. systemd-oomd kills processes from userspace using pressure stall information (PSI), so its decisions never touch the kernel log. Ubuntu turned it on by default for the desktop in 22.04. Check it before you conclude nothing killed anything:
sudo journalctl -u systemd-oomd --since today
cat /proc/pressure/memoryIf /proc/pressure/memory does not exist, check whether the kernel was built with CONFIG_PSI and whether PSI was disabled at boot. psi=1 on the kernel command line enables compiled-in support that was disabled at boot; it cannot add missing kernel support. When the file does exist, some avg10 measures the recent share of time with at least some tasks stalled on memory, averaged over ten seconds. A rising value shows pressure, not a guaranteed advance warning of a kill.
A 1 GB VPS with no swap can still reclaim file-backed cache and some kernel caches, and allocations can stall in direct reclaim before an OOM kill becomes necessary. Swap adds somewhere to evict anonymous memory. Whether swap is the right answer for your workload, and what it costs on a small plan, is worked through in whether your VPS needs swap.
dmesg or journalctl -k: which one has the data?
They carry the same messages from different storage, and each one holds data the other has lost.
dmesg reads the kernel ring buffer. The buffer lives in RAM, it is a fixed size, and it is emptied by every reboot. Check the base size configured for your kernel:
grep CONFIG_LOG_BUF_SHIFT /boot/config-$(uname -r)The value is an exponent for a power of two in bytes, so 18 means a 256 KiB base buffer. CPU-based sizing and the log_buf_len= boot parameter can increase it. When it fills, the oldest lines are overwritten. Readers of /dev/kmsg can detect the loss through an EPIPE error and record sequence numbers.
That matters more than it sounds, because a public VPS generates constant kernel noise. ufw logging writes kernel messages for matching traffic, with the volume depending on the logging level, per-rule settings and rate limiting:
[UFW BLOCK] IN=ens3 OUT= MAC=... SRC=203.0.113.9 DST=198.51.100.20 PROTO=TCP SPT=52134 DPT=23 WINDOW=1024 RES=0x00 SYN URGP=0A few thousand of those push this morning's OOM report out of the buffer before lunch. So dmesg coming back clean does not mean the crash was imagined. It can simply mean the evidence was overwritten.
journalctl -k reads what journald captured, and the journal survives reboots when it is stored on disk. Check whether yours is:
journalctl --list-bootsOne row means only one boot is retained and accessible, which does not prove the journal is volatile. Volatile journals sit under /run, in RAM, and are discarded at every boot. With Storage=auto, make the journal persistent using these commands; if Storage=volatile or Storage=none is explicitly configured, change it to Storage=persistent in the [Journal] section of /etc/systemd/journald.conf first:
sudo mkdir -p /var/log/journal
sudo systemd-tmpfiles --create --prefix /var/log/journal
sudo systemctl restart systemd-journald
sudo journalctl --flush
journalctl --disk-usage--list-boots should now grow a row after the next reboot, and sudo journalctl -k -b -1 becomes the most useful command you have: it reads the previous boot's saved kernel messages. Syslog files or remote logging can also preserve kernel messages across a reboot.
The journal loses in two situations. Journald reads /dev/kmsg like any other process and can fall behind a flood of messages, and when it does it says so plainly:
systemd-journald[318]: Missed 12 kernel messagesThose messages were overwritten in the ring buffer before journald read them, so dmesg cannot recover them from that buffer. The other situation is a box that stopped before systemd started journald, such as an initramfs prompt that comes up before systemd runs, where dmesg is the only reader available. A rescue shell is not that case: rescue.target pulls in sysinit.target, which starts journald, so journalctl -k works there.
Timestamps are the last difference. dmesg prints seconds since boot. dmesg -T converts them to wall-clock time, and its manual page warns that the result can be inaccurate: the time source is not updated after a suspend and resume, and the correction dmesg applies works only for messages printed after the last resume. journalctl stamps entries as it receives them and needs no conversion. When the two disagree on a guest, suspect the conversion first, and treat it as one more reason to fix a VPS clock that drifts.
To watch either one live while you reproduce a fault:
sudo dmesg -Tw
sudo journalctl -kfAvoid dmesg -C. It empties the ring buffer, and anything journald missed is then gone for good.
Disk errors that look like application timeouts
Your VPS disk is a virtual device. The guest kernel hands a request to the host, and if the host does not answer in time the guest kernel gives up and logs it. Your application sees only a slow query or a failed write.
sudo dmesg -T | grep -iE 'I/O error|EXT4-fs error|blocked for more than'An I/O error on the virtual disk. A line like I/O error, dev vda, sector 2048 op 0x1:(WRITE) names the device and the operation that failed. It does not identify the underlying cause or rule out a physical storage fault on the host. Ordinary bandwidth or IOPS throttling delays requests rather than failing them.
A filesystem that gave up. Ext4's response depends on the error and its configuration: errors=continue keeps going, errors=remount-ro remounts read-only, and errors=panic panics the kernel. An aborted journal and read-only remount look like this:
EXT4-fs error (device vda1): ext4_journal_check_start: Detected aborted journal
EXT4-fs (vda1): Remounting filesystem read-onlyYour version of that first line will also carry a function name and a line number. From the moment of the remount, every write fails with Read-only file system while reads keep working, so a web application can serve pages normally and fail every upload. Confirm it with mount | grep ' / ' and look for ro, in the options. This is a different failure from a disk that is simply full, which fails writes with No space left on device and is usually a mismatch between what df and du report.
A task stuck waiting on the host.
INFO: task jbd2/vda1-8:214 blocked for more than 120 seconds.
Not tainted 6.8.0-45-generic #45-Ubuntu
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.The kernel prints this when a task in uninterruptible sleep has not been scheduled for longer than kernel.hung_task_timeout_secs, which is 120 seconds in this example. The warning alone does not distinguish slow I/O from a deadlock or another kernel wait; read the accompanying stack trace. A blocked journal thread, jbd2/vda1-8 in the example above, can stall filesystem writes and make the whole box appear to freeze.
One boot line is worth knowing here, because it tells you which virtual disk is which:
virtio_blk virtio2: [vda] 62914560 512-byte logical blocks (32.2 GB/30.0 GiB)Dropped packets and conntrack pressure
Network failures in the kernel also reach you as application timeouts, because the packet never arrives at the service to be logged.
nf_conntrack: nf_conntrack: table full, dropping packetConnection tracking (conntrack) stores one entry per tracked flow, and the module loads as soon as you use a stateful firewall rule or start Docker. When the table cannot make room for a new entry, the kernel drops the packet that needs it, while connections with retained entries continue to be tracked. Compare the two numbers:
sysctl net.netfilter.nf_conntrack_count net.netfilter.nf_conntrack_maxA count sitting near the maximum is the confirmation. Raise nf_conntrack_max in a file under /etc/sysctl.d/ so the change survives a reboot, and shorten the UDP timeout if the entries are mostly UDP.
A second message gets misread constantly:
TCP: request_sock_TCP: Possible SYN flooding on port 0.0.0.0:443. Sending cookies.This means the listening socket's SYN backlog filled up. An attack is one cause; legitimate connection overload is another, and the warning alone does not distinguish them. Run ss -lnt and read Recv-Q on the listening socket, which is the current queue depth, against Send-Q, which is the configured backlog. Those columns describe completed connections waiting for the application to accept them, not the SYN backlog. If that accept queue is full while traffic is normal, investigate how quickly the application accepts connections.
net_ratelimit: 24 callbacks suppressed means the kernel discarded some of its own messages to keep the log usable, so the number of events was higher than the number of lines you can see. Before reading any of this as a network fault, confirm the basics: checking whether the port is actually open and listening rules out the simpler explanation in about ten seconds.
What the boot messages say after a kernel upgrade
The first forty lines of a boot describe the machine you are really on:
sudo dmesg | head -40
sudo journalctl -k -b -1 | head -40Linux version 6.8.0-45-generic (...) ... #45-Ubuntu SMP PREEMPT_DYNAMIC ...
Command line: BOOT_IMAGE=/boot/vmlinuz-6.8.0-45-generic root=UUID=... ro console=tty1 console=ttyS0
Hypervisor detected: KVMLinux version is the kernel that actually booted, which is not always the one you installed last. Command line is what the bootloader really passed, so it settles any argument you believe you set. Hypervisor detected names the virtualisation the guest found underneath it.
After an upgrade installs a new kernel, compare what booted against what is on disk:
uname -r
ls /boot/vmlinuz-*If uname -r is older than the newest file in /boot, the machine came back on the previous kernel. Sometimes that is deliberate. Sometimes it is a failed boot that fell back without telling anyone, and a VPS that will not boot after a kernel update needs its own recovery steps. When you want one specific version to stay in charge, pinning which kernel boots is the durable fix.
One more check costs nothing: cat /proc/sys/kernel/tainted returns 0 on an untainted kernel. A non-zero value records one or more taint reasons, including an out-of-tree module, a kernel warning or error, or live patching; diagnostic headers show the flags as Tainted: instead of Not tainted.
Why is the kernel log empty or permission denied?
Restricted reads and a shared host kernel are two reasons a reader sees nothing useful; empty output can also mean no matching records remain.
The read is restricted. Plain dmesg fails like this:
dmesg: read kernel buffer failed: Operation not permittedsysctl kernel.dmesg_restrictA value of 1 requires CAP_SYSLOG on current kernels; Linux 6.8 also accepts CAP_SYS_ADMIN as a deprecated fallback, with a warning. On a full VM, sudo dmesg normally supplies the required privilege. The journal has separate filesystem permissions: root and members of systemd-journal can read system journals, and distributions or administrators can grant access to adm, wheel or other users and groups through ACLs. A user without system-journal access can read their own per-user journal when one exists, and journalctl prints an access hint. Add the user to a group granted access on that system, such as sudo usermod -aG systemd-journal alice, then log in again.
The kernel is not yours. Ask what you are running on:
systemd-detect-virtkvm means a full virtual machine with a kernel of its own, and everything above applies to you. lxc or openvz means a container. Your VPS shares the host's kernel with other tenants; access to its kernel messages depends on the host's configuration and is commonly blocked.
That is not a defect to fix. It is the product you bought. On a container VPS, loading kernel modules requires host-level privileges, and changing non-namespaced sysctl values affects the host; namespaced settings can be configured separately. An OOM kill that ended your process can even be a result of memory pressure created by a neighbour on the same host. Having your own kernel gives you control over its logging, which is a practical difference between KVM, Xen and LXC virtualisation on a VPS.
Keep the record before you need it
The ring buffer dies at the next reboot, and the journal dies when the VPS is rebuilt. If the box you are investigating is also the box holding the evidence, one impatient reboot can erase the remaining record when it was kept only in memory. Make the journal persistent, then limit its disk use with SystemMaxUse= in /etc/systemd/journald.conf; journald deletes archived files to enforce the limit, so this is not an absolute guarantee against a full disk. For anything you would be sorry to lose, send it somewhere else: a self-hosted log server on a second VPS keeps kernel messages readable long after the guest that wrote them is gone.
FAQ
Why does dmesg say Operation not permitted?
The full error is dmesg: read kernel buffer failed: Operation not permitted. Run sysctl kernel.dmesg_restrict. If it returns 1, current kernels require CAP_SYSLOG; Linux 6.8 also accepts the deprecated CAP_SYS_ADMIN fallback. On a full VM, sudo dmesg normally supplies the required privilege. If it returns 0 and the command still fails, run systemd-detect-virt. An answer of lxc or openvz means your VPS is a container that shares the host's kernel, and container privileges do not necessarily grant access to that kernel's log.
How do I find out what the OOM killer killed?
Run sudo dmesg -T | grep -iE 'out of memory|oom-kill', and add sudo journalctl -k -b -1 | grep -i 'out of memory' if the machine has rebooted since. The line containing Killed process names the victim, its PID and its resident memory. The oom-kill: line above it distinguishes a system OOM, shown as global_oom, from a cgroup OOM, shown as oom_memcg= followed by the group's path. A cgroup limit can come from MemoryMax= or container configuration; the kill line begins Memory cgroup out of memory instead of Out of memory. The process named on the invoked oom-killer line is the one that requested memory, and it is frequently not the one that was killed.
Should I use dmesg or journalctl -k?
Use both, because each keeps what the other loses. dmesg reads a fixed-size buffer in RAM that covers the current boot only, and firewall logging can overwrite an hour-old OOM report. journalctl -k keeps history across reboots when the journal is persistent, so journalctl -k -b -1 can show the boot that failed. Note that -k implies the current boot, so you must pass -b -1 explicitly. Journald can also fall behind and log Missed 12 kernel messages, and it is not running yet at an initramfs prompt that comes up before systemd, where dmesg is the only option. A rescue shell does start journald, so journalctl -k works there.
Why does my VPS have no kernel log at all?
Run systemd-detect-virt. If it prints lxc or openvz, your VPS is a container running on the host's kernel, so there is no separate guest kernel and access to host kernel messages depends on the host's configuration. Module loading requires host-level privileges, while access to sysctl settings depends on namespacing and container permissions. If it prints kvm, you do have your own kernel. Check unfiltered sudo dmesg and sudo journalctl -k: restrictions produce permission errors, while empty output can reflect a cleared or overwritten ring buffer, no matching records, or disabled journal collection or storage. A volatile journal still holds current-boot records, and journal persistence does not control dmesg.
Why do disk errors show up as application timeouts?
A VPS disk is a virtual device backed by host storage. Slow or failed I/O can surface as application timeouts or failed writes, while the guest logs an I/O error or a hung-task warning. Neither message alone proves that host storage is the cause. If ext4 then logs Remounting filesystem read-only, reads can continue while writes fail with Read-only file system, which is why a site can still serve pages while every upload fails.