Linux kernel and driver development training
Practical Labs
https://bootlin.com
May 04, 2023
Linux kernel and driver development training
About this document
Updates to this document can be ound on https://bootlin.com/doc/training/linux-kernel.
This document was generated rom LaTeX sources ound on https://github.com/bootlin/
training-materials.
More details about our training sessions can be ound on https://bootlin.com/training.
Copying this document
© 2004-2023, Bootlin, https://bootlin.com.
This document is released under the terms o the Creative Commons CC BY-SA
3.0 license . This means that you are ree to download, distribute and even modiy
it, under certain conditions.
Corrections, suggestions, contributions and translations are welcome!
2 © 2004-2023 Bootlin, CC BY-SA license
Linux kernel and driver development training
Training setup
Download fles and directories used in practical labs
Install lab data
For the dierent labs in this course, your instructor has prepared a set o data (kernel images,
kernel congurations, root lesystems and more). Download and extract its tarball rom a
terminal:
$ cd
$ wget https://bootlin.com/doc/training/sessions/online.linux-kernel.sep2023/\
linux-kernel-labs.tar.xz
$ tar xvf linux-kernel-labs.tar.xz
Lab data are now available in an linux-kernel-labs directory in your home directory. This
directory contains directories and les used in the various practical labs. It will also be used as
working space, in particular to keep generated les separate when needed.
Update your distribution
To avoid any issue installing packages during the practical labs, you should apply the latest
updates to the packages in your distro:
$ sudo apt update
$ sudo apt dist-upgrade
You are now ready to start the real practical labs!
Install extra packages
Feel ree to install other packages you may need or your development environment. In particular,
we recommend to install your avorite text editor and congure it to your taste. The avorite text
editors o embedded Linux developers are o course Vim and Emacs, but there are also plenty
o other possibilities, such as Visual Studio Code1 , GEdit, Qt Creator, CodeBlocks, Geany, etc.
It is worth mentioning that by deault, Ubuntu comes with a very limited version o the vi
editor. So i you would like to use vi, we recommend to use the more eatureul version by
installing the vim package.
More guidelines
Can be useul throughout any o the labs
• Read instructions and tips careully. Lots o people make mistakes or waste time because
they missed an explanation or a guideline.
1 This tool rom Microsot is Open Source! To try it on Ubuntu: sudo snap install code --classic
© 2004-2023 Bootlin, CC BY-SA license 3
Linux kernel and driver development training
• Always read error messages careully, in particular the rst one which is issued. Some
people stumble on very simple errors just because they specied a wrong le path and
didn’t pay enough attention to the corresponding error message.
• Never stay stuck with a strange problem more than 5 minutes. Show your problem to
your colleagues or to the instructor.
• You should only use the root user or operations that require super-user privileges, such
as: mounting a le system, loading a kernel module, changing le ownership, conguring
the network. Most regular tasks (such as downloading, extracting sources, compiling...)
can be done as a regular user.
• I you ran commands rom a root shell by mistake, your regular user may no longer be
able to handle the corresponding generated les. In this case, use the chown -R command
to give the new les back to your regular user.
Example: $ sudo chown -R myuser.myuser linux/
4 © 2004-2023 Bootlin, CC BY-SA license
Linux kernel and driver development training
Downloading kernel source code
Get your own copy o the mainline Linux kernel source tree
Setup
Create the $HOME/linux-kernel-labs/src directory.
Installing git packages
First, let’s install sotware packages that we will need throughout the practical labs:
sudo apt install git gitk git-email
Git confguration
Ater installing git on a new machine, the rst thing to do is to let git know about your name
and e-mail address:
git config --global user.name 'My Name'
git config --global user.email me@mydomain.net
Such inormation will be stored in commits. It is important to congure it properly when the
time comes to generate and send patches, in particular.
It can also be particularly useul to display line numbers when using the git grep command.
This can be enabled by deault with the ollowing conguration:
git config --global grep.lineNumber true
Cloning the mainline Linux tree
To begin working with the Linux kernel sources, we need to clone its reerence git tree, the one
managed by Linus Torvalds.
However, this requires downloading more than 2.7 GB o data. I you are running this command
rom home, or i you have very ast access to the Internet at work (and i you are not 256
participants in the training room), you can do it directly by connecting to https://git.kernel.
org:
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux
cd linux
I Internet access is not ast enough and i multiple people have to share it, your instructor will
give you a USB fash drive with a tar.gz archive o a recently cloned Linux source tree.
You will just have to extract this archive in the current directory, and then pull the most recent
changes over the network:
tar xf linux-git.tar.gz
cd linux
© 2004-2023 Bootlin, CC BY-SA license 5