{"id":986,"date":"2026-08-27T23:13:44","date_gmt":"2026-08-27T23:13:44","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=986"},"modified":"2026-09-06T22:07:39","modified_gmt":"2026-09-06T22:07:39","slug":"kernel-live-patching-vps-kpatch-setup","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/","title":{"rendered":"Keep Your VPS Kernel Secure Without Downtime: A Practical Guide to Kpatch Live Patching"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Rebooting a production <a href=\"https:\/\/virtualserversvps.com\/\">VPS<\/a> for every kernel security update is not sustainable. Each reboot drops connections, interrupts services, and risks data inconsistency. Kpatch is an open-source tool that patches a running kernel in memory, applying security fixes without a restart. Here is how to set it up, verify it works, and automate it on your VPS.<\/p>\n<h2 class=\"wp-block-heading\">What Kpatch Actually Does<\/h2>\n<p class=\"wp-block-paragraph\">Kpatch works at the function level. When a security vulnerability is patched upstream, the fix usually modifies one or two functions. Kpatch compiles a kernel module containing only the corrected versions of those functions. At load time, the kpatch core intercepts calls to the old functions using ftrace and redirects them to the new implementations. The kernel never stops running, and processes are unaware that the code underneath them changed.<\/p>\n<p class=\"wp-block-paragraph\">This approach has limits. Patches that modify data structures, change function signatures, or touch initialization code cannot be applied live. Kpatch handles the most common case \u2014 a logic bug or buffer overflow fixed by swapping in a corrected function body \u2014 and that covers roughly 70% of kernel CVEs.<\/p>\n<h2 class=\"wp-block-heading\">Checking Kernel Compatibility<\/h2>\n<p class=\"wp-block-paragraph\">First, confirm your kernel was built with live patching support. Most VPS images from Ubuntu 22.04, Debian 12, Rocky Linux 9, and Fedora 38 onward include it by default.<\/p>\n<pre class=\"wp-block-code\"><code># Quick check on any system\ngrep CONFIG_LIVEPATCH \/boot\/config-$(uname -r)\n\n# Expected output:\n# CONFIG_LIVEPATCH=y\n\n# If the config file is not in \/boot, try \/proc\ngrep CONFIG_LIVEPATCH \/proc\/config.gz 2>\/dev\/null || \\\n  zcat \/proc\/config.gz 2>\/dev\/null | grep CONFIG_LIVEPATCH<\/code><\/pre>\n<p class=\"wp-block-paragraph\">If live patching is not enabled, you need a kernel upgrade and a single reboot to get there. This is a one-time cost.<\/p>\n<h2 class=\"wp-block-heading\">Installing Kpatch on Ubuntu and Debian<\/h2>\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install kpatch kpatch-build -y\n\n# Verify the tools are installed\nkpatch --version\n\n# Check that the kpatch kernel module loaded\nlsmod | grep kpatch<\/code><\/pre>\n<p class=\"wp-block-paragraph\">On RHEL-based systems, install from EPEL:<\/p>\n<pre class=\"wp-block-code\"><code>sudo dnf install epel-release -y\nsudo dnf install kpatch kpatch-dnf -y<\/code><\/pre>\n<h2 class=\"wp-block-heading\">Applying a Live Patch<\/h2>\n<p class=\"wp-block-paragraph\">Distribution repositories ship pre-built kpatch modules alongside kernel security updates. When you install a kernel update, the package manager also places a live patch module in <code>\/usr\/lib\/kpatch\/&lt;kernel-version&gt;\/<\/code>. Loading it is a single command:<\/p>\n<pre class=\"wp-block-code\"><code># List available patches for your running kernel\nls \/usr\/lib\/kpatch\/$(uname -r)\/*.ko 2>\/dev\/null\n\n# Load a specific patch\nsudo kpatch load \/usr\/lib\/kpatch\/$(uname -r)\/CVE-2024-12345.ko\n\n# Verify the patch is active\nsudo kpatch list\n# Output: Loaded patch modules:\n# kpatch_CVE_2024_12345 [enabled]<\/code><\/pre>\n<h2 class=\"wp-block-heading\">Building a Custom Patch from Source<\/h2>\n<p class=\"wp-block-paragraph\">If your distribution does not ship a pre-built module for a specific CVE, you can build one yourself. This requires the kernel source or debug symbols for your exact kernel version.<\/p>\n<pre class=\"wp-block-code\"><code># Install build dependencies\nsudo apt install linux-headers-$(uname -r) build-essential elfutils libelf-dev -y\n\n# Create a patch file from the CVE fix\n# Example: simple fix for a kernel function\ncat > \/tmp\/cve-fix.patch << 'EOF'\ndiff --git a\/kernel\/example.c b\/kernel\/example.c\n--- a\/kernel\/example.c\n+++ b\/kernel\/example.c\n@@ -42,6 +42,8 @@\n int vulnerable_function(void *data) {\n+    if (!data)\n+        return -EINVAL;\n     return do_work(data);\n }\nEOF\n\n# Build the kpatch module\nsudo kpatch-build -t vmlinux \/tmp\/cve-fix.patch \\\n  --vmlinux \/usr\/lib\/debug\/boot\/vmlinux-$(uname -r)\n\n# The output is kpatch-cve-fix.ko in the current directory\nsudo kpatch load .\/kpatch-cve-fix.ko<\/code><\/pre>\n<h2 class=\"wp-block-heading\">Automating Patch Application with Systemd<\/h2>\n<p class=\"wp-block-paragraph\">The safest approach is to automatically apply any available live patches on boot and periodically check for new ones:<\/p>\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# \/usr\/local\/sbin\/apply-kpatch.sh\n# Load all available kpatch modules for the running kernel\n\nPATCH_DIR=\"\/usr\/lib\/kpatch\/$(uname -r)\"\n\nif [ ! -d \"$PATCH_DIR\" ]; then\n    exit 0\nfi\n\nfor patch in \"$PATCH_DIR\"\/*.ko; do\n    [ -f \"$patch\" ] || continue\n    name=$(basename \"$patch\" .ko)\n    if ! kpatch list 2>\/dev\/null | grep -q \"$name\"; then\n        logger -t kpatch \"Loading patch: $name\"\n        kpatch load \"$patch\"\n    fi\ndone<\/code><\/pre>\n<pre class=\"wp-block-code\"><code># \/etc\/systemd\/system\/kpatch-apply.service\n[Unit]\nDescription=Apply kernel live patches\nAfter=network.target\n\n[Service]\nType=oneshot\nExecStart=\/usr\/local\/sbin\/apply-kpatch.sh\nRemainAfterExit=no\n\n# \/etc\/systemd\/system\/kpatch-apply.timer\n[Unit]\nDescription=Daily kernel live patch check\n\n[Timer]\nOnCalendar=daily\nOnBootSec=60\nPersistent=true\n\n[Install]\nWantedBy=timers.target<\/code><\/pre>\n<pre class=\"wp-block-code\"><code>sudo chmod +x \/usr\/local\/sbin\/apply-kpatch.sh\nsudo systemctl daemon-reload\nsudo systemctl enable --now kpatch-apply.timer<\/code><\/pre>\n<h2 class=\"wp-block-heading\">Troubleshooting Common Issues<\/h2>\n<ul class=\"wp-block-list\">\n<li><strong>\"kpatch: module not found\"<\/strong> \u2014 The kpatch-dkms package may not have built the core module. Reinstall it: <code>sudo apt install --reinstall kpatch-dkms<\/code>.<\/li>\n<li><strong>\"kpatch: incompatible kernel version\"<\/strong> \u2014 A patch module is tied to the exact kernel version it was compiled against. After a kernel upgrade, reboot to the new kernel before loading patches for it.<\/li>\n<li><strong>VPS runs on a container\/OpenVZ<\/strong> \u2014 Live patching requires a real kernel, not a containerized one. KVM-based VPS plans work fine. Check with <code>systemd-detect-virt<\/code> \u2014 if it returns <code>openvz<\/code> or <code>lxc<\/code>, live patching is not available.<\/li>\n<li><strong>Memory overhead<\/strong> \u2014 Each loaded patch consumes 100\u2013500 KB of kernel memory. On a VPS with 512 MB RAM, limit yourself to the most critical patches.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">When Live Patching Is Not Enough<\/h2>\n<p class=\"wp-block-paragraph\">Kpatch is a tactical tool. It eliminates the downtime cost of the most common kernel CVEs, but it does not replace scheduled reboots. Major kernel version upgrades, patches that change data structures, and fixes to module initialization code still require a restart. Use live patching to buy time \u2014 apply security fixes immediately, then schedule a reboot during the next maintenance window. For more on choosing a VPS that gives you full kernel control, see our <a href=\"https:\/\/virtualserversvps.com\/\">VPS hosting plans<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rebooting a production VPS for every kernel security update is not sustainable. Each reboot drops connections, interrupts services, and risks data inconsistency. Kpatch is an open-source tool that patches a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-986","post","type-post","status-publish","format-standard","hentry","category-security-compliance"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Keep Your VPS Kernel Secure Without Downtime: A Practical Guide to Kpatch Live Patching - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Keep Your VPS Kernel Secure Without Downtime: A Practical Guide to Kpatch Live Patching\" \/>\n<meta property=\"og:description\" content=\"Keep Your VPS Kernel Secure Without Downtime: A Practical Guide to Kpatch Live Patching\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-27T23:13:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-09-06T22:07:39+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/\",\"name\":\"Keep Your VPS Kernel Secure Without Downtime: A Practical Guide to Kpatch Live Patching - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-08-27T23:13:44+00:00\",\"dateModified\":\"2026-09-06T22:07:39+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Keep Your VPS Kernel Secure Without Downtime: A Practical Guide to Kpatch Live Patching\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Keep Your VPS Kernel Secure Without Downtime: A Practical Guide to Kpatch Live Patching - Virtual Servers VPS Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/","og_locale":"en_US","og_type":"article","og_title":"Keep Your VPS Kernel Secure Without Downtime: A Practical Guide to Kpatch Live Patching","og_description":"Keep Your VPS Kernel Secure Without Downtime: A Practical Guide to Kpatch Live Patching","og_url":"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-08-27T23:13:44+00:00","article_modified_time":"2026-09-06T22:07:39+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/","url":"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/","name":"Keep Your VPS Kernel Secure Without Downtime: A Practical Guide to Kpatch Live Patching - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-08-27T23:13:44+00:00","dateModified":"2026-09-06T22:07:39+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/kernel-live-patching-vps-kpatch-setup\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Keep Your VPS Kernel Secure Without Downtime: A Practical Guide to Kpatch Live Patching"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=986"}],"version-history":[{"count":2,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/986\/revisions"}],"predecessor-version":[{"id":1062,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/986\/revisions\/1062"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}