{"id":797,"date":"2026-03-06T17:05:36","date_gmt":"2026-03-06T09:05:36","guid":{"rendered":"https:\/\/play.datalude.com\/blog\/?p=797"},"modified":"2026-03-06T17:17:10","modified_gmt":"2026-03-06T09:17:10","slug":"removing-all-5-xx-kernels-and-associated-modules-config-from-ubuntu","status":"publish","type":"post","link":"https:\/\/play.datalude.com\/blog\/2026\/03\/removing-all-5-xx-kernels-and-associated-modules-config-from-ubuntu\/","title":{"rendered":"Removing all 5.xx kernels and associated modules, config from Ubuntu"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I was getting a bit cramped for space on the root partition of an older desktop, which has been running for 4 years or so, and discovered that although I'd been running the 6.x kernel for several years, there was a lot of baggage from 5.x kernels lying around. Here's a reminder to myself how to clear it up. If you've done an inplace upgrade from Ubuntu 22 to 24, you're probably in the same position. <br><br>So first of all, check your running kernel. You definitely want to keep that one! Then check what kernels you've got installed<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Current kernel\nuname -r\n6.8.0-101-generic\n# What kernels do we have installed. \n# ii at the beginning of the line means installed, but rc entries might have some residual config files.\ndpkg --list | grep 'linux-image-'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now, if you're certain that you want to get rid of all the kernels beginning with 5.x, then go ahead and run the following. Or otherwise edit the commands so that you're disposing of the ones you want to get. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt remove $(dpkg --list | grep 'linux-image-5\\.' | awk '{print $2}' | xargs)  \n# And now we get rid of all the associated modules and headers\nsudo apt remove $(dpkg --list | grep 'linux-headers-5\\.' | awk '{print $2}' | xargs)\nsudo apt remove $(dpkg --list | grep 'linux-modules-5\\.' | awk '{print $2}' | xargs)   \nsudo apt remove $(dpkg --list | grep 'linux-modules-extra-5\\.' | awk '{print $2}' | xargs)\n# And clean up\nsudo apt autoremove --purge\nsudo update-grub   <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So that cleared over a Gigabyte. Ubuntu will generally (I think) keep the last 3 kernels, but sometimes it doesn't seem to clean up everything it can. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was getting a bit cramped for space on the root partition of an older desktop, which has been running for 4 years or so, and discovered that although I'd been running the 6.x kernel for several years, there was a lot of baggage from 5.x kernels lying around. Here's a reminder to myself how &#8230; <a title=\"Removing all 5.xx kernels and associated modules, config from Ubuntu\" class=\"read-more\" href=\"https:\/\/play.datalude.com\/blog\/2026\/03\/removing-all-5-xx-kernels-and-associated-modules-config-from-ubuntu\/\" aria-label=\"Read more about Removing all 5.xx kernels and associated modules, config from Ubuntu\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[144,4],"tags":[],"class_list":["post-797","post","type-post","status-publish","format-standard","hentry","category-bash-script","category-linux"],"_links":{"self":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/comments?post=797"}],"version-history":[{"count":4,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/797\/revisions"}],"predecessor-version":[{"id":802,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/797\/revisions\/802"}],"wp:attachment":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/media?parent=797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/categories?post=797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/tags?post=797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}