# [Solved] Multiple Kernels in /usr/src/linux?

## nicolberg

So after I install the new kernel drivers and perform:

```

cd /usr/src/linux/

make clean

```

I get the following error:

```

desktop /usr/src/linux # make clean 

scripts/Makefile.clean:15: drivers/gpu/drm/arm/display/Makefile: No such file or directory 

make[5]: *** No rule to make target 'drivers/gpu/drm/arm/display/Makefile'.  Stop. 

make[4]: *** [scripts/Makefile.clean:71: drivers/gpu/drm/arm/display] Error 2 

make[3]: *** [scripts/Makefile.clean:71: drivers/gpu/drm/arm] Error 2 

make[2]: *** [scripts/Makefile.clean:71: drivers/gpu/drm] Error 2 

make[1]: *** [scripts/Makefile.clean:71: drivers/gpu] Error 2 

make: *** [Makefile:1828: _clean_drivers] Error 2 

```

```

Linux desktop 5.10.52-gentoo-dist-hardened #1 SMP Mon Aug 2 04:24:22 EDT 2021 x86_64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz GenuineIntel GNU/Linux 

```

comes from `uname -a`

I find that there's 3 symbolic links to 3 different kernels on my /usr/src/linux and I think I know how that happened:

running a clean make was not working for me after running `eselect kernel set` to start building from the newest kernel.

I tried booting from different kernels, linking that kernel manually, then running make clean to see if that would give the option to rebuild my kernel but it seems to have produced this stacking effect?

Not sure what to do here to get me back to compiling my kernel. Kind of afraid to do more harmLast edited by nicolberg on Fri Aug 20, 2021 7:02 pm; edited 2 times in total

----------

## jyoung

Hi,

The link /usr/src/linux should be unique. What does ls -l /usr/src/linux return?

Did you recently do an emerge --depclean? That would scrub the Makefiles from all but the most recent kernel.

----------

## Goverp

 *nicolberg wrote:*   

> ...
> 
> I find that there's 3 symbolic links to 3 different kernels on my /usr/src/linux and I think I know how that happened:
> 
> ...

 

Sorry, I don't understand what this means; can you elaborate?

/usr/src/linux is a symbolic link, and as such can point at exactly one target.  The target should be a /usr/src/linux-v-r-m-gentoo; "eselect kernel" lets you choose that target from the choices in /usr/src.

----------

## Hu

 *nicolberg wrote:*   

> So after I install the new kernel drivers and perform:

 What new kernel drivers? *nicolberg wrote:*   

> 
> 
> ```
> cd /usr/src/linux/
> 
> ...

 To which kernel source package does /usr/src/linux point? *nicolberg wrote:*   

> I get the following error:
> 
> ```
> desktop /usr/src/linux # make clean 
> 
> ...

 This suggests that you unmerged the kernel sources you are trying to build.  You probably need to redirect the symlink to sources you have installed. *nicolberg wrote:*   

> I find that there's 3 symbolic links to 3 different kernels on my /usr/src/linux and I think I know how that happened:

 Please show us the output instead of describing it. *nicolberg wrote:*   

> running a clean make was not working for me after running `eselect kernel set` to start building from the newest kernel.

 In what way did it fail?

----------

## nicolberg

 *Goverp wrote:*   

>  *nicolberg wrote:*   ...
> 
> I find that there's 3 symbolic links to 3 different kernels on my /usr/src/linux and I think I know how that happened:
> 
> ... 
> ...

 

Sorry; My symbolic & hard links are mixed up.

