# Removing Old Kernel versions

## OldTango

I would like to know the best way to remove or unmerge Old Kernels no longer in use, and hopefully source tree and all the files associated with them.  If I simply rm the kernel file it won,t remove the other files installed with it.  Or maybe I shouldn't do it this way in the first place.

Any advise?????????????????/

----------

## dotcomaset

i did emerge unmerge "kernel"

----------

## tuxwatcher

I loaded gentoolkit and ran 

```
qpkg --dups -v gentoo-sources
```

Then ran "emerge unmerge " on the individual sources I didn't want.  You still may have to manually remove some directories after it is finished.

----------

## NeddySeagoon

OldTango,

Remove the following:-

The kernel source tree in /usr/src

The installed modules in /lib/modules/<kernel_ver>

The kernel bzImage file from /boot

The refernces in /boot/grub/grub.conf

Do make sure that you have not left the /usr/src/linux symbolic link pointing to nothing. You will get many emerge errors otherwise.

Since emerge does not build the kernel for you, it doesn't know about the modules or how you have renamed the bzImage file when you copied it to /boot

----------

## OldTango

Thanks guys all the info was very helpful.

I did manage to emerge unemerge one old kernel source but still had one the emerge process could'nt find.

So I am going to follow Neddy's advice and manually remove the unnecessary kernels and sources.

I do have the gentoolkit and it a great tool.

In time I hope to assist others as well.  After only 2 weeks of working with linux, I don't feel qualifyied to try at this point.  Except for maybe grub.  After at least 50 bad installs I have that down patt...............lol

----------

## kevmille

I wrote this based on comments from the Gentoo users mailing list:

```
To unmerge an old kernel, follow these simple guidelines:

1.  If you do not have gentools installed on your computer yet, you will need to emerge it.  If you do

    not know what this is, you probably have not installed it.  To install gentoolkits:

   #emerge gentoolkit

2.  To find out which package names you have installed for each kernel:

   # qpkg -I -v gentoo-sources

   Your result may look somthing similar to this:

   sys-kernel/gentoo-sources-2.4.20-r5 *

   sys-kernel/gentoo-sources-2.4.20-r7 *

   Note:

         a. The above uses a CAPITAL I as in Indiana not L as in Louisiana.

         b. If you are using another kernel source, just replace 'gentoo-sources' with your preferred

            source, i.e. vanilla-sources

3.  To unmerge the packages:

   # emerge -C <package>

   Since I want to unmerge the kernel: gentoo-sources-2.4.20-r5, I will input this:

   # emerge -C gentoo-sources-2.4.20-r5 *

4.  So far, you have removed most of the source files, but not the compiled binary files.  To remove

    these files, go into /usr/src and rm -rf the directories of kernel you don't need anymore.  In this

    example, you would look for all files that relate to gentoo-sources-2.4.20-r5.

5.  Next, mount /boot and go the /boot directory.  Delete all the files related to the kernel version you just

   deleted.  When you are done, umount /boot.

6.  Finally, go into the /lib/modules/ and delete all the files related to the kernel version you just

   deleted.

You have now deleted this kernel and all the files and modules attached to it.  Time to go compile another kernel:)
```

This has worked everytime for me.

----------

## charlieg

Oi!  You're all making this sound so difficult!  It's so easy!

```
# emerge -Cp \<sys-kernel/love-sources-2.6.3-r5
```

Notes:

The < must be escaped as \< in order to prevent bash from using it

Remove the 'p' when you're happy you're about to do the right thing

You may be left with a little cleanup in /usr/src/linux and /boot, but nothing difficult (eg stuff left over from make menuconfig - ie files created by you and not by portage).  It's just a matter of doing a quick rm -rf on the appropriate directories.

----------

## OldTango

Well I guess I have to relink the old kernel before I can remove it because all I get is a pakcage can't be found when I attempt any of these above options.

I removed the link to the old kernel to compile a newer version of the same kernel.  So I belive I can simply make a new link to the old kernel, than remove it.

Is it safe to have 2 links to 2 different kernels in /usr/src/linux at the same time.  And will removing the old one affect the Kernel currantly in use.

Thanks so much for your help.  I am learning a lot fast.

----------

## NeddySeagoon

OldTango,

The link /usr/src/linux (there can only be one at a time) is used to find the kernel when things must be built against it. If it doesn't exist, some emerges will break. If it points to the wrong kernel, its dificult to forecast the effects

----------

## OldTango

Thanks Neddy..............I will manually remove the old kernel and any files I know for sure are linked to the old soruce alone.  The rest I will leave alone until I gain more knowledge about linux...............not to self...when in doubt don't delete............  :Smile: 

----------

## sapphirecat

I usually rm -rf the source trees before doing the emerge -C so that Portage doesn't have to compute the MD5s of every file it installed.

 *kevmille wrote:*   

> 
> 
> ```
>    # emerge -C gentoo-sources-2.4.20-r5 *
> ```
> ...

 

Is that "*" supposed to be there? It looks like it could either be annoying or dangerous, depending on what the current directory is when running that command.

----------

## kevmille

 *loonxtall wrote:*   

> I usually rm -rf the source trees before doing the emerge -C so that Portage doesn't have to compute the MD5s of every file it installed.
> 
>  *kevmille wrote:*   
> 
> ```
> ...

 

No, the * is NOT supposed to be there and it is dangerous.  Then again, if you want Gentoo to delete ALL of your kernels, go right ahead.  Don't worry, you will still be able to boot into your computer though.  I know this from experience  :Very Happy: 

----------

