From Gentoo Wiki
Jump to:navigation Jump to:search
Any issues caused by following this are not Gentoo bugs. Gentoo dependencies exist for good reason and the project cannot support deviation. IRC support may be given in the form of helpful hints to solve your issue however, you must clearly state you are using an older kernel and why, while asking for help.
This system will be a security risk so direct access to the Internet should not be allowed.
This page makes use of emerge --clean to workaround some issues, this should not be copied on any other system and emerge --deselect should be used instead.

This guide is intended for those that need to use an older kernel as that's all the hardware supports. Throughout this guide we will be using a 2.6.39 kernel as it's the oldest recommended by Musl however, older ones can still work with it and feel free to add the needed fixes to this guide.

Gentoo on Older Kernels


Log into the system, create your partitions, mount them, change into that directory and then finally download the Musl stage3 tarball for your system (this guide will be using amd64 as the example.)

Due to these devices having a number of ways the above steps need to be completed this guide will start from unpacking the stage3:

root #tar xvf stage3-amd64-musl-latest.tar.xz

Mount the required filesystems:

root #mount --types proc /proc /mnt/gentoo/proc
root #mount --rbind /sys /mnt/gentoo/sys
root #mount --make-rslave /mnt/gentoo/sys
root #mount --rbind /dev /mnt/gentoo/dev
root #mount --make-rslave /mnt/gentoo/dev
root #mount --bind /run /mnt/gentoo/run
root #mount --make-slave /mnt/gentoo/run
root #test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
root #mount --types tmpfs --options nosuid,nodev,noexec shm /dev/shm
root #chmod 1777 /dev/shm /run/shm

/run isn't provided by all old host systems so you can ignore it if it's not there.

Next copy over /etc/resolv.conf so Internet works in the chroot:

root #cp --dereference /etc/resolv.conf /mnt/gentoo/etc/

Chroot into the system:

root #chroot /mnt/gentoo /bin/bash
root #source /etc/profile

Before moving on to the next step this is the time to setup make.conf with the require common flags and use flags and finally run emerge-webrsync.

root #emerge-webrsync

Create Local Repository

Now, create a local repo for the kernel headers to match the device's kernel.

root #emerge --ask eselect-repository
root #eselect repository create local
root #mkdir -p /var/db/repos/local/sys-kernel/linux-headers
root #cp -r /var/db/repos/gentoo/sys-kernel/linux-headers/* /var/db/repos/local/sys-kernel/linux-headers/
root #cd /var/db/repos/local/sys-kernel/linux-headers/

Next, create the required kernel headers version:

root #nano linux-headers-2.6.39.ebuild
FILE linux-headers-2.6.39.ebuildlinux-headers-2.6.39.ebuild
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2


H_SUPPORTEDARCH="alpha amd64 arc arm arm64 avr32 bfin cris frv hexagon hppa ia64 m32r m68k metag microblaze mips mn10300 openrisc ppc ppc64 s390 score sh sparc tile x86 xtensa"
inherit kernel-2 toolchain-funcs


KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~m68k ~mips ppc ppc64 ~riscv ~s390 sparc x86 ~amd64-linux ~x86-linux"


[ [ -n ${PATCH_VER} ] ] && PATCHES=( "${WORKDIR}"/${PV} )

src_unpack() {
	# avoid kernel-2_src_unpack

src_prepare() {
	# avoid kernel-2_src_prepare

src_test() {
	einfo "Possible unescaped attribute/type usage"
	grep -E -r \
		-e '(^| [ [:space:](])(asm|volatile|inline)[ [:space:] (]' \
		-e '\<([us](8|16|32|64))\>' \

	emake ARCH="$(tc-arch-kernel)" headers_check

src_install() {

	find "${ED}" \( -name '.install' -o -name '*.cmd' \) -delete || die
	# delete empty directories
	find "${ED}" -empty -type d -delete || die

	# provided by libdrm (for now?)
	rm -rf "${ED}"/$(kernel_header_destdir)/drm || die

Change the header sources to what you need and others can be obtained from here.

Create a manifest for the ebuild:

root #ebuild linux-headers-2.6.39.ebuild manifest

Install Headers

First, remove sys-libs/libseccomp as it won't be supported by this kernel.

root #emerge --clean sys-libs/libseccomp

Using --clean isn't recommended normally however, in this case it is required so we can emerge the 2.6.29 headers.

root #emerge --ask =sys-kernel/linux-headers-2.6.39

This is the time to add USE="-seccomp" to your make.conf.

FILE /etc/portage/make.confmake.conf example
# These settings were set by the catalyst build script that automatically
# built this stage.
# Please consult /usr/share/portage/config/make.conf.example for a more
# detailed example.
COMMON_FLAGS="-march=native -O2 -pipe"


# NOTE: This stage was built with the bindist Use flag enabled

# This sets the language of build output to English.
# Please keep this setting intact when reporting bugs.


Now, create a package.mask so a newer kernel header isn't installed:

FILE /etc/portage/package.mask/kernel-headerspackage.mask

Ebuild fixes

Some ebuilds need to be edited to work.


This can be ignored on kernels newer than 4.13.
root #mkdir -p /var/db/repos/local/sys-apps/shadow
root #cp -r /var/db/repos/gentoo/sys-apps/shadow/* /var/db/repos/local/sys-apps/shadow
root #cd /var/db/repos/local/sys-apps/shadow

The btrfs flag will case issues here so you will need to remove the --enable-btrfs flag inside for for this to compile.

root #ebuild shadow-4.12.13.ebuild manifest


This section can be ignored on newer kernels (i.e 3.x)

net-misc/iputils cannot build due to the ipv6 headers so we need to disable this systemwide so only ipv4 can be used.

FILE /etc/portage/profile/profile.provided/iputilsiputils
FILE /etc/portage/make.confmake.conf example
USE="-seccomp -ipv6"


A header file is missing to allow net-forewall/iptables to successfully compile.

root #mkdir -p /usr/include/linux/netfilter
FILE /usr/include/linux/netfilter/nf_log.h
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

#define NF_LOG_TCPSEQ		0x01	/* Log TCP sequence numbers */
#define NF_LOG_TCPOPT		0x02	/* Log TCP options */
#define NF_LOG_IPOPT		0x04	/* Log IP options */
#define NF_LOG_UID		0x08	/* Log UID owning local socket */
#define NF_LOG_NFLOG		0x10	/* Unsupported, don't reuse */
#define NF_LOG_MACDECODE	0x20	/* Decode MAC header */
#define NF_LOG_MASK		0x2f

#define NF_LOG_PREFIXLEN	128

#endif /* _NETFILTER_NF_LOG_H */


Stop sys-libs/libseccomp from being pullied in the future

FILE /etc/portage/profile/profile.provided/libseccomplibseccomp


sys-libs/pam won't build with earlier headers, so this will disable it.

FILE /etc/portage/make.confmake.conf example
USE="-seccomp -pam"
FILE /etc/portage/package.use/util-linuxmake.conf example
sys-apps/util-linux -su

Replace sys-apps/systemd-utils with sys-fs/eudev

This can be ignored on kernels newer than 3.10.

sys-apps/systemd-utils won't work with the older headers so it needs to be replaced.

root #emerge -C virtual/udev sys-fs/udev-init-scripts virtual/dev-manager sys apps/systemd-utils virtual/tmpfiles

Next. a patch is required to remove the V4L part being built:

root #mkdir -p /etc/portage/patches/sys-fs/eudev
FILE /etc/portage/patches/sys-fs/eudev/eudev-remove-v4l.patchudev-remove-v4l.patch
--- a/src/v4l_id/    2021-12-14 19:57:01.000000000 +0000
+++ b/src/v4l_id/    2022-10-26 01:52:38.581688184 +0000
@@ -1,14 +1 @@

-       -I $(top_srcdir)/src/shared
-udevlibexec_PROGRAMS = \
-       v4l_id
-v4l_id_SOURCES = \
-       v4l_id.c
-v4l_id_LDADD = \
-       $(top_builddir)/src/libudev/ \
-       $(top_builddir)/src/udev/
root #emerge --ask sys-fs/eudev

Some fixes need to be applied:

root #mkdir -p /var/db/repos/local/virtual/tmpfiles
root #cp -r /var/db/repos/gentoo/virtual/tmpfiles/* /var/db/repos/local/virtual/tmpfiles/

Edit the ebuild to remove everything after the RDEPEND line in the local repo copy.

root #ebuild /var/db/repos/local/virtual/tmpfiles/tmpfiles-0-r3.ebuild manifest

Finally, emerge sys-apps/opentmpfiles:

root #mkdir -p /etc/portage/package.unmask
FILE /etc/portage/package.unmask/tmpfilestmpfiles
root #emerge --ask sys-apps/opentmpfiles

Re-emerge the system

Emerge the system again to take advantage of your new flags and rebuild against the correct headers for your system.

root #emerge --ask --emptytree @system

The base system is now installed, so now continue with original handbook for your system to make it bootable.

Known Packages to Fail under 2.6.39

net-misc/dhcpcd Can be replaced with net-dns/ddclient

See also