# Removing old sources?

## Uncle_Psychosis

Hi guys

How do I remove old kernel sources? (I don't want to remove all of them)

----------

## mikegpitt

 *Uncle_Psychosis wrote:*   

> Hi guys
> 
> How do I remove old kernel sources? (I don't want to remove all of them)

 Like this:

```
emerge -C =gentoo-source-2.6.XX-rx
```

That should specify a specific version of the sources to remove, while leaving the other slots alone.  It will tell you which sources will be unmerged/omitted before doing so, with enough time to ctrl-c it if you mess up.

----------

## John R. Graham

First, see which ones you have:

```
IPSN-JOHNGRAH2 ~ # equery list -i sources

[ Searching for package 'sources' in all categories among: ]

 * installed packages

[I--] [ ~] sys-kernel/reiser4-gentoo-sources-2.6.27-r10 (2.6.27-r10)

[I--] [ ~] sys-kernel/reiser4-gentoo-sources-2.6.29-r5 (2.6.29-r5)
```

Second, check to see which one you're using (don't want to delete that one):

```
IPSN-JOHNGRAH2 ~ # uname -r

2.6.29-reiser4-r5
```

Finally, use emerge -C to delete the one(s) you want to remove.  You explicitly name them so that you know the ones you want to keep aren't named:

```
emerge -C =sys-kernel/reiser4-gentoo-sources-2.6.27-r10
```

Clear?    :Smile: 

- John

----------

## V-Li

```
emerge --prune gentoo-sources
```

 removes all but the newest one.

----------

## John R. Graham

Yes but you still need to verify because the latest installed source may not be the one you're currently running and you usually don't want to uninstall that.  :Smile: 

- John

----------

## energyman76b

rm -rf /usr/src/linux*

emerge --C ... sources 

emerge vanilla-sources

done.

----------

## John R. Graham

Um, you just erased his kernel .config file.  He might be mad.    :Rolling Eyes: 

- John

----------

## energyman76b

 *john_r_graham wrote:*   

> Um, you just erased his kernel .config file.  He might be mad.   
> 
> - John

 

config file is in /boot anyway. If you use make install. As you should.

----------

## mikegpitt

 *john_r_graham wrote:*   

> Um, you just erased his kernel .config file.  He might be mad.   
> 
> - John

 You can get your .config back by using `zcat /proc/config.gz > .config` (if you have CONFIG_IKCONFIG=y compiled in your kernel).  Although I do agree with you that it's probably better not to rm -rf your entire source dir.

----------

## Roman_Gruber

/var/lib/modules also take a lot of harddisk space

so dont forget to delete all the old modules for the old kernels you have deleted.

also in the boot directory, check for unused kernels and also grub.conf for unused entries.

----------

## V-Li

The kernel should not be built as root anyway, so the .config should lie in a user-readable location under /home for example.

----------

## mikegpitt

 *V-Li wrote:*   

> The kernel should not be built as root anyway, so the .config should lie in a user-readable location under /home for example.

 Are you serious?  I've always built the kernel as root, and never thought to do it differently.  Is there a reason that building as root would be a problem?  (Not yelling; Just curious!)

----------

## V-Li

Read "Linux Kernel in a Nutshell" by Greg Kroah-Hartman for all the glory details. Yes, I am serious, as building as root is a serious flaw, you expose your whole system to a possibly whacky build system (the ebuild command for example runs fine as a user, except merging).  Only make modules_install and the actual installation in /boot needs superuser privileges. Set KBUILD_OUTPUT variable to a directory in your /home, copy your .config, start make in /usr/src/linux and watch it compile. Maybe you need to set O=${KBUILD_OUTPUT} when calling make.

----------

## cach0rr0

I've never heard of that either - mind you I'm not disputing that, I'm simply saying I've never heard of it. Guess I learned something. 

Would it not be worthwhile then, to put something in the handbook (for new installs) or doc somewhere making mention of this?

----------

## Hu

For the truly cautious, you can set INSTALL_PATH and INSTALL_MOD_PATH so that make install and make modules_install, respectively, install to a staging area.  This is useful if you want to package up the kernel in an archive, or have a chance to examine everything before it is written to the live filesystem.  It is also convenient if you need to install the kernel onto a secondary hard drive, which you can mount in a temporary area and name with those variables.

----------

## Roman_Gruber

Hi, 

I also haven*t heard about building the kernel without root privileges.

Can anyone be so kind and write down the commands, so i can understand this issue easier by learning by doing!

```
roman@r2d2 / $ cd /usr/src/linux

roman@r2d2 /usr/src/linux $ make menuconfig

  HOSTCC  scripts/basic/fixdep

scripts/basic/fixdep.c:399: fatal error: opening dependency file scripts/basic/.fixdep.d: Permission denied

compilation terminated.

make[1]: *** [scripts/basic/fixdep] Error 1

make: *** [scripts_basic] Error 2

roman@r2d2 /usr/src/linux $ 

```

So the only way for me is:

to copy the hole kernel source to the home directory

cp .config to this kernel directory in home directory

calling the command make

login as root with su

make modules && make install

cp arch/x86/boot/bzImage /boot/KernelXX___

edit grub.conf in /boot/grub/

Or is there any easier way? If I can get a list of commands it would be much easier for me to understand.

Thank you

----------

## V-Li

I use the following scripts:

And set globally KBUILD_OUTPUT=/home/fauli/kernel-config, in that directory you place the .config file (do a make mrproper on /usr/src/linux).  Understand the script before applying!  If you have questions, just ask me.

kernelgen.sh

```
#!/bin/bash

outputdir=/home/fauli/kernel-config/

numberofthreads=3

compileroptions="ccache gcc"

if [[ $# -lt 3 ]]; then

    echo "Too few arguments!"

    echo "Usage: ${0} <kernel major version (first three parts)> <Gentoo revision> <kernel minor version>"

    exit 1

fi

if [[ ${2} = 0 ]]; then

    gentoodir=linux-${1}-gentoo

else

    gentoodir=linux-${1}-gentoo-r${2}

fi

if [[ ${3} = 0 ]]; then

    kernelversion=${1}

else

    kernelversion=${1}.${3}

fi

cd /usr/src/${gentoodir}

make O=${outputdir} silentoldconfig

make -j${numberofthreads} O=${outputdir} CC="${compileroptions}"

/bin/su -c "/usr/local/sbin/kernelhelper.sh ${gentoodir} ${kernelversion} ${outputdir}"

```

kernelhelber.sh

```

#!/bin/bash

cd /usr/src/${1}

make modules_install O=${3}

mount /boot

cp ${3}/arch/i386/boot/bzImage /boot/kernel-${2}-gentoo

cp ${3}/System.map /boot/System.map-${2}-gentoo

cp ${3}/.config /boot/config-${2}-gentoo

ls --color=auto -la /boot

df

emacs /boot/grub/grub.conf

cd /

umount /boot

cd /usr/src/

rm linux 

ln -s ${1} linux

/usr/sbin/module-rebuild -X rebuild

```

----------

## Kobboi

 *Hu wrote:*   

> For the truly cautious, you can set INSTALL_PATH and INSTALL_MOD_PATH so that make install and make modules_install, respectively, install to a staging area.  This is useful if you want to package up the kernel in an archive, or have a chance to examine everything before it is written to the live filesystem.  It is also convenient if you need to install the kernel onto a secondary hard drive, which you can mount in a temporary area and name with those variables.

 

I use both of these variables in a "kernel ebuild" that, on multiple systems, automatically compiles (sandboxed) and packages if necessary, and installs from a binary repo if possible.

----------

## BrummieJim

Wow, never knew this, should definitely be in the install guide. Installing Gentoo is the first time most people have probably installed their own hand-rolled kernel, so good to explain and get people in good habits.

----------

## V-Li

As always...patches welcome.  :Smile: 

----------