/usr/src/ (http://0x0.st/-4lk.txt) contains one soft link

/usr/src/linux/ (http://0x0.st/-4lk.txt) contains the three hard links to the other directories in /usr/src/

I say they're hard links because they're flashing on my terminal emulator unlike the /usr/src/ soft link we're optionally instructed to make during kernel upgrade (https://wiki.gentoo.org/wiki/Kernel/Upgrade)

----------

## nicolberg

 *Hu wrote:*   

> 
> 
> What new kernel drivers?
> 
> ...
> ...

 

I tried emerging the kernel sources again just to make sure: http://0x0.st/-4UK.txt

 *Hu wrote:*   

> 
> 
> To which kernel source package does /usr/src/linux point?
> 
> 

 

"linux-5.10.52-gentoo-dist-hardened", here are some of the relevant outputs:

* /usr/src/ : http://0x0.st/-4lk.txt

* /usr/src/linux : http://0x0.st/-4l5.txt

Here are the found error tracebacks:

* make clean : http://0x0.st/-4UZ.txt

* make : http://0x0.st/-4UN.txt

lmk if there're any more commands I should try!

----------

## NeddySeagoon

nicolberg,

```
$ ls -l /usr/src/linux-5.10.52-gentoo-dist-hardened/

total 7080

drwxr-xr-x.  31 root root    4096 Aug  2 05:10 Documentation

-rw-r--r--.   1 root root     580 Aug  2 04:24 Kconfig

drwxr-xr-x.   2 root root    4096 Aug  2 05:10 LICENSES

-rw-r--r--.   1 root root   65112 Aug  2 04:24 Makefile

-rw-r--r--.   1 root root 1550150 Aug  2 05:09 Module.symvers

-rw-r--r--.   1 root root 5532157 Aug  2 05:09 System.map

drwxr-xr-x.  26 root root    4096 Aug  2 05:10 arch

drwxr-xr-x.   3 root root    4096 Aug  2 05:10 block

drwxr-xr-x.   2 root root    4096 Aug  2 05:10 certs

drwxr-xr-x.   4 root root    4096 Aug  2 05:10 crypto

drwxr-xr-x.   2 root root    4096 Aug  2 05:10 distro

drwxr-xr-x. 139 root root    4096 Aug  2 05:10 drivers

drwxr-xr-x.  79 root root    4096 Aug  2 05:10 fs

drwxr-xr-x.  31 root root    4096 Aug  2 05:10 include

drwxr-xr-x.   2 root root    4096 Aug  2 05:10 init

drwxr-xr-x.   2 root root    4096 Aug  2 05:10 ipc

drwxr-xr-x.  19 root root    4096 Aug  2 05:10 kernel

drwxr-xr-x.  21 root root    4096 Aug  2 05:10 lib

lrwxrwxrwx    1 root root      21 Aug  5 22:27 linux-5.10.27-gentoo -> linux-5.10.27-gentoo/

lrwxrwxrwx    1 root root      20 Aug  5 22:28 linux-5.10.52-gentoo -> linux-5.10.52-gentoo

lrwxrwxrwx.   1 root root      35 Aug  5 22:35 linux-5.10.52-gentoo-dist-hardened -> linux-5.10.52-gentoo-dist-hardened/

drwxr-xr-x.   3 root root    4096 Aug  2 05:10 mm

drwxr-xr-x.  72 root root    4096 Aug  2 05:10 net

drwxr-xr-x.  31 root root    4096 Aug  2 05:10 samples

drwxr-xr-x.  17 root root    4096 Aug  2 05:10 scripts

drwxr-xr-x.  13 root root    4096 Aug  2 05:10 security

drwxr-xr-x.  26 root root    4096 Aug  2 05:10 sound

drwxr-xr-x.  35 root root    4096 Aug  2 05:10 tools

drwxr-xr-x.   3 root root    4096 Aug  2 05:10 usr

drwxr-xr-x.   4 root root    4096 Aug  2 05:10 virt
```

The symbolic links

```
lrwxrwxrwx    1 root root      21 Aug  5 22:27 linux-5.10.27-gentoo -> linux-5.10.27-gentoo/

lrwxrwxrwx    1 root root      20 Aug  5 22:28 linux-5.10.52-gentoo -> linux-5.10.52-gentoo

lrwxrwxrwx.   1 root root      35 Aug  5 22:35 linux-5.10.52-gentoo-dist-hardened -> linux-5.10.52-gentoo-dist-hardened/
```

should not be there. They are broken, as they paint to things that do not exist. Its harmless but you can remove them if you wish.

You have a Makefile there.

```
-rw-r--r--.   1 root root   65112 Aug  2 04:24 Makefile
```

Either the kernel sources are damaged or you did not run make/make clean from the top level of the kernel tree, which is nominally, /usr/src/linux

----------

## nicolberg

 *NeddySeagoon wrote:*   

> 
> 
> Either the kernel sources are damaged or you did not run make/make clean from the top level of the kernel tree, which is nominally, /usr/src/linux
> 
> 

 

Just to make sure I ran these in the correct location, I ran the following commands as such:

* http://0x0.st/-4G-.txt

* http://0x0.st/-4Go.txt

Is there a way I can start fresh? I have a previous config file saved

I tried doing a deselect on sys-kernel/gentoo-sources but it wasn't found in my @world

----------

## Jaglover

Nothing in /usr/src is needed to run your computer, meaning it is safe to delete everything if you wish to start fresh.

----------

## Goverp

 *nicolberg wrote:*   

> ...
> 
> I say they're hard links because they're flashing on my terminal emulator unlike the /usr/src/ soft link we're optionally instructed to make during kernel upgrade (https://wiki.gentoo.org/wiki/Kernel/Upgrade)

 

Nope.  A hard link is indistinguishable from a normal file - 'cos all "normal" files are exactly that - a name hard-linked to an inode.  Another hard link is just another name linked to the same inode.  Flashing (reverse red, I assume) is 'ls' colour coding for broken links - i.e. a symbolic link where the target filename does not exist.

If these were the soft links you made following the wiki, you made them in the wrong place, i.e. within /usr/src,s - not sure what you've done,  but it's wrong  :Wink: 

The only way you normally need to make the symbolic links is with "eselect kernel set ...", which sets the one-and-only /usr/src/linux to one of your installed kernel sources.

----------

## nicolberg

I was able to use this Gentoo article to remove the kernel completely.

I also made sure to not remove the one that's currently running as an extra bit of precaution.

(At the time of writing this, the latest sys-kernel/gentoo-sources were 5.10.52)

```

bleachbit -s /boot/*52*

bleachbit -s /lib/modules/5.10.52-gentoo-*

bleachbit -s /usr/src/linux-5.10.52-gentoo*

```

After lurking the forums & wiki some more, I ran

```

cp /usr/src/linux/.config /root/kernel-config

emerge -c sys-kernel/gentoo-sources

emerge --ask --update --deep --with-bdeps=y --newuse @world

emerge --ask --update --deep --with-bdeps=y --newuse sys-kernel/gentoo-sources

USE="symlink" emerge --ask --update --deep --with-bdeps=y --newuse sys-kernel/gentoo-sources

cd /usr/src/linux

ls

make clean

cp /root/kernel-config .config

make menuconfig

make modules_prepare

emerge --ask @module-rebuild -vn

make modules

make modules_install

make

make install

grub-mkconfig -o /boot/grub/grub.cfg

reboot

```

but then it wouldn't work. I think the error was with the initramfs so I looked back in my install notes and remembered I use genkernel to do the initramfs as suggested by the handbook.

I then ran the following

```

cp /usr/src/linux/.config /root/kernel-config

genkernel --kernel-config=/root/kernel-config all

reboot

```

However, now this brought back this sound issure so I think I upgraded my kernel wrong again.

Being that the topic is a bit more than tangential to what I made this thread about, i made this post to open a discussion specifically relating to how to upgrade kernel on an initramfs system.

----------

## nicolberg

 *Jaglover wrote:*   

> Nothing in /usr/src is needed to run your computer, meaning it is safe to delete everything if you wish to start fresh.

 

Thank you! That made me a lot more comfortable in getting going.

I wonder if

```

bleachbit -s /usr/src/linux-5.10.52*

```

does the same as

```

emerge -c sys-kernel/gentoo-sources

```

(I did both either way)

[Moderator edit: fixed [code] tag.  Forum tags use /, not \, to indicate a close tag. -Hu]

----------

## nicolberg

 *Goverp wrote:*   

> 
> 
> Flashing (reverse red, I assume) is 'ls' colour coding for broken links - i.e. a symbolic link where the target filename does not exist.
> 
> 

 

Ah, makes total sense why the red is there. I was very confused as to why it would be red and flashing rather than just some other color if the devs really just wanted to color it.

 *Goverp wrote:*   

> 
> 
> Nope.  A hard link is indistinguishable from a normal file - 'cos all "normal" files are exactly that - a name hard-linked to an inode.  Another hard link is just another name linked to the same inode.
> 
> 

 

Yes, classic. I can usually tell that something is (potentially) a hard link from the second column/"link count" on the ls -l command but it seems like that just flew over my head.

----------

## Hu

 *nicolberg wrote:*   

> I also made sure to not remove the one that's currently running as an extra bit of precaution.
> 
> (At the time of writing this, the latest sys-kernel/gentoo-sources were 5.10.52)

 In stable, yes.  In testing, it is newer.

 *nicolberg wrote:*   

> 
> 
> ```
> bleachbit -s /boot/*52*
> 
> ...

 That first glob probably did the right thing, but is a bit too wild for my preference.  I would have shell-expanded it in place first. *nicolberg wrote:*   

> 
> 
> ```
> bleachbit -s /usr/src/linux-5.10.52*
> ```
> ...

 Why are you using bleachbit here?  Documentation for bleachbit is a bit sparse, but I'm guessing -s is short for --shred, in which case, no, those are not the same.  Shredding the files is for when you care specifically that nobody can read back what was in those files, even with direct access to the block device.  Using emerge -c, short for emerge --depclean, tells Portage to unlink the files from the filesystem.  This cheaply frees the space, but someone with direct block device access can readily try to recover the files.  For kernel sources, you don't need this level of privacy.  It is likely that bleachbit would recursively descend directories, shredding everything in its path.  Portage only deletes the files that are owned by the package you are removing.  Unmanaged content sitting alongside those files is left intact.  This is usually what you want.  Finally, I will note that shredding usually involves multiple attempts to overwrite the same file, which is undesirable on a solid state device.  In short: only use bleachbit if you can explain why you need the extra functionality it offers.  For most users, rm -r would be fine.

----------

## CaptainBlood

IIRC, as far as .config file is concerned,

```
make install all
```

will also install a timestamped versioned copy of it along with the other files, e.g.:

```
ls *5.13.9*

config-5.13.9-gentoo

System.map-5.13.9-gentoo

vmlinuz-5.13.9-gentoo
```

That should provide confidence enough to

```
rm /usr/src/linux-5.11.4-gentoo
```

altogether.

As a side note,

```
/lib/modules/5.13.9-gentoo
```

remains to be removed, for a manual consistent removal of a kernel building package, e.g. gentoo-source-5.13.9

Thks 4 ur attention, interest & support.

----------

## nicolberg

 *Hu wrote:*   

> Why are you using bleachbit here?

 

I guess it's just a brainlet move but I like the added functionality in general.

You were right however: there is a significant performance increase with portage "re-emerging"   :Cool:  sys-kerel/gentoo-sources as, like you said, it gets recovered from memory rather than just reinstalled

 *Hu wrote:*   

> 
> 
>  *nicolberg wrote:*   
> 
> ```
> ...

 

That first glob probably did the right thing, but is a bit too wild for my preference.

I need to practice my wildcard expansion in bash more: Not really experienced with it so I just use the wildcards plainly

----------

## nicolberg

 *CaptainBlood wrote:*   

> 
> 
> IIRC, as far as .config file is concerned,
> 
> ```
> ...

 

I need to brush up on my Makefile, seems very efficient!

I'm assuming (from the `make help` message) that `make install all` expands to

```
make vmlinux

make modules

make install

```

I've never used `make vmlinux`. My workflow for updating my kernel can be found in this post as I have a UEFI system so I have to "change it up" a little

----------

## nicolberg

I figured out the issue was that I was copying the .config from

/usr/src/linux-5.10.27-gentoo to linux-5.10.52-gentoo-dist-hardened and the two config files (hardened vs "standard") were incompatible.

Probably should eventually figure how to get back to a "hardened kernel" but for now I'm happy I'm able to upgrade and boot!

----------

