Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Force portage to download kernel source
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
RomikB
n00b
n00b


Joined: 03 Aug 2024
Posts: 23

PostPosted: Sun Aug 04, 2024 12:16 pm    Post subject: Force portage to download kernel source Reply with quote

I developing a kernel module that require kernel sources while emerging.

How can I ask the portage to install a kernel source (not headers) when for example the system kernel is gentoo-kernel-bin?
gentoo-kernel-bin itself not install the sources and virtual/linux-sources not install any sources.

Should I in 2024 ask users download kernel sources manually?
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2400

PostPosted: Sun Aug 04, 2024 12:25 pm    Post subject: Re: Force portage to download kernel source Reply with quote

RomikB wrote:
I developing a kernel module that require kernel sources while emerging.


then you're using something you're not supposed to.

RomikB wrote:
Should I in 2024 ask users download kernel sources manually?


That's the wrong question to ask. Kernel modules in 2024 require kernel headers only. And they should always have. Headers are the contract with the outside world, what happens in sources is not guaranteed to stay stable. You should conform to the contract, not dig something from the sources.

Best Regards,
Georgi
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9607
Location: beyond the rim

PostPosted: Sun Aug 04, 2024 1:18 pm    Post subject: Reply with quote

There is no way you can ensure that installed kernel sources would match the running kernel anyway.

Why do you think you need kernel sources installed for your module?
Back to top
View user's profile Send private message
RomikB
n00b
n00b


Joined: 03 Aug 2024
Posts: 23

PostPosted: Sun Aug 04, 2024 1:26 pm    Post subject: Re: Force portage to download kernel source Reply with quote

logrusx wrote:
then you're using something you're not supposed to.

I try to emerge the sources of prebuild kernel. Many distribs, possible all, allow it, why gentoo not?

logrusx wrote:
That's the wrong question to ask. Kernel modules in 2024 require kernel headers only. And they should always have. Headers are the contract with the outside world, what happens in sources is not guaranteed to stay stable. You should conform to the contract, not dig something from the sources.

I need to clone some sources from a module integrated in kernel and make a new a little changed module.

And the general question why virtual/linux-sources not emerge sources? Any distrib do it for prebuild kernels why gentoo not?
Back to top
View user's profile Send private message
RomikB
n00b
n00b


Joined: 03 Aug 2024
Posts: 23

PostPosted: Sun Aug 04, 2024 1:29 pm    Post subject: Reply with quote

Genone wrote:
There is no way you can ensure that installed kernel sources would match the running kernel anyway.
Why do you think you need kernel sources installed for your module?


Any prebuild kernel have sources, I just want to find a correct and automatic way to emerge it.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 5090
Location: Bavaria

PostPosted: Sun Aug 04, 2024 1:34 pm    Post subject: Re: Force portage to download kernel source Reply with quote

RomikB wrote:
And the general question why virtual/linux-sources not emerge sources? Any distrib do it for prebuild kernels why gentoo not?

... because you dont need virtual/linux-sources but sys-kernel/gentoo-sources.

Be aware that the default configuration is NOT the configuration of our distribution kernel. You surely know how to get the config from the dist-kernel (zcat /proc/config.gz > running.config)
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
RomikB
n00b
n00b


Joined: 03 Aug 2024
Posts: 23

PostPosted: Sun Aug 04, 2024 1:52 pm    Post subject: Re: Force portage to download kernel source Reply with quote

pietinger wrote:
... because you dont need virtual/linux-sources but sys-kernel/gentoo-sources.

I know. But it is not the answer why linux-sources emege headers not sources for gentoo prebuild kernel.

pietinger wrote:
Be aware that the default configuration is NOT the configuration of our distribution kernel. You surely know how to get the config from the dist-kernel (zcat /proc/config.gz > running.config)

Not sure what are try to say. I guess that for this kernel sys-kernel/gentoo-kernel-bin the sources are in sys-kernel/gentoo-kernel and there is a way to emerge it (without additional kernel compilations).
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2400

