3

I'm trying to install a linux-Kernel version 4.9.228 in my ubuntu 20.04. The kernel compiled successfully, without any errors. I also executed the command:

sudo make modules_install install

When I rebooted my system, to check whether it made correct entry, I checked the files under the /boot/ directory:

  • System.map-4.9.228
  • vmlinuz-4.9.228
  • initrd.img-4.9.228
  • config-4.9.228

I don't know why but when I ran uname -r. It hasn't updated my version. It still says 5.4.0-37-generic.

Please guide me if I am missing something.

Note: The sole purpose of doing all this, is to learn how to add a system call and how to compile a kernel. I'm open to suggestions, if you got any. Thanks.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
Qasim Khan
  • 154
  • 10
  • 1
    Most likely, `make install` has made your **kernel available for boot**. So you just need to **boot your kernel** instead of other ones. You may do that manually, selecting your kernel every time you boot, or you may configure your bootloader (probably, grub), so your kernel will be booted by default. As far as I know, grub prefers to load the newest kernel. In your case the newest kernel is `5.4.0-37-generic`, so it is loaded by default. But, as I said above, you may change this setting. Google for "configure grub" or so. – Tsyvarev Jun 21 '20 at 08:41

1 Answers1

3

You might have successfully installed a different kernel version, but in order to boot into it, you need to tell the bootloader to do so.

I'm going to assume that you are using GRUB2 as bootloader, since it's standard on most distributions including Ubuntu. In order to boot the new kernel, you have multiple options.

Option 1

This is the safest and recommended option.

  1. Edit the GRUB configuration file /etc/default/grub (you need to be root, so use something like sudo vi or sudo nano) and make sure that you have GRUB_TIMEOUT=N where N is a number of seconds. If you don't, then just add it in a new line. You want N to be at least 5 or 10 so that you have time to select the correct kernel version when GRUB starts.

    Additionally, make sure that you do not have any of the following lines (you shouldn't have them, but if you do, remove or comment them):

    GRUB_DISABLE_RECOVERY="true"
    GRUB_DISABLE_SUBMENU=y
    GRUB_HIDDEN_TIMEOUT=N
    GRUB_TIMEOUT_STYLE=hidden
    
  2. Save the changes to /etc/default/grub and run sudo update-grub. This will detect currently installed kernels and add them to the bootable list when you start the computer and enter GRUB.

  3. Reboot your PC, when GRUB starts you will see a list of options. If you don't do anything, your default kernel will boot, otherwise you can use the arrow keys and the ENTER key to navigate to "Advanced options for Ubuntu", where you will find the list of available kernels and you will be able to select the one you prefer.

    It should look something like this:

    grub1

    grub2

Option 2

Use only as fallback if option 1 does not work (it should, but you never know). This is not as clean as option 1 because it changes the default kernel, and changes are also probably going to be overridden by an upgrade of your current kernel (which technically does exactly this to update the default version).

  1. Make the kernel you want the default one by changing the two symlinks /initrd.img and /vmilunuz to point to the right versions of the kernel and initrd image. This can be done either manually or through the linux-update-symlinks command.

    $ linux-version list --paths
      ... grab the correct VERSION and PATH ...
    
    $ sudo linux-update-symlinks install VERSION PATH
    
  2. Run sudo update-grub to let GRUB detect the changes.

  3. Reboot your PC.

Option 3

Manually boot into the kernel you want from the GRUB command line. This is an advanced option and I'm listing it only as a last resort, you should never need to do this unless you have completely broken your system configuration.

  1. Reboot the PC into GRUB, and as soon as you see it, press C to enter the GRUB command line.
  2. Follow this answer from now on.

In any case, remember that playing around with kernel development on your own machine is not a good idea if you are not sure what you are doing. I recommend you use a virtual machine to experiment with the kernel, that way if anything goes wrong you can just throw it away and create a new one.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
  • Just noting that invoking linux-update-symlinks with the "install" argument value writes only the symlinks corresponding to the VERSION/IMAGE-PATH arguments. While invoking it with the "upgrade" argument value writes those symlinks as well as the symlinks corresponding to the previous kernel version's files found in the /boot dir. Invoking it with the "remove" argument value removes the corresponding symlinks. – Matthew Jan 07 '23 at 21:56