From the course: Linux Device Drivers: Reading, Writing, and Debugging
Getting Linux kernel source code - Linux Tutorial
From the course: Linux Device Drivers: Reading, Writing, and Debugging
Getting Linux kernel source code
- [Instructor] Let's talk about getting the source code for the Linux kernel, and even about configuring and building it a bit. If this is new to you, this will be quite valuable information. If it's not new to you, well, you can probably go through this pretty quickly. Maybe you'll pick up a thing or two though. So, our focus in the course is going to be of course, Linux device drivers. And what you need to build a driver is not the kernel source code per se. You need the headers for the kernel source code. And for distributions, those are often available as a package that you can install. But the kernel source itself can be valuable because it's all the code. It's example code. You can see how, perhaps, similar drivers are written and there's a lot of documentation separate from the source code. And of course, with the source code, you could build yourself a custom kernel and you can configure the kernel to say, provide extra debugging information that might be helpful during driver development. The official kernel source code is on kernel.org, and you can clone the latest tree with git if you want, or you can get a tarball of the various Linux kernel versions by going to the website. This is going to be pretty big. It's going to be several gig. And when you build it, it could take a while. So you want a decent system here with a fair amount of disk space available if you're going to be working with the kernel source. So installing the kernel header files is usually installing the appropriate package. And Ubuntu, it might be something like apt install build-essential. So you've got compilers and stuff. And the Linux headers-version of the kernel you have right now that back ticks with the uname when SRR gives you the kernel version you're running right now. On other sorts of distributions like Rocky, say, then the command would be dnf instead of apt. You can also potentially get the source package for your kernel. On Ubuntu, it might be apt source linux-image-unsigned- kernel version, or git clone the kernel tree, like for the noble release of Ubuntu. There's the big clone path. Also, Ubuntu does have a webpage about building your own kernel, so that would be a handy reference. For other versions of Linux besides Ubuntu, like Rocky, for example, then the commands could be different. Rocky would be a dnf download. Let's take a look at justthekernel.org website. So here we are. It's actually a mirror, mirrors.edge.kernel.org, and we're in the pub linuxkernelv6.x directory. And we can see lots of tarballs here. We've got different compressions, gz and xz, and we've got a sign file, lots of stuff. So you can pick the one you want and download it from your web browser if you want, besides using Wget and the other things that we talked about.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.