Skip to content

Instantly share code, notes, and snippets.

@Avyd
Last active September 23, 2021 09:33
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Avyd/8191406 to your computer and use it in GitHub Desktop.
Save Avyd/8191406 to your computer and use it in GitHub Desktop.
Compile kernel to installable .deb package
#Install necessary things
apt-get update
apt-get install kernel-package libncurses5-dev fakeroot wget bzip2 build-essential -y
#Get the kernel
cd /usr/src
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.13.tar.xz
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.13.tar.sign
gpg --verify linux-3.13.tar.sign
tar xpvf linux-3.13.tar.xz
ln -s linux-3.13 hlinux
##Patch - optional
#cd /usr/src/linux
#bzip2 -dc /usr/src/patch-whatever.bz2 | patch -p1 --dry-run
#bzip2 -dc /usr/src/patch-whatever.bz2 | patch -p1
#Configure the kernel
cd /usr/src/linux
make clean && make mrproper
#Save the existing config
cp /boot/config-`uname -r` ./.config
make menuconfig
#Load alternative config file - .config
#Edit config and save
#Build the kernel
make-kpkg clean
fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers
make modules
make modules_install
#Install new kernel
cd /usr/src
#Check file names before running dpkg
ls -l
dpkg -i linux-image-<VERSION>-custom_<VERSION>-custom-10.00.Custom_i386.deb
dpkg -i linux-headers-<VERSION>-custom_<VERSION>-custom-10.00.Custom_i386.deb
#Test the kernel
shutdown -r now
uname -r
#Notes
#http://www.berkes.ca/guides/linux_kernel.html
#http://www.howtoforge.com/kernel_compilation_ubuntu
@ashsholley88
Copy link

Kinda, very new at this

@obeardly
Copy link

I just wanted to say thank you. I needed to roll a kernel today, and hadn't done that manually in over a decade. This was a huge help.

@rubo77
Copy link

rubo77 commented Mar 21, 2018

Thanks a lot. I used this and updated it to a 4.x kernel: https://gist.github.com/rubo77/cd1f8d2e3db4720b7a60aa666fd195d6

You had a typo i line 11: ln -s linux-3.13 hlinux should be linux whthout h. And you don't need to install 1GB recommended latex, so better use apt-get --no-install-recommends instead. I also made it more variable to change the kernel version in the script in only one place.

I also released it at unix.stackexchange.com

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