View previous topic :: View next topic |
Author |
Message |
rupeshforu3 n00b

Joined: 19 Aug 2024 Posts: 61
|
Posted: Fri Feb 21, 2025 9:29 am Post subject: How to safely compile kernel myself install and use it. |
|
|
Hi I am Rupesh from India and I have brought a new system with AMD Ryzen zen3 5500GT and Asus prime b450 motherboard. I installed Linux Operating System five months back updating, and using it without any problem. I thought to compile kernel source code optimized for my hardware and succeeded but I have some doubts.
I want to compile kernel source code to remove unnecessary blotware in the kernel and to improve performance.
I have read a number of tutorials and tried or experimented to compile kernel and learnt a number of lessons.
I tried to compile kernel according to what I learnt but still there may be any mistakes. As you are experts can you try to examine the steps I followed and give suggestions.
The main steps I followed are as follows
1) Downloaded and installed kernel source code package.
2) Extracted the source code to my home directory.
3) Changed the ownership of the extracted directory recursively through the following command.
Code: |
chown -R $USER:$USER linux
|
4) Entered the source directory and issued the following command to clean any existing configuration.
5) I entered the following lines to my bash profile so that I need not enter again and again in terminal emulator.
Code: |
export KCPFLAGS=" -march=znver3 -O2 pipe"
export KCLAGS=" -march=znver3 -O2 pipe"
export CFLAGS=" -march=znver3 -O2 pipe"
export CPFLAGS=" -march=znver3 -O2 pipe"
|
6) After that I have created a configuration file which consists of only the modules loaded by old kernel through the following command.
Code: |
make localmodconfig
|
7) After that I entered the following command.
In this gui configuration I done the following changes.
*I selected amdgpu option to compile as module.
*I have added the string Rupesh to LocalVersion
*I have selected append Local_Version to version to yes
*I have disabled support for other processors like intel etc except AMD.
*I have saved and exited the configuration.
9) After that I issued the following command to make the kernel and modules.
Code: |
make bzImage modules
|
10) After that I issued the following command to install modules
Code: |
make modules_install
|
11) After that I have tried to install kernel to /boot through the following command.
12) After that I have updated my grub configuration through the following command.
Code: |
grub-mkconfig -o /boot/grub/grub.cfg
|
13) After that I have installed the grub boot loader through the following command.
Code: |
grub install /dev/nvmen101
|
I think that there is nothing better than "make localmodconfig" to create configuration file.
Previously I tried to compile mainline kernel which is downloaded from kernel.org but I thought distribution kernel source code is more efficient so I tried to compile distribution kernel.
Finally I am asking is it safe to compile kernel myself or it is recommended to use default kernel provided by distribution.
Kindly try to clarify my doubts. _________________ Regards,
Rupesh. |
|
Back to top |
|
 |
Banana Moderator


Joined: 21 May 2004 Posts: 1902 Location: Germany
|
Posted: Fri Feb 21, 2025 11:12 am Post subject: |
|
|
Quote: | Finally I am asking is it safe to compile kernel myself or it is recommended to use default kernel provided by distribution. |
Save is not an absolute thing, it depends on your preferences. Distribution kernels, either -bin or sources, do have additional patches added which the distribution think are good and needed.
So, yes you can do it the way to do it, but do not expect that your way is better. It is diferent. There are no absolute ways or configs which would result in the best possible. _________________ Forum Guidelines
PFL - Portage file list - find which package a file or command belongs to.
My delta-labs.org snippets do expire |
|
Back to top |
|
 |
Goverp Advocate


Joined: 07 Mar 2007 Posts: 2207
|
Posted: Fri Feb 21, 2025 11:14 am Post subject: |
|
|
Rupesh,
In essence, the steps you list seem correct. I think you will have a problem because the device drivers for your disks or NVMe or whatever will be modules, and therefore not available when you first boot this kernel.
Have you tried booting your new kernel, and if so, did it work? If not, what messages did you get?
Quote: | 1) Downloaded and installed kernel source code package. | - which package?
Quote: | 11) After that I have tried to install kernel to /boot through the following command.- | you should see your kernel in /boot, with a name "vmlinuz-x.y.z-rupesh" for whichever kernel version x.y.z you downloaded.
You should also see that in grub.cfg, if your "grub-mkconfig" worked correctly.
Quote: | Previously I tried to compile mainline kernel which is downloaded from kernel.org but I thought distribution kernel source code is more efficient so I tried to compile distribution kernel. |
If "mainline kernel" means one from kernel.org, and "distribution kernel" is the package sys-kernel/gentoo-sources, the difference it not of efficiency. AFAIR gentoo-sources are basically the same as kernel.org but a little bit older (to allow ~arch users to find the bugs!), perhaps with patches need in response to bugs found by Gentoo users, and with patches to allow configuring OpenRc vs Systemd and to ensure some basic security features are selected.
You might find the "kmake" script I use (see my page in the wiki) useful. _________________ Greybeard |
|
Back to top |
|
 |
