- How to create a kernel source tree?
- 3 Answers 3
- Is there a way to process the linux source tree using the config file
- How to Install Sourcetree on Ubuntu 22.04 or 20.04 Linux
- Prerequisites
- Step 1: Start with a System update
- Step 2: Install Wine on Linux
- Step 3: Download Sourcetree Package
- Step 4: Use wine and run SourceTree
- Step 5: Installing SourceTree on Ubuntu
- User Interface
How to create a kernel source tree?
I am reading a book on creating drivers on Linux, I do not have too much experience with Linux, I have installed a quite a few distros before but I have always used windows as my main operating system. I know some C , but I am mainly a C# programmer. I wish to learn (for fun) driver programming, and hope it will teach me some things about Linux and «get into it». My first hurdle is to find a distro with a standard 2.6.x kernel. I tried to find one but they are all past 3.x now. Any one know of a suitable one for this kind of task? Also the book says I should get a standard kernel from kernel.org and build a source tree. I have no idea what that means. This is the book: http://oreilly.com/openbook/linuxdrive3/book/
AFAIK building means compiling in this context. Once you have your kernel unpacked look into README , INSTALL etc. docs.
Questions like this one come up regularly and we should have a canonical version, so I wrote one: unix.stackexchange.com/questions/115620/…
3 Answers 3
You know of kernel.org , and this is where you can get vanilla kernels from old or new. For the newest kernels you can also use git.
Once you have a kernel, to create a «source tree», you just unpack it. For example, if you downloaded a .bz2 archive, you could unpack it with the command tar -jxvf .bz2 . Traditionally this tree is located in /usr/src and the symlink /usr/src/linux is made to point at the specific kernel directory you are using.
Once you have unpacked the source tree, to build it you need to first configure it e.g. make menuconfig (ncurses based) or make xconfig (X based). There are a few other config make targets if you are migrating a .config from a different kernel version. Finally, to build the kernel and its modules, use make . To install and boot the kernel use make modules_install for the modules and copy arch//boot/bzImage to wherever your bootloader expects kernels to be and configure it to boot that kernel. You will need to boot into the kernel if you expect to load any modules you build against it.
With that said, if you just want to experiment with building modules, just grab the source from your current distro kernel (there will be a package) and build modules against that kernel rather than going through the above process. It’s not hard, but if you are new to the kernel it may be a bit overwhelming.
Is there a way to process the linux source tree using the config file
I am wondering if there is a way to use my .config file for building the Linux kernel and create another source tree with only the code which will actually be used in the build. For instance, if I choose not to include a certain driver, the code for that driver will be left out and all #ifdef CONFIG_
What you want to do is technically possible with a bunch of scripts / make commands, but I don’t know if there readily exists any tool/build option to do it easily.
The generic tool for that is unifdef, but of course you’ll need to invoke it properly so that it handles your .config file and produces another tree. Also take a look at the unifdef.c file in the Linux Kernel tree.
Not really — but you can parse the build log and find all files actually compiled. (Or, hook the compiler command and log the input files). Then remove all the rest from the code base. Unifdef only removes parts of files based on its’ knowledge of defined macros, it is probably not what you want.
How to Install Sourcetree on Ubuntu 22.04 or 20.04 Linux
Wine is the solution that we can use to install the SourceTree software on Linux systems including Ubuntu. Here is the tutorial to learn the steps we need to follow to get this free Git Client software.
Sourcetree is a popular but free client software to manage repositories based on Git and Mercurial. However, it is not available for Linux and works only for Windows and Mac.
The graphical interface of this client software is designed to simplify the Git and Mercurial version control systems. It is the GUI and clean navigation that makes SourceTree easier for software developers to manage their source code repositories and collaborate with their development teams.
Apart from this other common tasks can be performed using the SourceTress such as creating repositories, pushing and pulling changes, and working with branches.
Prerequisites
Before you start the installation process, you will need to make sure that you have the following prerequisites:
Note: This tutorial is just for educational purpose and because of Wine we cannot assure that the software will work on Linux as it is natively for Windows or macOS
Step 1: Start with a System update
We should first run the system update command on our Linux to refresh the package manager index cache. So, open your command terminal and run the given command:
Step 2: Install Wine on Linux
As we know SourceTree is not available for Linux, therefore to install it we are using Wine on Linux. As per the distro, the command to install it will be different. Here we are using Ubuntu 22.04, hence follow the tutorial we already have done for it: Steps to install Wine on Ubuntu 22.04 whereas Ubuntu 20.04 can use this link.
Yet, those who want to go through the commands quickly, here are they:
sudo dpkg --add-architecture i386
wget -nc https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources
sudo mv winehq-jammy.sources /etc/apt/sources.list.d/
sudo mkdir -pm755 /etc/apt/keyrings
sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
wget -O - https://dl.winehq.org/wine-builds/winehq.key | sudo apt-key add -
sudo add-apt-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ focal main'
sudo apt install --install-recommends winehq-staging
Step 3: Download Sourcetree Package
The SoruceTree is not available as the Debian binary, so visit the official website of this Git Tool and download the Executable binary available for Windows.
Step 4: Use wine and run SourceTree
Once you have downloaded the file using the browser, it will be in the Downloads folder by default. Now, in your command terminal run the given command:
wine ~/Downloads/SourceTreeSetup-*.exe
Alternatively, you can graphically open the Downloads folder from the file manager and right-click on the SourceTreeSetup-*.exe file to select “Open with other Application” then Wine Windows Program Loader.
Step 5: Installing SourceTree on Ubuntu
- Next, you will see the Installation Wizard of SourceTree. Those who want to connect the BitBucket can do it here. Otherwise, just press the Skip button because we can do this later as well.
- SourceTree supports Gitand Mercurial, if you want to install any of them while installing the software, select the one and move forward. Learn – How to install Git on Almalinux or Rocky Linux 8
- The software will automatically pick the username, you can rename it.
- Once the installation is finished, you will see the SourceTree Desktop shortcut icon. Right-click it and select the “Allow Launching” option.
User Interface
Soon the user interface of the SourceTree will appear. You can start using it. However, you may face a crashing problem.