How to Upgrade to a New Linux Kernel Version on an SD Card

Beaglebone black board

In this article, we will show how to upgrade to a different linux kernel version on an SD card to boot a different linux kernel.

It's not a difficult process but it's not as easy as simply swapping out the linux kernel image.

You also need to make sure to build the linux kernel modules and install them in the root file system of the new linux kernel on the SD card.

Many times too, if you have a new linux kernel version, you want to swap out the device tree binary file as well.

So when you are trying to install a new linux kernel version on an external device such as an SD card, it is advisable to have the source code installed on your computer.

When you generate the appropriate files on your computer, you should have access to a variety of files including the linux kernel uImage file and the device tree binary file (dtb) of the target board. Later you should compile the modules and then install them in the /lib/modules/ directory within the root file system directory.

Other files, assuming the target board is the same, do not need to change, including the MLO file and the u-boot file. These are just second stage program loaders (MLO) and third stage program loaders (u-boot). These aren't related to the linux kernel versions themselves and, thus, can be kept the same as it was with the previous linux kernel version.

So let's start from the beginning.

Let's say you downloaded a linux kernel source code from your target board's official site and you did all the necessary builds in order to generate the uImage and the device tree binary file (dtb).

If you don't know how to do this, please refer to an article, which tells you step by step how you can generate all the necessary files needed to run a new linux kernel version.

After this, the next thing you have to do is build (or compile) the modules.

There is something in linux referred to as dynamically loadable kernel modules.

These are modules which are external to the linux kernel image (zImage or uImage), which are later compiled and added to the root file system. The reason these modules are external to the linux kernel image is to decrease the file size (memory) of the linux kernel image, or otherwise the file size would be excessively large.

You can check modules offered for the linux operating system when you run menuconfig for the linux kernel image you are using. Components labeled with an 'M' are dynamically loadable kernel modules. The components labeled with a * are going to be included directly into the zImage and uImage.

These modules, once compiled, must then be added to the /lib/modules/ directory of the root file system that you are utilizing.

So before you can install modules, you first must compile modules.

So you must compile your modules for your target.

In order to compile the dynamically loadable kernel modules on a beaglebone black board, we use the following line of code shown below.

This gives us the following output, which builds (or compiles) our modules.

Compiling dynamically loadable kernel modules for linux kernel source code

Once this is completed, the next step is we now install the modules. Installation is placing all the module files (.ko files) on our local computer.

By default, when we install modules on our local computer, they are placed within the /lib/modules/ directory.

We install the modules on our local computer using the following command below.

If the architecture for your target board is different than arm, you would specify this architecture.

After the installation process, you should see a directory representing the modules that have been installed in this /lib/modules/ directory.

This is shown below.

Contents of modules directory on local computer in a linux operating system

As you can see, as you work with modules, you may notice that you have several directories in this folder.

So the question may arise to, which module was just installed?

This can be found out in a few ways. You can manually go through each of the directories and check which was the most recent using the properties feature. Or you can go into the linux terminal and cd into the modules folder. Once you do this, then type in the command, ls -l, in order to see which module was created most recently. That is the module which you just installed.

Now that you've installed the module on your computer that you recently built, the next step is we have to transfer it to the /lib/modules/ directory in the root file system partition on our SD card.

The code to do this is shown below.

After you do this, there is one more code that needs to be run and that is the following shown below.

Once this is done, you should be able to go into the /lib/module/ directory and see the latest module that was recently installed on your local computer inside this directory.

You've now installed the appropriate module in the ROOTFS partition.

So we've now completed this step.

Remember, of course, you must swap out the uImage. Install the module directory, as we just did. And it's best to also swap out the device tree binary file for the appropriate device.

After these steps are done, you should have successfully upgraded your SD card to this latest linux kernel.

Now the only thing left is to place this SD card in the SD card adapter on your target board and attempt the booting process.

If it boots, then yhou know you've successfully upgraded to the new linux kernel on your SD card.

Keep in mind that there is one other way of doing this that could eliminate the step of having to download the modules first to your local computer and then copy it over. You could, in fact, install the module directory directly to the target board instead of the local computer.

For a beaglebone board, the code to do this would be the following shown below.

So this could eliminate the step of having it first download to your local computer and can download the module directly to the ROOTFS /lib/modules/ directory of your SD card.

So this jis how to upgrade to a new linux kernel version on an SD card.

So this is how to create a linux kernel module and run it on either the local host device or a target host device.

Related Resources

HTML Comment Box is loading comments...