NeddySeagoon Administrator


Joined: 05 Jul 2003 Posts: 54901 Location: 56N 3W
|
Posted: Fri Feb 21, 2025 11:45 am Post subject: |
|
|
rupeshforu3,
Safe in what respect?
Secure ... it could be better. Start reading here and here
Don't use Code: | export KCPFLAGS=" -march=znver3 -O2 pipe"
export KCLAGS=" -march=znver3 -O2 pipe"
export CFLAGS=" -march=znver3 -O2 pipe"
export CPFLAGS=" -march=znver3 -O2 pipe" | Choose your CPU in the list in the configuration tool.
If it breaks when you pass your flags to the kernel build system, nobody will have seen the problem before.
USE=experimental when you emerge gentoo-sources will get you a patch that adds more CPUs to the list in in the kernel.
They are better tested than doing your own thing.
What happens when you get a panic on boot?
You will - don't expect it to work first time. :)
For easy recovery, you keep a few extra known working kernels in the boot menu.
Your own kernel will not be any faster, at least not measurably, than the distribution kernel.
It can have a smaller attack surface, as it is not required to boot everywhere and take up less HDD space.
The kernels job is to arbitrate among contenders for resources, then get out of the way, so that the code you want to run gets on the CPU. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
 |
rupeshforu3 n00b

Joined: 19 Aug 2024 Posts: 61
|
Posted: Fri Feb 21, 2025 11:52 am Post subject: |
|
|
The kernel source package I have installed is
sys-kernel/zen-sources
Kernel version is 6.12.10
At the time of configuration I found the following error
Nvme_common not found.
Another issue is as I have entered the command "make localmodconfig" I thought everything will go fine but the configuration related to windows file systems like exFAT, NTFS etc. are not enabled.
After booting into the latest kernel I tried to mount exFAT partition directly through gui file manager but I received error as this partition support is not present in the kernel.
Similarly I think few settings are not present in the kernel configuration which are necessary to system work properly. _________________ Regards,
Rupesh. |
|
Back to top |
|
 |
sublogic Guru


Joined: 21 Mar 2022 Posts: 314 Location: Pennsylvania, USA
|
Posted: Sat Feb 22, 2025 3:08 am Post subject: Re: How to safely compile kernel myself install and use it. |
|
|
rupeshforu3 wrote: | Code: | make localmodconfig |
|
I would recommend:- make localyesconfig
- make xconfig and change the graphics and networking drivers back to modules
#1 ensures that your storage and filesystem drivers are builtin, not modules, thereby avoiding the issue pointed out by Goverp earlier.
#2 is for drivers that need external firmware; they are not needed in early boot, will initialize after the root partition is mounted, and will load what they need from /lib/firmware .
If you omit #2, you will probably be restricted to text consoles, and have no networking.
Quote: | Another issue is as I have entered the command "make localmodconfig" I thought everything will go fine but the configuration related to windows file systems like exFAT, NTFS etc. are not enabled. | Because the drivers were not in use when you ran localmodconfig. You should have mounted some exFAT or NTFS partitions before starting. Now, go back in xconfig and add the drivers (as modules). Also add USB storage, CDROM, etc. Rebuild, reinstall and reboot.
(Always keep a known good kernel as backup !) |
|
Back to top |
|
 |
rupeshforu3 n00b

Joined: 19 Aug 2024 Posts: 61
|
Posted: Sat Feb 22, 2025 11:50 am Post subject: |
|
|
Yesterday while compiling in the xconfig window for the amdgpu option I have selected y installed of m.
It's meaning is compile amdgpu into the kernel instead of module.
After installation of the kernel I booted into the latest kernel but I can't start display manager and so I have entered startx but I got errors related to drm.
In the grub boot loader I have selected old kernel to boot and at this time I am able to start display manager.
After that in the xconfig window I have selected amdgpu to compile as module.
After installation of the kernel I booted into the latest kernel and I am able to start display manager without any errors.
So localyesconfig tries to create configuration file with modules inbuilt into the kernel and so the system may not boot properly. _________________ Regards,
Rupesh. |
|
Back to top |
|
 |
pietinger Moderator

Joined: 17 Oct 2006 Posts: 5419 Location: Bavaria
|
|
Back to top |
|
 |
rupeshforu3 n00b

Joined: 19 Aug 2024 Posts: 61
|
Posted: Sat Feb 22, 2025 1:11 pm Post subject: |
|
|
Thanks for your support and I will read this tutorial thoroughly and do what you said. _________________ Regards,
Rupesh. |
|
Back to top |
|
 |
|