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

Generated by cgit