0

I have installed ubuntu 20.04 on a qemu arm64 virtual machine. This is based on qemu's arm64 'virt' machine and I added a peripheral in the virtual machine. Now to test device driver, I need to build kernel module and I have to do it on my x86_64 ubuntu 20.04 machine.
Inside the VM, the uname -r command gives me 5.4.0-77-generic. I learned that I need the kernel source for this version(or is only the kernel header enough? this says I need kernel source.) . I have had trouble downloading a specific kernel version in the past and now I'm not sure how I should get this version.
From https://launchpad.net/ubuntu/focal/+source/linux-signed I can see some 5.4.0-77.86 versions under security and main but I'm not sure how these versions are different from 5.4.0-77-generic. Please anyone tell me how I can get this 5.4.0-77-generic kernel version source. Step by step instruction will be appreciated but any comment is welcome. Thanks! (The kernel.org site shows only some selected or recent versions.)

ADD :
After apt-cache search 5.4.0 I tried sudo apt install linux-cloud-tools-5.4.0-77-generic and it installs

/. /usr /usr/lib /usr/lib/linux-tools /usr/lib/linux-tools/5.4.0-77-generic /usr/share /usr/share/doc /usr/share/doc/linux-cloud-tools-5.4.0-77-generic /usr/share/doc/linux-cloud-tools-5.4.0-77-generic/copyright /usr/lib/linux-tools/5.4.0-77-generic/hv_fcopy_daemon /usr/lib/linux-tools/5.4.0-77-generic/hv_kvp_daemon /usr/lib/linux-tools/5.4.0-77-generic/hv_vss_daemon /usr/lib/linux-tools/5.4.0-77-generic/lsvmbus /usr/share/doc/linux-cloud-tools-5.4.0-77-generic/changelog.Debian.gz 

I don't think this contains the kernel source.

1 Answer 1

1

To build a standalone kernel driver, you only need your kernel's header. It can be installed throught the linux-headers-5.4.0-77-generic package. Don't mind about what is on repository, just:

  1. Make sure your package database is up-to-date by running as root apt update
  2. Install the required package with, still as root, apt install linux-headers-5.4.0-77-generic.

Usually, on ubuntu based distros, you'll have:

  • linux-image-<version> : The kernel by itself.
  • linux-headers-<version> : Kernel's header.
  • linux-source-<version> : Kernel's whole sources.
6
  • Ah, thanks for the very succinct and clear answer! Commented Jul 13, 2021 at 13:14
  • But how come in my ubuntu 20.04 machine, I see linux-headers-5.4.0-77-generic and linux-image-5.4.0-77-generic for apt install candidates and not linux-source-5.4.0-77-generic? I see a candidate linux-source-5.4.0 - Linux kernel source for version 5.4.0 with Ubuntu patches which is the only source containing 5.4.0 pattern. (I understand I don't need the source). Commented Jul 13, 2021 at 13:22
  • I can't tell why the sources don't follow the same naming convention, nevertheless, linux-source-5.4.0 actually fetch 5.4.0.77 sources as you can see there: packages.ubuntu.com/focal/linux-source-5.4.0 Commented Jul 13, 2021 at 13:27
  • Oh, thanks so much again. I learned also that I have to check the package info at least :). Commented Jul 13, 2021 at 15:21
  • After installing the headers for 5.4, how do I boot into it? Commented Sep 23, 2021 at 3:58

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.