Problems building a custom kernel 0n 4.2.0

Post questions about how to make a customized SystemRescueCd, and if you have problems to install new packages. Please read the handbook first.
Post Reply
Posts: 86
Joined: 22 Jun 2012, 02:24

Problems building a custom kernel 0n 4.2.0

Post by vanepp » 11 May 2014, 04:42

I'm trying to build a custom kernel (with the ultimate aim of making a rescuecd system that boots without a ram
disk from a disk assuming I can figure out how). However I've hit a problem and a couple of documentation errors
listed below. An ext3 file system is mounted on /mnt/custom and the files from the CD have been extracted successfully.
The 4 kernel patches and the 3.10 kernel sources have been aquired installed and patched in to /mnt/custom/files/usr/src after a couple of documentation errors were overcome. On page ... own_kernel

wget -c ... 3.4.tar.xz

should be

wget -c ... 3.4.tar.xz

to actually get the source (the original gives a directory not found error). Then later in the same page

wget -r -l1 -A bz2 --no-directories

should be

wget -r -l1 -A xz --no-directories

as the compression method has changed at some point and the original line returns no files as the filter fails.
Further down the same page

cd /usr/src/linux-3.4
make gconfig

doesn't work, it complains about no GTK+ librarys (running on X) but the text version

make menuconfig

does work. So the kernel sources are installed and patched as documented, I set .config from /proc/.config.gz on
the CD and set up a current copy of portage in the chroot jail and did

emerge crossdev

to get the cross compiler support that I think is needed to build a 64 bit kernel. However gives erros (probably because
I have missed setting something :-)):

CROSS_COMPILE=x86_64-pc-linux-gnu- ARCH=x86_64 make
sysresccd linux-3.10 # CROSS_COMPILE=x86_64-pc-linux-gnu- ARCH=x86_64 make
/usr/src/linux-3.10/arch/x86/Makefile:98: stack protector enabled but no compiler support
/usr/src/linux-3.10/arch/x86/Makefile:113: CONFIG_X86_X32 enabled but no binutils support
make: x86_64-pc-linux-gnu-gcc: Command not found
scripts/kconfig/conf --silentoldconfig Kconfig
/usr/src/linux-3.10/arch/x86/Makefile:98: stack protector enabled but no compiler support
/usr/src/linux-3.10/arch/x86/Makefile:113: CONFIG_X86_X32 enabled but no binutils support
make: x86_64-pc-linux-gnu-gcc: Command not found
make[1]: Nothing to be done for `all'.
make[1]: Nothing to be done for `relocs'.
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CC kernel/bounds.s
/bin/sh: x86_64-pc-linux-gnu-gcc: command not found
make[1]: *** [kernel/bounds.s] Error 127
make: *** [prepare0] Error 2

Can someone tell me what I'm doing wrong here please?

Peter Van Epp

Posts: 86
Joined: 22 Jun 2012, 02:24

Re: Problems building a custom kernel 0n 4.2.0

Post by vanepp » 16 May 2014, 03:07

Half a step forward to the next problem :-). The first problem is that the documentation is incomplete and
the crossdev package doesn't have the tool chain(s) compiled in. After much searching and head scratching I've
got the x86_64 toolchain compiled in ad loaded on a DVD (since it is too big for a CD). So I downloaded
the 3.10 kernel sources and the 4 patch files and patched the sourcei, copied the config file from /proc/config.gz
(to build an umchanged kernel to make sure I can) and ran the CROSSCOMPILE again. It runs along and dies on this error message now:

/usr/src/linux-3.10/scripts/ Cannot open '/var/tmp/genkernel/initramfs-3.10.35-std420-amd64.cpio'

which would be correct because the file doesn't exist. I don't see any such file in the source tree. The docs
suggest I need to create a cpio file later and compile twice but it doesn't mention this particular path anywhere
I can see. Suggestions on what I need to do to proceed? I am keeping a log of the steps to do this and assuming
I'm ever successfull I'll post it so the docs could be updated (after someone knowledgable checks that it is in
fact correct!).

Peter Van Epp

Posts: 86
Joined: 22 Jun 2012, 02:24

Re: Problems building a custom kernel 0n 4.2.0

Post by vanepp » 16 May 2014, 03:30

Easy one :-) rrtfm (reread the manual) which says

"Also it's important to disable CONFIG_INITRAMFS_SOURCE (remove the value which contains just a space) except if you know how to use it. "

It is apparantly on by default in the running config, and obviously I don't know how to use it :-). Replacing the
file name with a blank from menuconfig is letting the kernel compile so I may yet have success ...

Peter Van Epp

Posts: 86
Joined: 22 Jun 2012, 02:24

Re: Problems building a custom kernel 0n 4.2.0

Post by vanepp » 17 May 2014, 01:21

Further but still no cigar. The kernel now compiles using the commands:

CROSS_COMPILE=x86_64-pc-linux-gnu- ARCH=x86_64 make
CROSS_COMPILE=x86_64-pc-linux-gnu- ARCH=x86_64 make modules
CROSS_COMPILE=x86_64-pc-linux-gnu- ARCH=x86_64 make modules_install

however this doesn't appear to create 64 librarys only 32 bit.

ls -l /lib64/modules
drwx... apr 1518:54 3.10.35-std420-amd64
dwrx... apr 1518:54 3.13.10-alt420-amd64

ls -l /lib/modules

lrwx... apr 15 18:54 3.10.35-std420 -> /lib64/modules/3.10.35-std420-amd64
drwx... apr 15 18:54 3.10.35-std420-i586
drxx... may 17 00:59 3.10.39-gentoo (my new kernel librarys presumably 32 bit!)
lrwx... apr 15 18:54 3.13.10-alt420-amd64 -> lib64/modules/3.13.10-alt420-amd64
drwx... apr 15 18:54 3.13.10-alt420-amd64 3.13.10-alt420-i586

presumably the 3.10.39-gentoo should be in /lib64/modules with a link in to the /lib/modules directory like the
other 2 kernels but the crossdev environment hasn't done that (or I failed to tell it to which is also possible). I also
don't understand why it thinks the version is 3.10.39 when it was built from the sysresccd patch set which should have created version 3.10.35 at least according to the patch 1 file name (and the name of the current kernels). While
I'll poke at the crossdev docs on gentoo suggestions would be welcome (and solutions even more so!).

Peter Van Epp

Posts: 86
Joined: 22 Jun 2012, 02:24

Re: Problems building a custom kernel 0n 4.2.0

Post by vanepp » 18 May 2014, 00:25

Well this has been educational at least :-). I just realized I have been misreading the documentation and that
I only need the crossdev environment to build a 64 bit kernel on a 32 bit machine (which isn't the case I'm
dealing with). On the bright side I believe I have figured out how to configure the crossdev environment (which
isn't simple) so I'll leave my documetatuon here in case it is usefull to anyone else in future and/or makes it
in to the documentation.

1) boot from the current rescuecd (4.2.0 in my case)

2) partition the drive to the desired gentoo layout:

/dev/sda1 bootloader 2M bios boot partition
/dev/sda2 grub (ext2) 128M
/dev/sda3 (swap) 500M swap
/dev/sda4 ext3 rest linux partiton


parted -a optimal /dev/sda
(parted) mklabel msdos
(parted) unit mib
(parted) mkpart primary 1 3
(parted) set 1 boot on
(parted) mkpart primary 3 131
(parted) mkpart primary 131 531
(parted) mkpart primary 531 -1
(parted) q

3) format the file systems as follows:

mkfs.ext2 /dev/sda2
mkfs.ext3 /dev/sda4

(ext3 rather then ext4 so partimage can back it up!)

4) mount the file systems

mount /dev/sda4 /mnt/custom
mkdir /mnt/custom/boot
mount /dev/sda2 /mnt/custom/boot

5) extract the files from the CD

/usr/sbin/sysresccd-custom extract

6) copy DNS info for after chroot

cp -L /etc/resolv.conf /mnt/custom/customcd/files/etc/
(answer y to the overwrite request)

7) chroot in to the system we just set up

mkdir -p /mnt/custom/customcd/files/proc
mkdir -p /mnt/custom/customcd/files/dev
mkdir -p /mnt/custom/customcd/files/sys
mount -o bind /proc /mnt/custom/customcd/files/proc
mount -o bind /dev /mnt/custom/customcd/files/dev
mount -o bind /dev/pts /mnt/custom/customcd/files/dev/pts
mount -o bind /sys /mnt/custom/customcd/files/sys
chroot /mnt/custom/customcd/files/ /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"

(the mount of /dev/pts above avoids a complaint of "out of ptys" during the biuld)

8) set MAKEOPTS to # cores + 1, I have 4 cores so


9) set up mirrors

mirrorselect -i -o >> /etc/portage/make.conf
cat /etc/portage/make.conf
(to make sure you did it right and didn't overwrite the makefile with just the mirrors!)

10) change the portage config file layout for crossdev which wants these files to change to directories
with the current file contents in the same file name in the direcory like this:

cd /etc/portage
mv package.keywords keywords
mv package.mask mask
mv package.unmask unmask
mv package.use use
mkdir package.keywords
mv keywords package.keywords
mkdir package.mask
mv mask package.mask
mkdir package.unmask
mv unmask package.unmask
mkdir package.use
mv use package.use

11) install a portage snapshot

cd /etc/portage/package.keywords
ls -a

(look over ._cfg* files and if they look ok, move them in place of the indicated files
(2 in my case) to keep emerge happy. Thid also verifies portage has accepted your directory
change as it has put the ._cfg file in the correct place!)

diff keywords ._cfg0000_keywords (then if the change looks reasonable):
mv ._cfg0000_keywords keywords

cd ../package.mask
ls -a
diff mask package.mask
mv ._cfg0001_package.mask package.mask

cd ../package.unmask
ls -a

cd ../package.use
ls -a
(these 2 didn't have ._cfg files in my case!)

12) set up the cross compile environment (assuming you need a 64 bit kernel as I do)

emerge crossdev
vi /root/sysresccd-pkg.txt

(to get the host system package list to select package versions for the cross tool chain!
the example below is for a 4.2.0 CD so your versions may be different!)


crossdev --target x86_64-pc-linux-gnu --ov-output /usr/local/portage --h 3.10 --b 2.23.2 --g 4.4.7 --l 2.15-r3

(Create the cross compile tool chain (the missing step!) The numbers are the versions of the packages
on the CD from the list above so the cross compiler is using the same versions as the CD. Check that
the 4 lines after ABIs: amd64 match the name and version numbers listed above!)

13) save a copy of the standard rescueCD config file for later.

cat /proc/config.gz | gzip -d > /mnt/custom/usr/src/kern_config.4.2.0

14) save a copy of initramfs from the 4.2.0 CD for later too

mkdir /mnt/custom/usr
mkdir /mnt/custom/usr/src
mkdir /mnt/custom/usr/src/initramfs
cd /mnt/custom/usr/src/initramfs
cat /livemnt/boot/isolinux/initram.igz | xz -d | cpio -id

15) cut a custom CD of your changes and/or ust partimage to do a backup of /dev/sda4!

vi /mnt/custom/customcd/files/root/.config/xfce4/helpers.rc

change TerminalEmulator=Terminal to


(to get rid of the annoying select your terminal emulator bug in the xfce4 desktop)
and save the file

/usr/sbin/sysresccd-custom squashfs

/usr/sbin/sysresccd-custom isogen my_srcd

change any boot options you want (such as a default keymap)

burn it to a DVD (its to big for a CD!)

16) rename the cross compile build in case you need it again

mv /mnt/custom/customcd /mnt/custom/customcd_crosscompiler

17) extract the files from the stock CD in to /mnt/custom/customcd to use to build a CD with the new
kernel later!

/usr/sbin/sysresccd-custom extract

18) unmount the /mnt/custom disk and reboot with the just created DVD to get in to a system with the
cross compiler enabled

19) mount the build volume and create a kernel source directory and mount it

mount /dev/sda4 /mnt/custom
mkdir /mnt/custom/usr
mkdir /mnt/custom/usr/src
mount -o bind /mnt/custom/usr/src /usr/src
cd /usr/src

20) create the cross comiler shell script

vi xkmake

exec make ARCH="x86_64" CROSS_COMPILE="x86_64-pc-linux-gnu-" INSTALL_MOD_PATH="/usr/src/x86_64" "[email protected]"

and save it then add /usr/src to the path so it will be found later.

chmod +x /usr/src/xkmake
export PATH="$PATH:/usr/src"

21) download the kernel patches first (remembering to replace the 4.2.0 below with the version of the
CD you are using!)

cd /usr/src
wget -r -l1 -A xz --no-directories

22) figure out what kernel source you want

ls /usr/src


indicates I need the 3.10 kernel sources so

wget -c ... .10.tar.xz

tar xfp linux-3.10.tar.xz

cd /usr/src/linux-3.10

xzcat ../std-sources-3.10-01-01-stable-310.35.patch.xz | patch -p1

xzcat ../std-sources-3.10-02-fc18.patch.xz | patch -p1

xzcat ../std-sources-3.10-03-aufs.patch.xz | patch -p1

xzcat ../std-sources-3.10-04-reiser4.patch.xz | patch -p1

23) config the kernel start with the current config from the CD

cd /usr/src/linux-3.10

cp /mnt/custom/usr/src/kern_config.4.2.0 > .config

(note the current DVD has a wrong config file for the standard CD on it!)

xkmake menuconfig

(the config needs to run in the cross devel environment too!)

step down to general setup and press enter

step down to Initramfs source file(s) and press enter

backspace to remeove the file name /var/tmp/genkernel/initramfs-3.10.35-std420-amd64.cpio then press OK to save it

you should now see () as the file name

hit esc twice until you are at the top level then save the config

24) build the kernel (note since I only wanted a 64 bit kernel I only built it)

xkmake && xkmake modules && xkmake modules_install

this leaves the new kernel in /usr/src/linux-3.10/arch/boot/bzImage
and the modules in /usr/src/x86_64/lib (from the xkmake script) presumably ready to install.

Hopefully this will be usefull to someone, if not it was certainly educational!

Peter Van Epp

Post Reply