Skip to content

Instantly share code, notes, and snippets.

@katsel
Last active November 7, 2016 13:31
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save katsel/8ef5d32c0ffa2d026ad05e78b995903c to your computer and use it in GitHub Desktop.
How to compile a linux kernel with grsec and custom kernel configuration on Arch Linux.

How to compile a linux kernel with grsec and custom kernel configuration on Arch Linux

  • Download the latest sources via the Arch Built System tool abs:
sudo abs community/linux-grsec

The default abs directory is /var/abs/, so the linux-grsec build files will be located in /var/abs/community/linux-grsec/.

I build kernel things in my home directory, so I change to that directory:

cd ~/src/abs/
  • Copy the abs directory to the current working directory:
cp -R /var/abs/community/linux-grsec/ .
cd linux-grsec/
  • Open the PKGBUILD file with your favourite editor.

    • Replace pkgbase=linux-grsec with pkgbase=linux-grsec-custom.
    • Scroll down to the section #load configuration and uncomment your favourite config tool. I like make nconfig.
  • Save the file and exit your editor.

  • Rename the .install file to match the name specified in PKGBUILD:

mv linux-grsec.install linux-grsec-custom.install
  • Start the makepkg process:
MAKEFLAGS="-j$(nproc)" makepkg -s

The -j flag specifies the number of jobs to be run simultaneously my make. We set it to $(nproc) - the number of processor cores on our machine. Using multiple cores speeds up the compilation considerably.

Once makepkg has downloaded the kernel sources and patches, you will see the kernel configuration menu pop up in your terminal. Now you can either find and set kernel options by yourself (view a list of grsec config options here), or provide an existing config file.

For example, use the following command to write your current .config to a file:

sudo zcat /proc/config.gz > current.config

(You may need to move the file into the src/linux-*/ subdirectory so your config editor can find it.)

  • When you're done setting kernel options, exit the configuration menu and watch the kernel compile. That's going to take a while.

Once compilation is finished, you will find that makepkg has written 3 files to your current directory:

linux-grsec-custom-*.pkg.tar
linux-grsec-custom-docs-*.pkg.tar
linux-grsec-custom-headers-*.pkg.tar
  • Install them with sudo pacman -U linux-grsec-custom-*.pkg.tar and you're done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment