- Ubuntu Wiki
- Obtaining the source for an Ubuntu release
- Obtaining the kernel sources for an Ubuntu release using apt-get
- Obtaining the kernel sources for an Ubuntu release using git
- Obtaining a copy
- How to View and Browse the Linux Kernel Source?
- What Is the Linux Kernel and How To Browse It
- The Linux Kernel Structure
- Viewing and Browsing the Linux Kernel Source Code
- Conclusion
- Saved searches
- Use saved searches to filter your results more quickly
- License
- torvalds/linux
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README
- About
Ubuntu Wiki
The kernel source for the Ubuntu kernel is based very closely on the upstream mainline kernel tree maintained by Linus. The Ubuntu-ness of this kernel is maintained as a git branch against the Linus tree.
Obtaining the source for an Ubuntu release
There are a number of different ways of getting the kernel sources. The two main ways will be documented here.
If you have installed a version of Ubuntu and you want to make changes to the kernel that is installed on your system, use the apt-get method (described below) to obtain the sources.
However, if you wish to get the most up to date sources for the Ubuntu release you are running and make changes to that, use the git method (described below) to obtain the sources.
Obtaining the kernel sources for an Ubuntu release using apt-get
apt-get source linux-image-unsigned-$(uname -r)
apt-get source linux-image-$(uname -r)
Obtaining the kernel sources for an Ubuntu release using git
The source for each release is maintained in its own git repository on Launchpad.
git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source//+git/
git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/cosmic
groovy | git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/groovy |
focal | git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/focal |
bionic | git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/bionic |
Replace your intended OS series in the above, and pull the source for the kernels you need.
The distro kernel is always on the master branch in these repositories. Each release also has a master-next branch containing the commits that will go onto the master branch and become the next release for that release.
A number of releases also have other source packages which represent other related but divergent kernels for other purposes. For example, there is a specialized AWS kernel available in the linux-aws source package. (Previously these sorts of things were done in Topic Branches and some older kernels and projects still use them.)
Obtaining a copy
To obtain a local copy you can simply git clone the repository for the release you are interested. The git command is part of the git package.
git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/bionic
git clone git://kernel.ubuntu.com/ubuntu/linux.git git clone --reference linux git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/groovy
In each case you will end up with a new directory ubuntu- containing the source and the full history which can be manipulated using the git command from within each directory.
$ git tag -l Ubuntu-* Ubuntu-5.4.0-47.51 Ubuntu-5.4.0-48.52 Ubuntu-5.4.0-49.53 Ubuntu-5.4.0-51.56 Ubuntu-5.4.0-52.57 $
git checkout -b temp Ubuntu-5.4.0-52.57
You may then manipulate the release - for example, by adding new commits.
Kernel/SourceCode (последним исправлял пользователь 85-210-146-14 2010-06-21 08:20:10)
The material on this wiki is available under a free license, see Copyright / License for details.
How to View and Browse the Linux Kernel Source?
This article briefly explains the Linux kernel is and how to browse its source code.
This tutorial is optimized for inexperienced Linux users and programmers who want to read the kernel source code or become Linux kernel developers. The Linux kernel is universal; therefore, the present document is useful for all Linux distributions.
By reading this article, you will understand what the kernel is, how it is structured and how to browse through its components. This article was initially written in 2019 and updated in 2022.
What Is the Linux Kernel and How To Browse It
The Linux kernel is the main component allowing interaction between the software and the hardware with the help of device drivers. You can think about the Linux kernel as a translator allowing communication between programs, the hardware, and the user interface.
Learning how to browse the Linux kernel is the first step for any programmer who wants to become a kernel developer. It is also useful for programmers or users who want to read its source code or modify it.
The Linux Kernel Structure
The Linux kernel is structured with directories and subdirectories known as “kernel tree”, users can browse to access specific sections of the whole code. This allows users and developers to focus on specific parts of the code.
Except for the Slackware Linux distribution, whose kernel is maintained by a single person, the rest of the Linux distributions’ huge developers’ community divide tasks based on the kernel tree. In contrast, several developers focus on drivers, others focus on security, and others on virtualization.
The kernel source tree is the following structure described through which users can browse the source code:
Viewing and Browsing the Linux Kernel Source Code
Usually, when we install Linux, we don’t include the source code. We can install Linux and keep the source code in our system. But most users discard it to download a smaller ISO image. After all, you can download the source code later if you need it.
If the kernel source code is present in your system, you can find it under the /usr/src/linux- directory, where must be replaced with the source code kernel version you are dealing with.
You also can find the last kernel source code at https://github.com/torvalds/linux.
As you can see in the previous screenshot or at the provided URL, within the source code tree, we can find the following main directories and files:
- arch: This directory contains source codes for different system architectures supported by the Linux kernel.
- block: The block I/O layer directory contains code for the management of block devices (such as hard disks, DVDs, floppy disks, etc.) and their requests.
- certs: The certs directory contains certificates and signs files to allow module signatures for the kernel to load signed modules. This can be useful to prevent malicious code from running within kernel modules like rootkits.
- COPYING: This file has information about licenses for the source code
- CREDITS: A partial listing of people who have contributed to the linux kernel source code
- Crypto: This directory contains cryptographic ciphers, which handle cryptographic and compression tasks.
- Documentation: As its name suggests, this directory includes all documentation about all kernel components.
- drivers: The drivers directory contains source code for device drivers to support hardware. Inside this directory, you’ll find subdirectories for each hardware, such as video, Bluetooth, etc. (any supported hardware).
- Fs: This directory contains sources for file systems, including virtual file systems, plus read and write file systems.
- include: This directory contains C headers for kernel files, such as functions to compile code.
- init: The init directory contains source code related to the boot process and the initialization of the Linux kernel. The source code is stored in a file named mainc.c within the /init directory. The code initializes the kernel and some initial processes.
- ipc: Inter-Process Communication, such as signals and pipes.
- Kbuild: The Kbuild file indicates object files for vmlinuz.
- Kconfig: The Kconfig file is used to disable or enable kernel features. Users deal with running the “make menuconfig” command.
- kernel: The kernel directory includes core subsystems, such as scheduler signal handling code.
- lib: This directory includes library routines, common string operations, hardware-dependent operations, debugging routines, and command-line parsing code.
- LICENSES: It contains the licenses to be applied to the kernel source and individual source files, which may have different licenses. Inside this directory, you will find four main subdirectories containing supported licenses like LGPL-X, Apache license, etc.
- MANTAINERS: The MAINTAINERS file shows the kernel maintainers’ list and instructions to submit kernel changes.
- Makefile: This file reads the .config file and builds modules and vmlinux.
- mm: The Linux kernel manages hardware and virtual memory (swap). This is the directory where the source code for memory management is stored.
- net: The net directory contains the network stack. Here, you can find code related to communication protocols, such as IP, TCP, and UP.
- README: The README file refers to guides for kernel developers in the Documentation directory previously described.
- Samples: The samples directory includes kernel and configuration files sample code.
- scripts: Here are stored the necessary scripts to build the Linux kernel.
- security: The security subdirectory contains the Security-Enhanced Linux (SELinux) security framework.
- sound: Here, you can find the sound subsystem, including sound drivers, driver architectures, and code related to sound, such as ALSA.
- tools: Here are tools for compressed kernel development, such as ACPI, cgroup, USB testing tools, vhost test module, GPIO, IIO and SPI tools, and Inter energy policy tool.
- usr: here, usr stores the initramfs, which roots the filesystem and init in the kernel memory cache. Code included allows you to execute code in user space in the boot process when the kernel isn’t fully loaded.
- virt: The virtualization directory contains the KVM (Kernel Virtual Machine) module for hypervisors, including architectures.
These are all top files and directories included in the main kernel source directory. You can browse each section depending on your needs. Once you understand the purpose of all files and directories listed above, subdirectories are pretty intuitive.
Conclusion
As you can see, this article was written for novel and medium users to understand the basics of the Linux kernel. Yet, some knowledge on development under Linux, hardware, and operating system characteristics is necessary for practical use. The previous lecture is excellent as an introduction to the Linux kernel structure and Linux distribution. Keep in mind that the Linux kernel evolves periodically. That’s why we keep the previously described content up-to-date.
We hope you found this article useful. Keep reading LinuxHint for more Linux professional articles.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
License
torvalds/linux
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
…inux/kernel/git/xiang/erofs Pull erofs fixes from Gao Xiang: "Three patches address regressions related to post-EOF unexpected behaviors and fsdax unavailability of chunk-based regular files. The other two patches mainly get rid of kmap_atomic() and simplify z_erofs_transform_plain(). - Fix two unexpected loop cases when reading beyond EOF - Fix fsdax unavailability for chunk-based regular files - Get rid of the remaining kmap_atomic() - Minor cleanups" * tag 'erofs-for-6.5-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs: erofs: fix fsdax unavailability for chunk-based regular files erofs: avoid infinite loop in z_erofs_do_read_page() when reading beyond EOF erofs: avoid useless loops in z_erofs_pcluster_readmore() when reading beyond EOF erofs: simplify z_erofs_transform_plain() erofs: get rid of the remaining kmap_atomic()
Git stats
Files
Failed to load latest commit information.
README
Linux kernel ============ There are several guides for kernel developers and users. These guides can be rendered in a number of formats, like HTML and PDF. Please read Documentation/admin-guide/README.rst first. In order to build the documentation, use ``make htmldocs`` or ``make pdfdocs``. The formatted documentation can also be read online at: https://www.kernel.org/doc/html/latest/ There are various text files in the Documentation/ subdirectory, several of them using the Restructured Text markup notation. Please read the Documentation/process/changes.rst file, as it contains the requirements for building and running the kernel, and information about the problems which may result by upgrading your kernel.