# Question about /usr/src/linux*

## dpst

Hello,

I'm not sure if the question I want to ask should be in this part of the forums, but anyway, here's what I'd like to know:

I installed Gentoo with 2.6.5-r1 kernel. Emerge placed the kernel sources in /usr/src/linux-2.6.5-gentoo-r1. Recently, I upgraded to 2.6.7 kernel, which placed it's sources in /usr/src/linux-2.6.7-gentoo. Then, numerous revision spawned, emerging them caused my /usr/src dir to be full with sources. Currently I have:

```
drwxr-xr-x   7 root root  296 Jun 25 15:13 .

drwxr-xr-x  14 root root  472 Jun 25 00:54 ..

-rw-r--r--   1 root root    0 Jun  8 12:12 .keep

lrwxrwxrwx   1 root root   28 Jun 19 18:09 linux -> /usr/src/linux-2.6.7-gentoo/

drwxr-xr-x  19 root root 1280 Jun 11 16:32 linux-2.6.5-gentoo-r1

drwxr-xr-x  19 root root 1248 Jun 23 14:14 linux-2.6.7-gentoo

drwxr-xr-x  18 root root  632 Jun 23 00:06 linux-2.6.7-gentoo-r4

drwxr-xr-x  18 root root  632 Jun 25 13:52 linux-2.6.7-gentoo-r5

drwxr-xr-x  18 root root  632 Jun 25 15:15 linux-2.6.7-gentoo-r6
```

Now, the question (at last!). Can I just keep the linux-2.6.7-gentoo-r6 sources and will it be safe to delete the older versions, and will it make any difference if I keep them?

Thank you in advance.

----------

## spudicus

 *dpst wrote:*   

> 
> 
> Now, the question (at last!). Can I just keep the linux-2.6.7-gentoo-r6 sources and will it be safe to delete the older versions, and will it make any difference if I keep them?

 

Yes you can delete the unused source. You could also delete the current source as well if you were'nt going to compile anything that needed it, but it's safer to leave it there for now.

You could do this by running the following:

```
emerge -pC "<sys-kernel/gentoo-dev-sources-2.6.7-r6"
```

What difference will it make? Change to /usr/src and run the following (before unmerging) to see the space used by each directory:

```
for i in `ls`; do du -sh $i; done
```

----------

## beowulf918

Seeing as how enormous uncompressed kernel sources are (my 2.6.6-love2 directory is 239M), cleaning out the /usr/src directory is usually one of the first stops when disk space is running low. It's ok to expire stale kernel sources if you're sure that you don't need to recompile anything from that version. Expiring revisions is safe as well. Generally, you might want to leave the vanilla sources (eg linux-2.6.7.tar.bz2) in /usr/portage/distfiles because they are used as the root for most related revisions and patch sets.

James.

----------

## saccory

You can delete anything you don't use. But your linux symlink shows to linux-2.6.7-gentoo. So I assume this is your current kernel. You'll need the sources of your current kernel (and actually only them) for some programs to compile.

----------

## dpst

Thank you all for the replies, and yes, it's symlinked to linux-2.6.7-gentoo... because the other revisions spawned in just a day or two and I didn't have time to recompile.

----------

## saccory

 *spudicus wrote:*   

> Change to /usr/src and run the following (before unmerging) to see the space used by each directory:
> 
> ```
> for i in `ls`; do du -sh $i; done
> ```
> ...

 

Or just 

```
du -sh /usr/src/*
```

  :Wink: 

----------

## dpst

```
bash-2.05b# du -sh /usr/src/*

0       /usr/src/linux

285M    /usr/src/linux-2.6.5-gentoo-r1

281M    /usr/src/linux-2.6.7-gentoo

214M    /usr/src/linux-2.6.7-gentoo-r4

214M    /usr/src/linux-2.6.7-gentoo-r5

214M    /usr/src/linux-2.6.7-gentoo-r6

bash-2.05b#
```

 :Shocked: 

And I was wondering where all that diskspace went....

----------

## spudicus

 *saccory wrote:*   

>  *spudicus wrote:*   Change to /usr/src and run the following (before unmerging) to see the space used by each directory:
> 
> ```
> for i in `ls`; do du -sh $i; done
> ```
> ...

 

 :Embarassed: 

But my way looks more complex so it must be faster   :Rolling Eyes:   :Wink: 

----------

## ryceck

 *dpst wrote:*   

> 
> 
> ```
> bash-2.05b# du -sh /usr/src/*
> 
> ...

 

heheheh  :Smile: 

WHile ur missing on diskspace check these directories too:

```

/usr/portage/distfiles

/var/tmp/portage

/tmp

