 Hi, I'm Denshi, and in today's video I'm going to show you how to download and compile your very own customized Linux kernel. The first thing you're going to want to do is go to the kernel.org website which is linked in the description right here, which contains obviously the Linux kernel archive. We're going to right click over here on the latest release and copy a link address. Then we're going to go to our terminal, whichever terminal emulator you use, and I'm going to use the WGet tool to download this exact file. Now this is a tarball that contains all the source code for the latest Linux kernel build. All right. So it's now untarred. Tar, xvf, then linux, whatever it may be, dot tar dot xc. That's going to uncompress this tarball to this directory. As you can see, there is a lot of stuff in the kernel, so this may take a while. All right. So now that we're done downloading and extracting the kernel, let's take a look at how we can actually compile and customize it. So if we go into the Linux directory that we just created, you'll see that there's a lot of things here. The thing you want to pay attention to is the .config file, which if you do ls-a, as you can see is not present at the moment because we still have to create it. This kernel is customized through the .config file, which tells the compiler what to compile in and what not to compile in. This includes things like kernel modules and core kernel functions and customizing them to your needs. So there's various ways of generating that .config file. There's ways of doing that automatically. There's ways of just downloading ones that are pre-made on the internet. But today we're going to make our very own from scratch. So we're going to want to run make menu config, which creates an interactable and curses menu for us to customize our kernel. I'm also going to pass a DAFJ12 flag over here to make sure that it's using as many cores as possible when compiling. You normally want to set the number to the amount of threads on your computer. All right. So now that we've ran make menu config, we can finally customize our kernel with this interactive screen. So we're going to begin in general setup. And there's a lot of things you can customize about the kernel here. Now there's a few things at the top like compile drivers, which also will not load and things that most of these options are generally arbitrary not needed. Like for example, the default init path, this kind of stuff is set pretty much by a distribution. You don't need to add this. The kernel is enough to have control over that. However, we can change the kernel compression mode, which changes how the binary of the kernel is compressed to boot a little faster. So ZSD is generally the least compressed. So we're going to select that by pressing space or enter. And we can go down over here and disable a few other things like pose x message skews that aren't needed. You can go over here and go to, we can also disable auditing support. Go to the timer subsystem. We can change the time to handling. So this one over here is better for battery because it actually disables the timer to completely shuts it down when the CPU doesn't need it. And this one is better for performance because it keeps the timer constantly, constantly ticking. So we're going to select that one pressing space and we can disable these two configurations as they are no longer needed. You can go down here and change a few other things about the system. Like for example, in CPU test time, it says accounting. We can disable BSD process accounting and a few other things probably here. But I'm going to keep these enabled to be safe. The kernel log buffer size, CPU kernel log buffer and temporary per CPU print K log buffer size. Now I've seen a few people set these to as low as 15, 15 and 12. I'm going to go for a little preemptive 16. I'm going to go for 15 here, not 115, 15. And I'm going to set this one to 11 is probably going to be fine. Or maybe no, I'll do 13. That's a little better. Now going on over here, there is an important option. This is the init ram FS. Now this may be needed if you need to add modules that are kernel, like for example, NVIDIA stuff. However, you obviously don't need it for every single type of compression because we're only compressing with the aforementioned Z STD. So I'm going to disable all of these and only keep the regular init ram FS. And that's pretty much it for this section of the kernel. All right. So for processor type and features, this is where you customize things directly for the CPU. There's a lot of options here. All you want to do is enable the Intel ones and disable the AMD ones or do the opposite if you're on AMD, of course. We're going to go to processor family and changes to whatever model you have. So if you're on AMD stuff, you'd pick this over here. If you have an Intel CPU newer than Core 2 or newer Xeon, then select this, which is me in my case. And if you have an Intel item, you select that one. All right, maximum number is CPUs. This actually can be changed as well. I don't have 64 cores. It definitely will probably never have 64 threads. So I'm going to do 12. There's a few other options over here. Like for example, enable maximum number of SMP processors and NUMA nodes. You don't need that. And multi-core schedule support. I do need this because I have quite a lot of cores. However, if you have like an only two core system or something, you could think of disabling this. Going down here, we can disable AMD microcode loading support. You want to keep the MSR and CPU ID options enabled because they might actually help with certain programs that do use that kind of stuff. Like for example, mining software. And you should keep NUMA memory allocation support because that also can help with some software that uses it. Even if all your core is shared the same memory bus, this might still be useful. Five-level paging support, we can disable this. Now, I know Mental Outlaw mentioned this in his kernel video. And I think a few other kernel videos also mentioned this. But this is basically unneeded. You're probably never going to want to need this. Maximum NUMA nodes, six would probably be okay. You probably can go with lower, if not no NUMA at all in some cases. Over here, there's EFI support. I'm going to keep this on because I use a UEFI system. Memory protection keys, these are for your security. However, if you don't want the slight tiny overhead from these, you can disable them. The KExec system call, you're probably going to want to need this if you want to install things like NVIDIA drivers or other drivers that aren't directly in the kernel. However, if you're not going to be doing that, you can probably disable it. All right, so that was it for CPU type and features. Let's go to power management and ACPI options. This is Pentagram. You're probably going to want this. If you're on a laptop, I want to save battery. I'm going to disable it. And there's a few other things like hibernation, obviously. And you might want to go to CPU frequency scaling and enable a few things here. For example, if you're on a laptop and want to use tools to change your performance governor, then you can change it to power save or user space or on demand or whatever. There's all these options. I'm going to disable this because I'm not going to use this. However, if you are on a laptop or other devices, then know that you can change your CPU profile. And I'm going to enable the CPU idle driver for Intel processors just in case. All right, so when it comes to bus options, there's pretty much nothing to do in here. So we could ignore the default. Then in binary emulation, as you can see, not much to really customize here so we can get out of that and just leave it as default. Firmware drivers, once again, not much here. However, if you are on a Google device, you can enable Google firmware drivers if for some reason you want that. So what do you do? Virtualization, I'm going to disable this. I'm not really going to be running a lot of virtual machines. I don't need it. However, if you do wish to run virtual machines and Keymoon stuff and do enable this. General architecture dependent options. Once again, not much here, but this generally can be kept the same unless you know what you're doing with GCC and want to customize things here or whatever. Enable loadable module support. We can basically keep this as default, not really much that you can change here. I know in mental outlaw, I know in mental outlaws video he does forced module loaning and disables it. However, I don't really think it has a huge difference when it comes to performance. That's mostly a thing that's useful when administrating a system. The IO scheduler is once again, not much to look at here. With enable the block layer, there are a few things you can disable here like for example, block layer debugging. Now I know mental outlaw mentioned this in this video and you want to disable this because once again, it's bloat. It's only really needed for kernel developers, as you can see. And so it's not really useful. That goes for a lot of these log modules. They're only really useful if you're going to be debugging the kernel, which most people don't do. So you can pretty much disable most debugging options unless you're a little bit paranoid. And with IO schedulers, once again, we can just leave this as default. Most of these options are pretty much not going to change much. Executable file formats, we can leave this as default. Memory management options. We can also leave this as default. I'm not an expert in this area. So I literally have little idea of what you could change here for performance. Networking support. Here you could disable different things. If you want Bluetooth support, you could enable it here. However, I'm not going to be building it in, so I'm going to disable that. We will take a look at how you can disable wireless drivers later on. If you go to networking options, you can't customize this very low level internet stuff. However, I'm definitely not going to go through and do this because I'd probably mess something completely up. All right, now device drivers, this is the big one. Here you can disable and enable drivers for different devices, as the name implies. And there's a lot of things you can enable and disable and a lot of bloat is located here because there's just a lot of devices that Linux supports. So PC card, we can disable that. Now scroll down here to MVME support. I'm going to enable this because I have an MVME drive. You can enable all these different options because I do use it. And with miscellaneous devices, you want to make sure that any of these things you don't need are disabled. I'm keeping them all disabled because I don't need any of these weird things. Now go into the SCSI device support. You can go over here and enable asynchronous SCSI scanning. I've tested it myself and yes, the Linux kernel boots faster under that option. Now going down over here to serial, ADA and parallel ADA drivers, you should basically keep this the same. However, there are a few things you might want to disable depending on your drive, but it should generally be okay just keeping this the same. And when it comes to multiple device support, this refers to things like RAID and LVM. I don't have any kind of RAID drive so I can disable this. However, if you do, you can go through there and customize things. We can disable Macintosh device drivers as they do not use them. Go to network device support and disable things you're not going to be using. Like for example, I'm going to go over here. I'm going to completely disable wireless LAN, which I do not need. Alongside USB network adapters because I also don't need those. And I'm going to disable network console logging support as you might not strictly need that. You might also want to enable the wire guard secure network tunnel if you're using that kind of VPN. Some VPNs need this. So make sure to enable it just in case if you're going to be using a VPN. All right, so down to input device support, you can disable a few things here. I'm going to completely disable all touch screens, miscellaneous devices and tablets as they do not use them. You can disable things specifically in keyboards and mice. However, keeping these on will generally be a little bit safer. All right, now going down over here, you can disable all USB support if you want that for some reason, but you can go over here and enable multimedia support. You're going to need this if you're going to be playing certain sounds and my sound card completely doesn't work without this. So I definitely need the same. Now going to graphics support, here you can disable a few things like for example, maximum number GPUs. I'm going to make this two as I have my integrated one and of course my graphics and my laptop. And because of that, I'm going to enable the laptop hybrid graphics which are needed. Make sure to enable the ADI radio and our AMD GPU drivers if you are on those but I'm not on those. And if you're on video and you want to use the open source drivers for whatever reason, then enable this Nouveau driver. However, I'm not going to be using that. So it's going to be okay for me. I'm going to be using the proprietary one. All right, so going to sound card support. There are a few things you want to enable here. So I'm going to go to PCI sound devices and enable your sound card because if it's not enabled here, you're not going to get sound. My case is one of these Intel ones. I'm just going to enable all of them and that should be it for sound card support. When it comes to USB support, you can disable a few things here. However, I'm not going to touch this because I don't want my USB is to be completely done for. And then going down here, keep going there's accessibility support if you need that kind of stuff and you can enable it over here. And this section might be important, the X86 platform specific device drivers. In here, you'll find options for specific devices that you might actually need for certain laptops or certain desktop computers that have like quirks or nuances about them. So if you know that your device specifically has something odd about it, then enable stuff here. I'm going to enable the Dell stuff because I'm using a Dell laptop. As you can see, all of these little laptop extras and stuff I'm going to enable except the freefall driver because I don't have that in my system. So things like updating the BIOS for Dell devices and stuff. Because Dell is very friendly to Linux, because Dell is very friendly to Linux, these sort of things are included in the Linux kernel. All right, so there is also platform support for Goldfish devices, support for Chrome hardware and Melanox hardware, you might need this of course. I'm going to disable the Microsoft Surface stuff because I don't need that. Going to the bottom, most of the stuff you're probably not going to need at all. In the Android section, you might want to build in some Android drivers just in case you're going to be dealing with your system and its file system and stuff. All right, so that's pretty much it for device drivers. That was the big part of customizing the kernel. It's probably going to save us a lot of RAM. And now we're going to go to file systems. And in here, you can pretty much keep everything generally the same, except we're going to disable miscellaneous and network file systems. You need network file systems to use systems like Samba and other things on the network. And you need miscellaneous systems for specific file systems that some may need and most really don't, so I'm going to go out of there. Now, when it comes to security options, there are a few things in here that you can customize. However, I wouldn't be to, you know, touch you with this sort of section. I'm just going to ignore it. Cryptographic API, once again, same with security. I wouldn't mess around here because you're probably going to compromise something. And LiveBee routine is the same thing here. I generally, I wouldn't touch this. Finally, in kernel hacking, you can enable things like specific logs or tracing for the kernel, but I'm not going to enable any of that because I don't need that. I'm not a kernel developer. All right, so it's done. We've configured the Linux kernel. We can now go over to the save section, press enter, press okay, press exit, and then we're going to exit over here. So just like that. And now we can finally compile our kernel. So to compile that, we're going to run a few commands. We're going to begin by running make-j12 to compile the actual kernel. Then we're going to run sudo make modules install-j12. So it compiles the kernel modules and installs them. Then after this, we're going to manually copy over the kernel to our boot directory. So we can actually boot to it. And then we're going to update our bootloader accordingly. But in the meantime, just let this run. It will take a while to compile. The Linux kernel is quite large. And I'll see you in a few minutes. Okay, so as you can see, the kernel is now done compiling. And most importantly, those modules are also installed. So it says over here that arch x86 bootpz image is ready. So that's the actual kernel. That's the binary of the kernel. And in fact, we can go and copy this over to our boot directory and give it a new name. So if you list out your boot directory, you'll see there's a file called vmlinus and vmlinus linux. So this over here is your current kernel. Probably, it might be named something else. We're going to give it a custom name. So we're going to copy over sudo cp arch x86. This is relative to the local directory. And we're going to copy it over to slash boot vmlinus. And we're going to give it a name linux alex. That's going to be alex linux. Now we're going to press enter. And as you can see, it's copied over. And finally, after copying the linux kernel image to the boot directory, we're going to reconfigure our boot loader. So we're going to do sudo grub mkit config and dash o to send an output to this file over here. We're going to press enter. And as you can see, it found the linux image over here. Now we're going to reboot. I'm going to switch the kernel in the grub menu and I'm going to open it up here. One thing to note before we do any of this is to check our RAM usage to compare it between before and after. So if we do free dash h, just your current memory usage is 1.6, give you bytes, which is probably caused by a combination of me recording and doing other things. So let's take a look at how that changes once we go in the other kernel. All right, I'm booted back with my new customized kernel. Just going to do uname dash h to check. Yeah, there we go. 5.12.10, which is not the same as the one installed on my system. So if I check that one, see that this one over here is 5.12.9 and also arch because the arch linux one. So let's check our resource usage. And as you can see, it's relatively low compared to the previous one, which was 1.6 or so and this one's 989 megabytes. Now, obviously this isn't a perfectly fair comparison. This isn't a magic benchmark that means that, yeah, your system's going to run 1,000 times faster because you did a custom kernel. However, when it comes to saving memory and especially on systems with low memory, this sort of customization can really help. And if you're in a really competitive space or something where you really need as much power as possible and customizing your linux kernel to remove a lot of features might be a good idea. And in my opinion, it's the one thing that really counts when it comes to custom compile. Anyways, I hope you enjoyed this video I made on how to compile your very own linux kernel. I've been Denshi. Goodbye.