Article View: linux.gentoo.user
Article #104Re: [gentoo-user] Building a custom kernel
From: Pocket
Date: Fri, 06 Nov 2026 18:20
Date: Fri, 06 Nov 2026 18:20
128 lines
5571 bytes
5571 bytes
On 11/6/26 10:40, Michael wrote:
> On Friday, 6 November 2026 15:10:33 Greenwich Mean Time Pocket wrote:
>> I have my gentoo project going very well and I would like to rebuild
>> the rpi kernel to have btrfs built into the kernel instead of a
>> module.
>>
>> I want to use btrfs as the filesystem for the root partition as I do
>> on my archlinux systems.
>>
>> I have looked at the ebuilds for kernels and I can not figure them
>> out. I have looking into portage as a later project after I finish
>> this desktop project.
>>
>> I have three options at this point.
>>
>> 1. Use my custom kernel build from archlinuxarm using my PKGBUILD and
>> remove the ebuild and extract the package archive to system.
>>
>> 2. Modify a kernel ebuild.
>>
>> 3. Create a initramfs
>>
>>
>> Any one have any hints or direction on how to accomplish this?
>
> In the first instance you can read these pages a couple of times to get
> a grounding on what options Gentoo offers, both in its distribution
> kernels and DIY from source:
>
> https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Kernel
> https://wiki.gentoo.org/wiki/Kernel
>
> If you know your archlinuxarm is exactly, or mostly, what you want from
> a kernel configuration, you can use the archlinuxarm configuration to
> get you ready to compile your own kernel from source. The general idea
> is to follow the basic steps below:
>
> 1. First emerge sys-kernel/gentoo-sources.
> 2. Check what modules are loaded when you boot with your archlinuxarm
> kernel. You may wish to build some of these in-kernel, as opposed to
> have them as loadable modules and exclude any modules which do not need
> if you want to keep the kernel image small(er) in size.
> 3. Copy the archlinuxarm running .config into the gentoo-sources
> installed in /usr/src/linux/.
> 4. Run 'make oldconfig', followed by 'make menuconfig' to adjust the
> configuration as you want.
> 5. Compile and install as described at the bottom of the Handbook page
> above.
>
> The above should get you mostly there. You can use dracut or a UKI if
> you need an initramfs.
>
> HTH.
I have a archlinux PKGBUILD that I wrote to build a custom kernel.
The upstream source is from raspberrypi kernel sources and I modiify
.config to add btrfs as built in not a module.
I thought I could convert the PKGBUILD to ebuild then add it to a custom
repository, then emerge that.
Looking at the gentoo kernel ebuilds didn't give me a way forward.
I am still looking at that. My PKGBUILD file is nothing like the gentoo
ebuild.
Goes something like this......
https://github.com/raspberrypi/linux/archive/refs/tags/stable_20260911.tar.gz
prepare() {
cd "$srcdir"/"$_pkgname"_"$_pkgver"
make mrproper
make bcm2711_defconfig
sed -e '/^CONFIG_BTRFS_FS/s|m|y|' -i .config
make oldconfig
}
build() {
cd "$srcdir"/"$_pkgname"_"$_pkgver"
make Image.gz modules dtbs
}
then package that into a tar archive'
package() {
# variables
make -s kernelrelease > version
version="$(< version)"
# Install kernel modules
mkdir -vp "$pkgdir/usr"
make INSTALL_MOD_PATH="$pkgdir/usr" INSTALL_MOD_STRIP=1 \
DEPMOD=/doesnt/exist modules_install # Suppress depmod
# Install kernel and firmware
mkdir -vp "${pkgdir}"/boot/overlays
cp -v arch/arm64/boot/Image.gz "${pkgdir}"/boot/$KERNEL.img
cp -v arch/arm64/boot/dts/broadcom/*.dtb "${pkgdir}"/boot/
cp -v arch/arm64/boot/dts/overlays/*.dtb* "${pkgdir}"/boot/overlays
cp -v arch/arm64/boot/dts/overlays/README "${pkgdir}"/boot/overlays
# Versioning, system map and configuration
cp -v version "${pkgdir}"/boot/
cp -v System.map "${pkgdir}"/boot/System.map-"$version"
cp -v .config "${pkgdir}"/boot/config-"$version"
# Boot and Configuration
cp -v "$srcdir"/cmdline.txt "${pkgdir}"/boot/
cp -v "$srcdir"/config.txt "${pkgdir}"/boot/
# Remove symlink that points to file in the building directory
unlink "${pkgdir}"/usr/lib/modules/6.18.50-v8/build
}
I guess I could make a shell script to install directly to /boot and
/usr but I was really looking to make an ebuild for this.
A PKGBUILD is nothing more than a shell script that makepkg calls.
I don't really need or want an initramfs
--
Hindi madali ang maging ako
Technical Details
Message-ID:
<NWwHD-aeXC-15@gated-at.bofh.it>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomodReferences:
<NWtTs-adpa-21@gated-at.bofh.it> <NWumt-adAe-13@gated-at.bofh.it>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod From: Pocket <pocket@oldfart.online> Newsgroups: linux.gentoo.user Subject: Re: [gentoo-user] Building a custom kernel Date: Fri, 06 Nov 2026 19:20:01 +0100 Message-ID: <NWwHD-aeXC-15@gated-at.bofh.it> References: <NWtTs-adpa-21@gated-at.bofh.it> <NWumt-adAe-13@gated-at.bofh.it> List-ID: Gentoo Linux mail <gentoo-user.gentoo.org> Reply-To: gentoo-user@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Envelope-From: pocket@oldfart.online Approved: robomod@news.nic.it Lines: 128 Organization: linux.* mail to news gateway Sender: robomod@news.nic.it X-Original-Date: Fri, 6 Nov 2026 13:16:13 -0500 X-Original-Message-ID: <06ed66b8-a78e-4a5d-9d68-3f935d397d2b@oldfart.online> X-Original-References: <96dbc5af-dc8c-450e-9b4e-1e6a40be4cdd@oldfart.online> <hokyXLvHR06uCKzIA5XC-g@kintzios.com>