```

I think this way u could clean up another 1 GB :p

----------

## spb

1GB is a conservative estimate. My distfiles is 2.4GB, and /var/tmp/portage is 2.1GB.

----------

## nick_downing

You might also want to check into the current status of your /usr/include directory.. try this:

cd /usr/include

ls -l |less

Check the entries "asm", "asm-generic" and "linux" ... these should point to:

asm -> /usr/src/linux/include/asm

asm-generic -> /usr/src/linux/include/asm-generic

linux -> /usr/src/linux/include/linux [NOTE: EVERYONE: DONT DO THIS.. READ FURTHER DOWN, I STAND CORRECTED]

If they're not symlinks then you should worry, as they're probably 2.4 kernel headers from the kernel-headers package.  If they're symlinked to any of the earlier kernels then obviously you can't delete those earlier kernels.  My preferred system is to symlink them THROUGH the /usr/include/linux symlink (as above) so you can change everything just by redirecting the /usr/src/linux symlink.  If I'm stating the obvious here, I'll shutup  :Wink: 

cheers,

Nick

PS.  Your /usr/src/linux symlink can be a relative path ie.

linux -> linux-2.6.6-blah-im-very-good

rather than:

linux -> /usr/src/linux-2.6.6-blah-im-very-goodLast edited by nick_downing on Wed Jun 30, 2004 6:16 am; edited 2 times in total

----------

## aloha99

 *nick_downing wrote:*   

> Check the entries "asm", "asm-generic" and "linux" ... these should point to:
> 
> asm -> /usr/src/linux/include/asm
> 
> asm-generic -> /usr/src/linux/include/asm-generic
> ...

 

Uh ... well, I'm using gentoo-dev-sources, 2.6.7-r6, after starting with a 2.4 kernel, and these are not symlinks for me.  "asm" has a list of over 100 header files, "linux" is a directory with more than 500 header files, and I don't have "asm-generic", though I do have a "dis-asm.h" file, which says it is an "interface between the opcode library and its callers."

Do I have a problem, Houston?

----------

## aloha99

Whad'ya know, I just emerged iproute2 and it told me that the "linux-headers in /usr/include/linux are too old"  ...

How can I update them?  Take me to school!

----------

## spudicus

 *aloha99 wrote:*   

> Whad'ya know, I just emerged iproute2 and it told me that the "linux-headers in /usr/include/linux are too old"  ...
> 
> How can I update them?  Take me to school!

 

```
sudo emerge -auvD linux-headers
```

----------

## aloha99

 *spudicus wrote:*   

> 
> 
> ```
> sudo emerge -auvD linux-headers
> ```
> ...

 

Doh, a package.  Unfortunately, I'm already at the (au courant) linux-headers version, 2.4.21-r1,  so the update does nothing.  

It also doesn't explain to this gentoo n00b why the ebuild for iproute2 complains about outdated linux-headers, or why the symlinks are a problem as indicated.  Am I misunderstanding something?

Thanks!

----------

## spudicus

 *aloha99 wrote:*   

>  *spudicus wrote:*   
> 
> ```
> sudo emerge -auvD linux-headers
> ```
> ...

 

Oops, I should have read nick_downing's post first.

It is odd, however, because I have iproute2-2.4.7.20020116 installed with the linux-header version you have. Although, I think I had to fudge something to get it to work (I can't remember what).

Following Nick's method try:

```
cd /usr/include

rm -rf linux

rm -rf  asm

ln -sf ../src/linux/include/linux/ linux

ln -sf ../src/linux/include/asm-i386 asm  #If your not using an intel machine use asm-<arch>

