Skip to content

Instantly share code, notes, and snippets.

@franga2000
Last active January 7, 2024 08:39
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save franga2000/a07342b985a7c167668f to your computer and use it in GitHub Desktop.
Save franga2000/a07342b985a7c167668f to your computer and use it in GitHub Desktop.
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