Ubuntu Wiki
Git is the source code management tool used by the Linux kernel developer community. Ubuntu has adopted this tool for our own Linux kernel source code so that we can interact better with the community and the other kernel developers.
Installing GIT
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.
Maintaining local changes
During development, the kernel git repository is being constantly rebased against Linus' tree. IOW, Ubuntu specific changes are not being merged, but rather popped off, the tree updated to mainline, and then the Ubuntu specific changes reapplied; they are rebased. There are two ways to track the kernel git tree, depending on whether you have local changes or not:
git fetch git reset --hard origin/master
git fetch git rebase --onto origin/master origin/master@
Pushing changes to the main repo
Since the main repo is not publicly writable, the primary means for sending patches to the kernel team is using git format-patch. The output from this command can then be sent to the kernel-team mailing list.
Alternatively, if you have a publicly available git repository for which changes can be pulled from, you can use git request-pull to generate an email message to send to the kernel-team mailing list.
Using Commit templates
git commit -s -F debian/commit-templates/patch -e
UBUNTU: scsi: My cool change to the scsi subsystem UpstreamStatus: Merged with 2.6.15-rc3 My cool change to the scsi subsystem makes scsi transfers increase magically to 124GiB/sec. Signed-off-by: Joe Cool Hacker
Prefix | Meaning |
UBUNTU: SAUCE: | a kernel source modification which is specific to Ubuntu |
UBUNTU: [Config] | a change to the kernel configuration |
UBUNTU: | any other change to the debian packaging for the kernel |
upstream kernel patches |
Patch acceptance criteria
- /Documentation/SubmittingPatches
- /scripts/checkpatch.pl
- /scripts/cleanpatch
- /scripts/cleanfile
- /scripts/Lindent
If you are creating a new file, it is helpful to run it through cleanfile and/or Lindent before creating a patch
If you have generated a patch, it helps running it through checkpatch.pl and cleanpatch if necessary
Also, using the commit template described above is a good idea for Ubuntu-specific patches
[old] Developers with access to kernel.ubuntu.com
The kernel team has a git repo located on kernel.ubuntu.com (AKA zinc.ubuntu.com) in /srv/kernel.ubuntu.com/git/ubuntu.
You can, if you want, create a clone for yourself in your directory, and just have your changes pulled when ready.
git clone -l -n -s --bare /srv/kernel.ubuntu.com/git/ubuntu/ubuntu-jaunty.git vi ubuntu-jaunty.git/description ( give it a descriptive name ) mv ubuntu-jaunty.git/ /srv/kernel.ubuntu.com/git//my-git-tree.git
You can now push your changes to this tree via ssh. Note the -l -n -s options do a few special things, mainly making your repo share objects with ours (saves space).
cd /srv/kernel.ubuntu.com/git//my-git-tree.git git update-server-info mv hooks/post-update.sample hooks/post-update chmod +x hooks/post-update
chmod +x /srv/kernel.ubuntu.com/git//my-git-tree.git/hooks/post-commit
git clone git://kernel.ubuntu.com/ubuntu/ubuntu-jaunty.git my-tree git remote add zinc ssh://kernel.ubuntu.com/srv/kernel.ubuntu.com/git//my-git-tree.git git push zinc master
cd my-tree git fetch origin git rebase origin
This will keep your changes on top of the original tree (as opposed to being merged). This is also a good idea because during development (e.g. while following the upstream git repo), we frequently rebase to linux-2.6.git upstream, so the HEAD is not always suitable for pull/merge.
Kernel/Dev/KernelGitGuide (последним исправлял пользователь daxtens 2018-12-10 05:42:17)
The material on this wiki is available under a free license, see Copyright / License for details.
Use GIT for Linux Kernel Development
GIT is a free, open source distributed version control tool. It is easy to learn and is also fast, as most of the operations are performed locally. It has a very small footprint. Just to compare GIT with another SVN (Source Version Control) tool, refer to http://git-scm.com/about/small-and-fast.
GIT allows multiple local copies (branches), each totally different from the otherit allows the making of clones of the entire repository so each user will have a full backup of the main repository. Figure 1 gives one among the many pictorial representations of GIT. Developers can clone the main repository, maintain their own local copy (branch and branch1) and push the code changes (branch1) to the main repository. For more information on GIT, refer to http://git-scm.com/book.
Note: GIT is under development and hence changes are often pushed into GIT repositories. To get the latest GIT code, use the following command:
$git clone git://git.kernel.org/pub/scm/git/git.git
The kernel
The kernel is the lowest level program that manages communications between the software and hardware using IPC and system calls. It resides in the main memory (RAM), when any operating system is loaded in memory.
The kernel is mainly of two types – the micro kernel and the monolithic kernel. The Linux kernel is monolithic, as is depicted clearly in Figure 2.
Based on the above diagram, the kernel can be viewed as a resource manager; the managed resource could be a process, hardware, memory or storage devices. More details about the internals of the Linux kernel can be found at http://kernelnewbies.org/LinuxVersions and https://www.kernel.org/doc/Documentation/.
Linux kernel files and modules
In Ubuntu, kernel files are stored under the /boot/ directory (run ls /boot/ from the command prompt). Inside this directory, the kernel file will look something like this:
where A.B is 3.2, C is your version and D is a patch or fix.
Lets delve deeper into certain aspects depicted in Figure 3:
- Vmlinuz-3.2.0-29-generic: In vmlinuz, z indicates the compressed Linux kernel. With the development of virtual memory, the prefix vm was used to indicate that the kernel supports virtual memory.
- Initrd.img-3.2.0-29-generic: An initial ramdisk for your kernel.
- Config-3.2.0-29-generic: The config file is used to configure the kernel. We can configure, define options and determine which modules to load into the kernel image while compiling.
- System.map-3.2.0-29-generic: This is used for memory management before the kernel loads.
Kernel modules
The interesting thing about kernel modules is that they can be loaded or unloaded at runtime. These modules typically add functionality to the kernelfile systems, devices and system calls. They are located under /lib/modules with the extension .ko.
Setting up a development environment
Lets set up the host machine with Ubuntu 14.04. Building the Linux kernel requires a few tools like GIT, make, gcc and ctag/ncurser-dev. Run the following command:
Sudo apt-get install git-core gcc make libncurses5-dev exuberant-ctags
Once GIT is installed on the local machine (I am using Ubuntu), open a command prompt and issue the following commands to create an account:
git config --global user.name Vinay Patkar git config global user. Email Vinay_Patkar@dell.com
Lets set up our own local repository for the Linux kernel.
Note: 1. Multiple Linux kernel repositories exist online. Here, we pull Linus Torvalds Linux-2.6 GIT code — Git clone http://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
2. In case you are behind a proxy-server, set the proxy by running git config global https.proxy https://domain\usernmae:password@proxy:port.
Now you can see a directory named linux-2.6 in the current directory. Do a GIT pull to update your repository:
Note: Alternatively, you can clone the latest stable build as shown below:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git cd linux-2.6
Next, find the latest stable kernel tag by running the following code:
git tag -l | less
git checkout -b stable v3.9
Note: RC is the release candidate, and it is a functional but not stable build.
Once you have the latest kernel code pulled, create your own local branch using GIT. Make some changes to the code and to commit changes to the code, run git commit a.
Setting up the kernel configuration
Many kernel drivers can be turned on or off, or be built on modules. The .config file in the kernel source directory determines which drivers are built. When you download the source tree, it doesnt come with a .config file. You have several options for generating a .config file. The easiest is to duplicate your current config.
There are multiple files that start with config; find the file that is associated with your kernel by running uname a. Then run:
cp /boot/config-`uname -r`* .config or cp /boot/config-3.13.0-24-generic .config Make defconfigThis will take some time and if everything goes well, install the newly built kernel by running the following command:
Sudo make modules_install Sudo make installAt this point, you should have your own version of the kernel, so reboot the machine and log in as the super user (root) and check uname-a. It should list your own version of the Linux kernel (something like Linux Kernel 3.9.0rc9).