ln -sf ../src/linux/include/asm-generic/ asm-generic
```

----------

## UncleOwen

 *nick_downing wrote:*   

> Check the entries "asm", "asm-generic" and "linux" ... these should point to:
> 
> asm -> /usr/src/linux/include/asm
> 
> asm-generic -> /usr/src/linux/include/asm-generic
> ...

 

NO, NO, NO, /usr/include/linux should NEVER EVER be a symlink to /usr/src/linux/include. /usr/src/linux should point to the currently running kernel, while /usr/include/linux are the headers glibc was build against. So what you are proposing may (or may not) go boom the next time you compile a new kernel and not recompile glibc immediately afterwards.

That's why we have a seperate kernel-headers-paket. I don't know why 2.6.* are still masked, but I know that the interface between kernel and userspace (that's what these headers are for) is backwards-compatible, so it should be safe to use 2.4-headers with a 2.6-kernel.

At least that's what Linus keeps telling people...

----------

## spudicus

 *UncleOwen wrote:*   

>  *nick_downing wrote:*   Check the entries "asm", "asm-generic" and "linux" ... these should point to:
> 
> asm -> /usr/src/linux/include/asm
> 
> asm-generic -> /usr/src/linux/include/asm-generic
> ...

 

Oops (I'm saying that a lot today  :Embarassed:  ). Well in my case, I've already made the change and everything still works (i.e. I've been able to compile new packages). However, I'll be re-emerging the stable kernel-headers, to revert to the way Linus recommends here:

http://www.uwsg.iu.edu/hypermail/linux/kernel/0007.3/0587.html

----------

## nick_downing

OK, thanks for clearing that up.  I'll stop spreading disinformation now.   :Wink:   But honestly, I really didn't know and I was trying to help.  Linus of course, knows everything  :Wink:   For those who don't want to take the trouble of reading Linus's very long post I'll just summarize a key point here:

 *Quote:*   

> Pretty much every distribution still has that broken symlink, and people still remember that the linux sources should go into "/usr/src/linux" even though that hasn't been true in a _loong_ time.

 

However I definitely think iptables is still going to break after the 2.4 -> 2.6 kernel upgrade, this is because iptables doesn't use the c library to communicate with the kernel (except the ioctl call which is very generic) but rather, it includes kernel headers to get kernel structures directly.

cheers,

Nick

----------

## dpst

 *ryceck wrote:*   

>  *dpst wrote:*   
> 
> ```
> bash-2.05b# du -sh /usr/src/*
> 
> ...

 

So what you're saying, I can safely delete the contents of those directiories, right?

----------

## neysx

Cleaning up /tmp should be OK but you should have a look inside before and some running processes might not like losing some files.

rm -r /var/tmp/portage/* is always OK as long as you're not running emerge at the same time  :Wink: 

Removing files from /usr/portage/distfiles is safe but you will have to download some files again if you want to recompile or upgrade some packages. If you want to keep sources of currently installed packages and remove sources of all previous versions, use the following one-liner

```
# find /usr/portage/distfiles -type f -not \( `emerge -epf world 2>&1|awk 'BEGIN{mino=""}{n=split($1,a,"/");if(n>1){print mino,"-name ",a[n];mino=" -o "}}'` \)
```

to list all obsolete sources. Be patient, it takes a while to run.

----------

## nick_downing

My god!!  Pardon my taking the Lord's name in vain, but how on earth did you come up with that??  Better still:  Can you give me a commandline that will "qpkg --find-file" every file in the filesystem and print a summary of those that don't belong to installed packages, but without taking many hours to execute?   :Wink:   It looks like equery is still a bit broken & also can't do that??

cheers,

Nick

----------

## neysx

Sorry I can't give you any command that would do anything like that. You could compare a full listing with the output of qpkg -l (lowercase L) that lists all files known to portage. Good luck with that.

On my box, it would mean a diff between 500,000 and 650,000 lines in two files.

The command I posted simply finds files under /usr/portage/distfiles that would not be required by a full emerge of all known packages.

----------

## RoYzter

 *saccory wrote:*   

>  *spudicus wrote:*   Change to /usr/src and run the following (before unmerging) to see the space used by each directory:
> 
> ```
> for i in `ls`; do du -sh $i; done
> ```
> ...

 

i used to do it like spudicus because i wanted to know the size of each directory, not the sum of all of them. however, somebody posted somewhere this command to achieve the very effect:

```
du -h --max-depth=1
```

----------

## dpst

Thank you all for the replies  :Cool: 

----------

## nick_downing

Thanx nesyx regarding the qpkg -l command, I didn't know about that.  I can derive my own solution with that knowledge.  By the way everyone, on the subject of Linux headers I found out from plasmaroo the proper way to emerge your headers:

emerge <full-ebuild-pathname>

eg:

```
emerge /usr/portage/sys-kernel/linux-headers-2.6.6

```

this is how you get around the -* masking.  Alternatively you can do this:

```
mkdir -p /etc/portage

echo 'sys-kernel/linux-headers -*' >> /etc/portage/package.keywords

```

(the above was from memory so I hope it's right).

cheers all,

Nick

----------

## aloha99

 *nick_downing wrote:*   

> However I definitely think iptables is still going to break after the 2.4 -> 2.6 kernel upgrade

 

For those following this thread due to problems with compiling iptables, the latest iptables release (1.2.9-r3) has fixes, including for the "DECLARE MUTEX declared but not defined" error related to the old linux-headers.  See the iptables changelog for details.

** EDIT ** : Oops!  I'd been up all night ... I'd meant to say the latest (at the time) g-d-s kernel ( gentoo-dev-sources-r7 ) had the patch.

----------

