summaryrefslogtreecommitdiff
path: root/posts/gentoo:kernel_cleanup.adoc
blob: 178d2f60350b632f372e7758caf2bc83f064d867 (plain)
    1 Gentoo:Kernel Cleanup
    2 =====================
    3 :author: Aaron Ball
    4 :email: nullspoon@iohq.net
    5 :revdate: October 30, 2015
    6 
    7 
    8 Gentoo is a source-based Linux distribution. Moreover it's aimed at more
    9 advanced users with the intent of not forcing anything on them, as much as is
   10 possible with so many packages.
   11 
   12 Normally, whenever you get a kernel update on a distro, say from 4.2.0 to
   13 4.2.5, the system does several things.
   14 
   15 * Download the new kernel (pre-compiled)
   16 * Install the new kernel
   17 * Update the initramfs
   18 * Update the bootloader
   19 * Clean up the unused kernels
   20 
   21 Gentoo requires that their users to each of those items. I'm fairly new to
   22 Gentoo and, coming from Arch Linux, already knew for the most part how to do
   23 all of those steps, except for the last one. That said, lets talka bout how to
   24 clean up unused kernels on your system.
   25 
   26 == TL;DR Summary
   27 
   28 Here are the locations that need to be cleaned up, in case you want to skip to
   29 that section or already know what you're doing but just need the list.
   30 
   31 * emerge -C <sys-kernel/<type>-sources-<version> _(This is specific to Gentoo)_
   32 * Files
   33   * /usr/src/linux-<versions>
   34   * /lib/modules/<versions>
   35   * /boot/*-<versions>
   36 
   37 
   38 == Inventory
   39 
   40 The first step is to take an inventory. The largest part of a kernel in Gentoo
   41 is its source code, so we'll look at that for the inventory (there are other
   42 ways and we'll look into those as well).
   43 
   44 Gentoo stores its kernel source at _/usr/src/linux-*_. In there, you can see 
   45 multiple versions of the linux source code. In my case, I have linux-4.2.0 all
   46 the way up to linux 4.2.5.
   47 
   48 NOTE: In my case, I'm using vanilla-sources for my kernel, so the directory
   49 names for you might be a tad different. Despite though, they should still start
   50 with _linux-x.x.x*_.
   51 
   52 
   53 == Clean Up the Source
   54 
   55 Now that we have an inventory, let's clean up the source. This is very simple.
   56 Once you know what versions you want to keep, we can issue an emerge command
   57 that will clean up the files for the source. For my example, we'll say we want
   58 to remove anything before 4.2.4
   59 
   60     emerge -Cp <sys-kernel/vanilla-sources-4.2.4
   61 
   62 That command will delete any files installed by emerge if they belong to kernel
   63 versions 4.2.3 or less. However, it doesn't clean up any files created by the
   64 compile process, so we still need to remove those.
   65 
   66 To see where we are first, here's an ls example of my src directory.
   67 
   68     0 [nullspoon@null ~]$ ls /usr/src/
   69     linux  linux-4.2.0  linux-4.2.1  linux-4.2.2  linux-4.2.3  linux-4.2.4  linux-4.2.4-gentoo  linux-4.2.5  linux-4.2.5-gentoo
   70 
   71 Now for a simple but gratifying rm command. Since rm has no knowledge of the
   72 kernel versioning scheme, we can't say "less than version 4.2.4" and it'll
   73 clean up. In this case, we'll use a simple bash sequence.
   74 
   75     rm -rf /usr/src/linux-4.2.{0,1,2,3}
   76 
   77 NOTE: If you are worried about running that command and what it'll do, run it
   78 with echo before it to see what it will output without actually deleting
   79 anything.
   80 
   81 
   82 == Clean up Installed Modules
   83 
   84 The Linux kernel stores its modules in */lib/modules* (fun fact: /lib is
   85 usually a symlink to /lib64 if you're running a 64 bit system, or /lib32 if
   86 you're running a 32 bit system).
   87 
   88 Similar to cleaning up the sources, we will clean up the moduels with a simple
   89 but gratifying _rm -rf_ command.
   90 
   91     rm -rf /lib/modules/4.2.{0,1,2,3}
   92 
   93 That will clean up all the installed modules for the specified old kernel
   94 versions (in this case, 4.2.0, 4.2.1, etc).
   95 
   96 
   97 == Clean up Old Installed Kernels
   98 
   99 The Linux Kernel installs itself to  _/boot_. To see what you have for the
  100 given version set (again, using the one from previous examples, run the
  101 following command...
  102 
  103     ls /boot/*-4.2.{0,1,2,3}
  104 
  105 Again, a simple rm command will clean up these files.
  106 
  107     rm -f /boot/*-4.2.{0,1,2,3}
  108 
  109 
  110 And with that, you're done. All clean!
  111 
  112 
  113 
  114 
  115 [role="datelastedit"]
  116 Last edited: {revdate}
  117 
  118 // vim:set syntax=asciidoc:

Generated by cgit