PostPosted: Sun Aug 04, 2024 2:00 pm    Post subject: Re: Force portage to download kernel source Reply with quote

RomikB wrote:
I guess that for this kernel sys-kernel/gentoo-kernel-bin the sources are in sys-kernel/gentoo-kernel and there is a way to emerge it (without additional kernel compilations).


They are not. Gentoo-kernel produces the same result as gentoo-kernel-bin but compiled on your computer. Once again, you should not be needing kernel sources to compile a kernel module. That's wrong.

May I ask what does that kernel module do? Is it necessarily a kernel module?

Best Regards,
Georgi
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22618

PostPosted: Sun Aug 04, 2024 2:05 pm    Post subject: Re: Force portage to download kernel source Reply with quote

RomikB wrote:
pietinger wrote:
... because you dont need virtual/linux-sources but sys-kernel/gentoo-sources.
I know. But it is not the answer why linux-sources emege headers not sources for gentoo prebuild kernel.
As I read the ebuild, virtual/linux-sources will pull in some source package, though not necessarily sys-kernel/gentoo-sources. It could pull in any of 13 different possibilities, all of which look to me like they would provide actual kernel sources.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 5090
Location: Bavaria

PostPosted: Sun Aug 04, 2024 2:10 pm    Post subject: Re: Force portage to download kernel source Reply with quote

RomikB wrote:
Not sure what are try to say. I guess that for this kernel sys-kernel/gentoo-kernel-bin the sources are in sys-kernel/gentoo-kernel and there is a way to emerge it (without additional kernel compilations).

Yes, you can just download sys-kernel/gentoo-kernel (emerge -f) and then unpack it:
https://devmanual.gentoo.org/ebuild-writing/functions/index.html
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
RomikB
n00b
n00b


Joined: 03 Aug 2024
Posts: 23

PostPosted: Sun Aug 04, 2024 2:21 pm    Post subject: Re: Force portage to download kernel source Reply with quote

logrusx wrote:
They are not. Gentoo-kernel produces the same result as gentoo-kernel-bin but compiled on your computer. Once again, you should not be needing kernel sources to compile a kernel module. That's wrong.

Is the answer is: "gentoo-kernel-bin have no sources if you need sources use another kernel.

logrusx wrote:
May I ask what does that kernel module do? Is it necessarily a kernel module?

It is a fork of the wireguard kernel module. It use the sources of wireguard, patch them and add new. I not the author, just try to make a gentoo ebuild. It compiles and work on many distribs that use prebuild kernel. I want to do the same here on gentoo.
Back to top
View user's profile Send private message
RomikB
n00b
n00b


Joined: 03 Aug 2024
Posts: 23

PostPosted: Sun Aug 04, 2024 2:27 pm    Post subject: Re: Force portage to download kernel source Reply with quote

Hu wrote:
As I read the ebuild, virtual/linux-sources will pull in some source package, though not necessarily sys-kernel/gentoo-sources. It could pull in any of 13 different possibilities, all of which look to me like they would provide actual kernel sources.

The virtual/linux-sources think that gentoo-kernel-bin provide sources and not try any other possibilities. But gentoo-kernel-bin not provide sources only headers.
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2400

PostPosted: Sun Aug 04, 2024 2:27 pm    Post subject: Re: Force portage to download kernel source Reply with quote

RomikB wrote:

It is a fork of the wireguard kernel module.


That does not need to be a kernel module. The poor choice to make it so also explains the need for kernel sources. Better not bother with it.

Best Regards,
Georgi
Back to top
View user's profile Send private message
RomikB
n00b
n00b


Joined: 03 Aug 2024
Posts: 23

PostPosted: Sun Aug 04, 2024 2:33 pm    Post subject: Re: Force portage to download kernel source Reply with quote

logrusx wrote:
That does not need to be a kernel module. The poor choice to make it so also explains the need for kernel sources. Better not bother with it.

A module wants to be a module for the same reason that wireguard does. Network modules are faster and use less resources.
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2400

PostPosted: Sun Aug 04, 2024 2:47 pm    Post subject: Re: Force portage to download kernel source Reply with quote

RomikB wrote:
logrusx wrote:
That does not need to be a kernel module. The poor choice to make it so also explains the need for kernel sources. Better not bother with it.

A module wants to be a module for the same reason that wireguard does. Network modules are faster and use less resources.


What I see is two poor design choices. For me this is alarming.

You can do whatever you like of course, but I would not bother with it. Especially writing an ebuild for it.

Best Regards,
Georgi
Back to top
View user's profile Send private message
RomikB
n00b
n00b


Joined: 03 Aug 2024
Posts: 23

PostPosted: Sun Aug 04, 2024 3:05 pm    Post subject: Re: Force portage to download kernel source Reply with quote

logrusx wrote:
What I see is two poor design choices. For me this is alarming.

As I know all linux network are inside the kernel. Is it poor design?

logrusx wrote:
You can do whatever you like of course, but I would not bother with it. Especially writing an ebuild for it.

Unfortunately I need to use it. And if I make an ebuild upgrading kernel will be easy.
Back to top
View user's profile Send private message
RomikB
n00b
n00b


Joined: 03 Aug 2024
Posts: 23

PostPosted: Sun Aug 04, 2024 3:08 pm    Post subject: Re: Force portage to download kernel source Reply with quote

pietinger wrote:
Yes, you can just download sys-kernel/gentoo-kernel (emerge -f) and then unpack it:
https://devmanual.gentoo.org/ebuild-writing/functions/index.html

Thank you, I try to use this option.
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2400

PostPosted: Sun Aug 04, 2024 4:15 pm    Post subject: Re: Force portage to download kernel source Reply with quote

RomikB wrote:
logrusx wrote:
What I see is two poor design choices. For me this is alarming.

As I know all linux network are inside the kernel. Is it poor design?


That's false. Look at openvpn.

RomikB wrote:
logrusx wrote:
You can do whatever you like of course, but I would not bother with it. Especially writing an ebuild for it.

Unfortunately I need to use it. And if I make an ebuild upgrading kernel will be easy.


That's also false. You can always run make and make install on your module after a kernel update. An ebuild won't make it easier, rather slower. Just be careful that you either supply the correct kernel dir or adjust it by eselect kernel.

p.s. you can download your own sources as part of the ebuild. It's overkill but it'll work. This way it'll be actually easier when you upgrade your kernel.

Best Regards,
Georgi
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3687
Location: Rasi, Finland

PostPosted: Sun Aug 04, 2024 6:14 pm    Post subject: Re: Force portage to download kernel source Reply with quote

RomikB wrote:
It is a fork of the wireguard kernel module. It use the sources of wireguard, patch them and add new. I not the author, just try to make a gentoo ebuild. It compiles and work on many distribs that use prebuild kernel. I want to do the same here on gentoo.
Patch would be the "correct" route. But that cannot work with *-bin kernels.

To make it work, you could
  • only download the code for wireguard module
  • apply your patch
  • compile
... inside an ebuild. But you'd need to have checks there to make sure the kernel in host system is compatible... That may be hard task.

Or just outright make your ebuild block *-bin kernels.
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2400

PostPosted: Sun Aug 04, 2024 7:17 pm    Post subject: Re: Force portage to download kernel source Reply with quote

Zucca wrote:

Or just outright make your ebuild block *-bin kernels.

-kernel as well. Unless gentoo-kernel installs sources, which I think is not the case.

I still see it as too much and too hard work to be worth it. Still there should be a check if the sources match the running kernel and so on. Only if they wrote it the right way it would have been so much less trouble.

Another option is patches for gentoo-kernel to include it in the kernel. On their site that's a viable option. It should work with default gentoo -kernel configuration, if it works with gentoo-kernel-bin.

Best Regards,
Georgi
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3687
Location: Rasi, Finland

