2 minute read

Hi, this post is a follow-up to another post, where I needed a specific version of Linux header.

Read that post here, How to Configure a Raspberry Pi as an OpenFlow Switch: Steps, Issues, and Solutions

If we search for linux headers using the following command:

$ apt search linux-headers

we see, there is nothing less than 5.10+ version. However, I wanted to install version 4.9.

In this post, I will go through the steps to install a specific linux header in a Raspberry Pi.

  1. Download the source code for the kernel version you want to install. You can find the source code at https://github.com/raspberrypi/linux. You need to select 4.9 from the branch and then download zip file.
  2. Extract the source code to the /usr/src directory

     $ sudo cp linux-rpi-4.9.y-stable.zip /usr/src/
     $ cd /usr/src/
    
     $ sudo unzip linux-rpi-4.9.y-stable.zip
    
  3. Change to the extracted source code directory
     $ cd linux-rpi-4.9.y-stable/
    
  4. Check bcmxxxx_deconfig version, check the xxxx part
     $ ls arch/arm/configs/
    

    I got 2709

     $ sudo make bcm2709_defconfig
    
  5. Next we need to create zImage
     $ sudo make clean
     $ sudo make mrproper
     $ sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig
     $ sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage
    

    After executing the last command we can get a error like

     usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x10): multiple definition of 'yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here
    

    we need to edit the scripts/dtc/dtc-lexer-lex.c file in that case, find the line ‘YYLTYPE yylloc’ and change it to ‘extern YYLTYPE yylloc’. I found the solution here.

    Now, let’s run the command again. This will take a while (hours!). You can do other things in the meantime.

  6. If the build process completes successfully this time, the zImage file should be in the arch/arm/boot folder. Copy the “zImage” file to the “/boot” directory on your Raspberry Pi’s SD card.
     $ sudo cp arch/arm/boot/zImage /boot
    
  7. Configure the kernel using the existing configuration file (.config)

     $ sudo make oldconfig
    
  8. Compile the kernel
     $ sudo make -j$(nproc)
    

    This also takes some time.

  9. Install the kernel modules
     $ sudo make modules_install
    
  10. Install the kernel
    $ sudo make install
    
  11. Reboot the system to start using the new kernel.

That’s all!

You can also read my other posts related to Raspberry Pi:

Leave a comment