- Don't follow this guide for compiling linux kernel, there are much better guides out there for that purpose (this is the one I followed). The guide exists to help you learn some new stuff which you didn't know before, and to improve your understanding of Linux a bit.
- My knowledge of Linux and operating systems, in general, is somewhat limited, and hence, some things might be wrong (or at least not perfectly correct).
- The main reason for writing this tutorial is because I had to submit a document showing what I did. It's not exactly related to hacking. It just gives you some insight into linux (which I perceive is helpful).
- Do everything on a virtual machine, and be prepared for the eventuality that you'll break your installation completely.
Linux Kernel
Running uname -r on your machine would show you what kernel version you're using. uname -a would give you some more details regarding that.
Every once in a while, a new stable kernel release is made available on kernel.org. At the time of writing this, the release was 4.9.8. At the same time, there is also the latest release candidate kernel, which is not of our interest, as it's bleeding edge (latest features are available in the kernel, but there could be bugs and compatibility issues), and hence not stable enough for our use.
I download the tar ball for the latest kernel (a compressed archive of ~100MB size, which becomes ~600 MB upon extraction). What we get upon extraction is the source files of your linux kernel. We need to compile this to get an object file which will run our OS. To get a feel for what this means, I have a little exercise for you-
Small (and optional) exercise
We will do the following-
- Make a folder, and move to that folder
- Write a small c++ hello world program
- Compile it, using make
- Run the compiled object file.
On the terminal, run the following-
Step 1:
mkdir testing
cd testingStep 2:
cat > code.cppPaste this into the terminal
#include <iostream>
int main(){
std::cout << "Hello World\n";
return 0;
}
After pasting this, press ctrl+d on your keyboard (ctrl+d = EOL = end of line).
If this doesn't work, just write the above code in your favourite text editor and save as code.cpp
Step 3:
make codeStep 4:
./codeNotice how we used the make command to compile our source code and get an executable. Also, notice how the make command itself executed this command for us-
g++ code.cpp -o codeIn our case, since there was only one source file, make knew what to do (just compile the single file). However, in case there are multiple source, make can't determine what to do.
For example, if you have 2 files, and the second one depends on the first one in some way. Then, you need the first one to be compiled before the second one. In case of the kernel, there are possibly millions of source code files, and how they get compiled is a very complex process.
If you navigate to the folder containing linux kernel (the folder where you extracted the tar ball), you'll get an idea of the sheer magnitude of complexity behind a kernel. For example, open the Makefile file in that folder in your favourite text and editor and see the contents of the folder. Makefile contains instructions which make (the command line tool we used earlier) uses to determine how to compile the source files in that directory (and subdirectories).
Some tools
Compiling our simple c++ program didn't need much, and your linux distribution (I'm using Ubuntu 16 for this tutorial) would come with the required tools pre-installed. However, compiling kernel needs some more stuff, and you'll need to install the required tools. For me, this command installed everything that was needed-
sudo apt-get install libncurses5-dev gcc make git exuberant-ctags bc libssl-devMany of these tools would actually be pre-installed, so downloading and installing this won't take too long.
(if you're not on Ubuntu/Kali, then refer to this guide, as it has instruction for Red Hat based and SUSE based systems as well)
Download kernel
In the guide that I followed, he suggested that I clone this repository-
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.gitAfter cloning the repo, I had to choose the latest stable kernel and then proceed further with it. This would be useful when you want to keep pulling updates and recompiling your kernel. However, for the purpose of this tutorial, let's ignore this possibility (because cloning the git repo took a lot of time and the downloaded file was huge and everything was taking forever).
Instead, we just download and extract the tarball (as discussed earlier in the Linux Kernel section).
Configuration
Here, we have two options.
- Use a default configuration
- Use the configuration of your current kernel (on which your OS is running right now).
As in downloading the kernel step, I tried both methods, and for me, the default one worked better. Anyways, for current configuration, run the following-
cp /boot/config-`uname -r`* .configThis copies the configuration for your current kernel to a file in the current folder. So, before running this command, navigate to the folder containing the extracted tarball. For me, it was /home/me/Download/linux-4.9.8
For default config (recommended), run
make defconfig
If you don't see a config file, don't worry. In linux, files/directories starting with . are hidden. On your terminal, type vi .config (replace vi with your favourite text editor) and you can see the config file.
Compiling
Similar to the way you compiled your c++ program, you can compile the kernel. In case of c++ program, we didn't have any Makefile, so we had to specify the name of the source file (make code), however, since we have a Makefile here, we can simply type make, and our Makefile and .config file (and probably many more files) will tell make what to do. Note that the config file contains the options which were chosen for your current kernel. However, on a later kernel, there might be some choices which weren't available in the the previous kernel (the one you're using). In that case, make will ask you what to do (you'll get to choose between option - yes and no, or options - 1,2,3,4,5,6, etc.). Pressing enter chooses the default option. Again, I suggest you use the default configuration file to avoid any issues.
To summarise, simply run this command-
makeIf you have multiple cores, then specify it as an argument (compilation will be faster). For example, if you have two cores, run make -j2
If you have 4 cores, run make -j4
Now, you can do something else for a while. Compilation will take some time. When it's finished, follow the remaining steps.
Installation
Simply run this command-
sudo make modules_install install
Fixing grub
There are following things that need to be changed in the /etc/default/grub file. Open this file as sudo, with your favourite text editor, and do the following.- Remove GRUB_HIDDEN_TIMEOUT_QUIET line from the file.
- Change GRUB_DEFAULT to 10 from 0
This is how my file looks after being edited.
What these changes do is-
- Grub menu for choosing OS to boot from is hidden by default in Ubuntu, it changes that to visible.
- The menu shows up for 0secs, before choosing the default option. It changes it to 10 secs, so we get a chance to choose which OS to boot from.
After all this, just run the command to apply the changes.
sudo update-grub2
Now restart the machine.
Did it work?
If it worked, then you'll ideally see something like this upon restart -In advanced options, you'll see two kernels. If you did everything perfectly, and no drivers issues are there, then your new kernel will boot up properly (4.9.8 for me). If you did everything reasonably well, and didn't mess things up too bad, then at least your original kernel should work, if not the new one. If you messed things up completely, then the new kernel won't work, nor would the old kernel (which was working fine to begin with). In my case, in the first trial, my new kernel wasn't working. In the second trial, both kernels were working.
Once you have logged in to your new kernel, just do a uname -r and see the version, and give yourself a pat on the back if it is the kernel version you tried to download.
I did give myself a pat on the back |
Removing the kernel (optional and untidy section)
The accepted answer here is all you need. I'm gonna write it here anyways. Note that I'm writing this from memory, so some things may be a bit off. Follow the AskUbuntu answer to be sure.
Remove the following (this is correct)-
/boot/vmlinuz*KERNEL-VERSION*
/boot/initrd*KERNEL-VERSION*
/boot/System-map*KERNEL-VERSION*
/boot/config-*KERNEL-VERSION*
/lib/modules/*KERNEL-VERSION*/
/var/lib/initramfs/*KERNEL-VERSION*/
cd /boot/
rm *4.9.8*
cd /lib/module
rm *4.9.8*
cd /var/lib/initramfs
rm *4.9.8*
Also, I have a faint recollection that the name of the initramfs folder was something a bit different in my case (not sure).
Kthnxbye
nice article....working for me
ReplyDeleteExtraordinary post! I am enthused about watching narratives. The universe of workmanship is in every case profound and fascinating, and rouses composing different incredible articles. There lies a minor line and a point of separation in the middle of the two ideas of being a human and being a normal individual which has just been clarified by the obtaining of instruction and information that changes the individual totally and causes him include into somebody better.
ReplyDeleteRecently, a friend of mine showed me a site https://essaysbank.com/ where you can order study materials. There you can buy a ready-made article or essay on any topic. I'm glad I can save my time.
ReplyDeleteThat was an informative writeup. Kudos to the author! The large pool of native writers associated with the Cloud Computing Assignment Help Canada service of the LiveWebTutors platform guarantee to provide premium quality content with different assignment formats ranging from simple essays to complicated dissertations in record time.
ReplyDeleteWith the help of such step-by-step instructions, everyone can master this program on their own and get rid of all the errors, if any. I want to spend more time programming so I decided to use the services https://place-4-papers.com/buy-apa-research-paper/
ReplyDeleteThis is best you've got
ReplyDeleteSparkocam Crack
Bandicam Crack
MalwareBytes premium crack
Aivivu - đại lý chuyên vé máy bay trong nước và quốc tế
ReplyDeletevé máy bay đi Mỹ hạng thương gia
vé máy bay từ mỹ về việt nam hãng ana
vé máy bay từ frankfurt đi hà nội
giá vé máy bay từ nga về việt nam
giá thuê máy bay từ anh về việt nam
mua vé máy bay giá rẻ từ pháp về việt nam
khách sạn cách ly ở cam ranh
chuyen bay danh cho chuyen gia
The best post with a piece of acquainted data. Much obliged to you for sharing such data. In the event that you need any scholastic level myassignmenthelp at sensible cost with better work, then, at that point call us now!
ReplyDeleteYes, you know this guide is not very relevant for this blog, but there will probably be people who will be interested. I would like to share with you also something useful, namely a service where you can buy pre written essays for sale https://essaysempire.com/buy-pre-written-essay.html
ReplyDeleteHello friends, my name is Rahul, who has brought something special for you. I am a resident of Jalandhar city. I have brought something for you, you will find it on my website. You can visit my website.
ReplyDeleteJalandhar Escort Service
Escorts Service in Jalandhar
ReplyDeleteVery wonderful informative article. I appreciated looking at your article. Very wonderful reveal. I would like to twit this on my followers. Many thanks!
bulletintech
whizzherald
talesbuzz
alternativestips
techwithgeeks
shindigweb
gettechexpert
chatiw
Yes, you know this guide is not very relevant for this blog, but there will probably be people who will be interested.
ReplyDeleteThis is a great post I seen because of offer it. It is truly what I needed to see seek in future you will proceed after sharing such a magnificent post. 먹튀검증
ReplyDeleteWhat a fantabulous post this has been. Never seen this kind of useful post. I am grateful to you and expect more number of posts like these. Thank you very much.
ReplyDeletefhfdhd
ReplyDeleteGil Kenan (Poltergeist) is directing this adaptation of Scott Cawthon's horror video game Five Nights at Freddy's, in which security officer Mike Schmidht is hired by a pizza parlor that is terrorized by unknown monsters every night. The goal of this video game is to make it through each day of perilous labor alive.
ReplyDeleteKeep sharing good information
ReplyDeleteThanks for sharing information
ReplyDeleteThis Article is Awesome.
ReplyDeleteThe bank is the only doubtlessly profitable place, and this profit will usually be negated by the commission charged by the casino. Traditionally, on both sides of the table the gamers take turns to be the lively player. If the lively player wins the coup, the 카지노사이트 same player continues to play for that facet of the table within the subsequent coup. If the player loses, the turn to play the hand passes to the next player on that facet in counter-clockwise rotation. Now, if the banker's whole is 7 or much less, the banker must decide whether or not to draw a third card.
ReplyDeletehello
ReplyDeleteThank you very much for providing this information. The best article with some well-known information about Compiling Linux Kernel. Call us right away if you require any type of academic level administrative law assignment topics at a reasonable price and of higher quality.
ReplyDeleteI find this post so informative. Thanks for sharing this one! www.repairmyappliance.ca/stove-oven-repair/
ReplyDeleteThanks for sharing beautiful content. I got information from your blog.keep sharing
ReplyDeletebankruptcy lawyers in virginia beach
bankruptcy lawyers in lynchburg virginia
I wish it were easier than this. According to Mark Kriski wife Jessica, it could always be better to stay calm. Even Amber Lovato claims that her sister Demi is quite crazy.
ReplyDeleteAll Linux distributions are built upon the Linux Kernel. The kernel is in charge of resource allocation and communication between hardware and software.
ReplyDeleteLove Shayari in Hindi
ReplyDeleteAttitude Shayari in Hindi
Birthday Shayari in Hindi
The blog "compiling-linux-kernel-on-ubuntu.html" offers a comprehensive guide for users eager to delve into kernel compilation on Ubuntu. Its clear instructions and insights make it an invaluable resource for both beginners and experienced users. Kudos to the author for simplifying a complex process and empowering readers to enhance their Linux experience. This blog exemplifies the collaborative spirit of the open-source community, fostering learning and innovation.
ReplyDeletenew york uncontested divorce instructions
new york state divorce mediation
Here are the list of Hottest Female celebrities Visit Hottest Female Athletes
ReplyDeleteThese detailed tutorials enable anyone to become proficient with the programme independently and eliminate any faults, if any. I chose to use postal service because I want to spend more time programming. How have codes systems adjusted to fit modern technology as they have evolved throughout different nations? Any recent advancements that might have an impact on the future operations of international Postal Codes particularly catch my attention. I'm willing to assist.
ReplyDeleteIm very pleased to read this article. Awesome post, Thanks for this one
ReplyDeleteGreat Post! Im looking forward to seeing more from this blog here.
ReplyDeleteThere are some great ideas above. Thanks for providing this good stories
ReplyDeleteThis website is useful. You made great points Many thanks for sharing.
ReplyDeleteThank you for such kind and heartfelt words! They mean so much. It’s always wonderful to know when content resonates and connects on a deeper level. If you ever have thoughts, questions, or even suggestions for future topics, please feel free to share—I’d love to hear your perspective as well! Best interior designers in Chennai
ReplyDeleteThank you so much for your fantastic blog post! seo company Chennai I really appreciated how you broke things down, especially the part where you discussed [insert specific topic]. Your writing is so clear and engaging, and I walked away with so many valuable insights. It's exactly what I needed, and I’ll definitely be coming back for more!
ReplyDelete