PostPosted: Sun Aug 04, 2024 7:28 pm    Post subject: Re: Force portage to download kernel source Reply with quote

logrusx wrote:
Unless gentoo-kernel installs sources, which I think is not the case.
Nope. At least gentoo-kernel does contain sources.
Code:
zucca@NBLK-WAX9X ~ $ qlist -Iv gentoo-kernel
sys-kernel/gentoo-kernel-6.1.69
zucca@NBLK-WAX9X ~ $ qlist =sys-kernel/gentoo-kernel-6.1.69 | grep '^/usr/src/linux-' | wc -l
17936
(Yeah. I should update already.)
That said... maybe *-bin kernels should have USE=include-sources or something similar.

logrusx wrote:
Only if they wrote it the right way it would have been so much less trouble.
Yes. A proper fork of the module would be easiest maybe. I can't state much more as I haven't had a need to write a kernel module, let alone know enough to do so.
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9607
Location: beyond the rim

PostPosted: Sun Aug 04, 2024 11:15 pm    Post subject: Reply with quote

The proper solution for your use-case is not to depend on kernel sources and do some copy+patch routine, but provide the patched wireguard sourcetree with your ebuild (like the wireguard-modules ebuild does for older kernels).

Keep in mind that gentoo-kernel-bin is just an option for users, many users will use a different kernel so installing the sources for gentoo-kernel-bin wouldn't fly anyway. Not to mention that you'd have to figure out which version to use as well.

That said, it seems strange to me that gentoo-kernel-bin (and vanilla-sources-bin) is actually a provider for virtual/linux-sources. But I guess there is a reason for that.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3420

PostPosted: Sun Aug 04, 2024 11:40 pm    Post subject: Reply with quote

I wonder, what does this patch even do?
Like in: how is it better than wireguard already included in mainline kernel?

Since you're writing an ebuild, I suppose you want to share it. For local-only tweaks, you could just drop a diff into /etc/portage/patches/<category>/<package>/ and have emerge apply your changes automatically to every new version your install. Very convenient, though not very portable.
_________________
Make Computing Fun Again
Back to top
View user's profile Send private message
logrusx
Advocate
Advocate


Joined: 22 Feb 2018
Posts: 2400

PostPosted: Mon Aug 05, 2024 4:38 am    Post subject: Re: Force portage to download kernel source Reply with quote

Zucca wrote:
logrusx wrote:
Unless gentoo-kernel installs sources, which I think is not the case.
Nope. At least gentoo-kernel does contain sources.


Back when I used gentoo kernel it seemed it didn't provide sources, just replicate what gentoo-kernel-bin is locally. I don't have the time to test now.

Best Regards,
Georgi
Back to top
View user's profile Send private message
RomikB
n00b
n00b


Joined: 03 Aug 2024
Posts: 23

PostPosted: Mon Aug 05, 2024 8:19 am    Post subject: Reply with quote

szatox wrote:
I wonder, what does this patch even do?
Like in: how is it better than wireguard already included in mainline kernel?

Wireguard protocol is easy to detect by Deep Packet Inspection (DPI) systems. In my country wireguard protocol is detected and blocked.
The patch add some advanced obfuscation methods to make "Undetectable by DPI analysis systems, resistant to blocking".

Zucca wrote:
That said... maybe *-bin kernels should have USE=include-sources or something similar.

I want to offer something like this also.

Genone wrote:
That said, it seems strange to me that gentoo-kernel-bin (and vanilla-sources-bin) is actually a provider for virtual/linux-sources. But I guess there is a reason for that.

It is my main guestion.

Genone wrote:
The proper solution for your use-case is not to depend on kernel sources and do some copy+patch routine, but provide the patched wireguard sourcetree with your ebuild (like the wireguard-modules ebuild does for older kernels).
I ask the wireguard fork devs about using kernel source. They say that wireguard module source is different in different kernels on different distros. Thats why they use current system kernel source to build compatible to system kernel module.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum