Skip to content

Instantly share code, notes, and snippets.

@franga2000
Last active February 20, 2022 13:26
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Compiling a custom Linux kernel from source

#Compiling a custom Linux kernel

# Install required tools
sudo apt-get install ncurses-dev
# Download Linux source
sudo apt-get install linux-source
cd /usr/src/
# Extract Linux source
tar xf linux-source-*.tar.xz
cd linux-source-*/
# Copy default config
cp /boot/config-* .config

This is where you should install any patches you want to add to the kernel

# Configure the kernel
# You can learn more about configuration at http://www.linux.org/threads/4274/
make menuconfig
# Build the kernel (This will take a LONG time)
make
# Build the kernel modules (This MIGHT take a long time)
make modules
# Install modules
make modules_install
# Install kernel
make install
@BrokenEyesCode
Copy link

What options do we select in menuconfig? Do we leave it as it is and build?

@Klubuntu
Copy link

Klubuntu commented Nov 26, 2021

Hi, im problem if compiling this code.

Old Problem Fixed

$ make
/bin/sh: ./scripts/pahole-flags.sh: Permission denied
/bin/sh: ./scripts/pahole-flags.sh: Permission denied
/bin/sh: ./scripts/pahole-flags.sh: Permission denied
/bin/sh: ./scripts/pahole-flags.sh: Permission denied
/bin/sh: ./scripts/pahole-flags.sh: Permission denied
/bin/sh: ./scripts/pahole-flags.sh: Permission denied
/bin/sh: ./scripts/pahole-flags.sh: Permission denied
/bin/sh: ./scripts/pahole-flags.sh: Permission denied
/bin/sh: ./scripts/pahole-flags.sh: Permission denied
/bin/sh: ./scripts/pahole-flags.sh: Permission denied
/bin/sh: ./scripts/pahole-flags.sh: Permission denied
/bin/sh: ./scripts/pahole-flags.sh: Permission denied
CC scripts / mod / empty.o
cc1: error: code model kernel does not support PIC mode
make [1]: *** [scripts / Makefile.build: 287: scripts / mod / empty.o] Error 1
make: *** [Makefile: 1196: prepare0] Error 2

New Problem:

$ make
  CC      scripts/mod/empty.o
cc1: error: code model kernel does not support PIC mode
make[1]: *** [scripts/Makefile.build:287: scripts/mod/empty.o] Error 1
make: *** [Makefile:1196: prepare0] Error 2

@franga2000
Copy link
Author

@Klubuntu your GCC has the PIE on by default - most distros don't do that.

Try editing the Makefile - find a line similar to this: EXTRA_CFLAGS += $(CFLAGS_EXTRA)

and edit it like so: EXTRA_CFLAGS += $(CFLAGS_EXTRA) -fno-pie.

Depending on the kernel version you're compiling that like might look a bit different - just search for CFLAGS_EXTRA.

@Klubuntu
Copy link

Klubuntu commented Nov 26, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment