I've read many tutorials about how to build custom kernels and boot Ubuntu using those kernels, and successfully followed the guides and booted custom kernels, but I have no understanding about what each of the command in the guides do and what is actually happening with each command.

The procedure described on Ubuntu's site does a lot of work with fakeroot, dpkg, make-kpkg, some initramfs, and other horrible stuff that works but simply does not help me understand what is going on.

  • What is the output of make in a linux kernel directory?
  • Does it create a "compressed kernel image"?
  • What is the name of the "compressed kernel image" file and where is it placed?
  • What does make modules do?
  • Should make modules be done before or after make?
  • Doesn't make build my modules automatically?
  • What is the process (in English, not just the list of commands) of adding newly built kernels to the list of bootable kernels?
  • What does make install do?
  • Will make install add it to my list of bootable kernels so that I don't have to do anything more?
  • Is there an equivalent make modules_install?

From the top...

  • make compiles and links the kernel image. This is a single file named vmlinuz.
  • make modules compiles individual files for each question you answered M during kernel config. The object code is linked against your freshly built kernel. (For questions answered Y, these are already part of vmlinuz, and for questions answered N they are skipped).
  • make install installs your built kernel to /vmlinuz.
  • make modules_install installs your kernel modules to /lib/modules or /lib/modules/<version>.

As for adding it to the list of available kernels, that's taken care of by the boot loader. It's different for each boot loader, but grub is the most common on x86 and amd64 so I'll describe that. It's actually quite simple. Grub looks in /, /boot and /lib/modules for any thing that looks like it might be a working kernel and adds it. And yes, this is an oversimplified description.

That extra "horrible stuff" in the Ubuntu documentation is extra stuff to create a deb package. When you're doing it for more than yourself it's far better to package it. You'll switch in time.

Building the kernel and modules is kept separate because for the people who need to (i.e., kernel developers) they are often making changes to only a module. They can apply their changes, rebuild and install just the modules. This saves a lot of time when it has to be done 20 times a day. It will never be updated to have a single make everything command. You instead, run make && make modules && make install && make modules_install just like the documentation says to do. The build process favors kernel developers, not you. And that's the way it should be.

In reality there's almost no reason for anybody except kernel developers or distro packagers to compile a kernel. In almost any circumstance the kernel feature you want has already been built for you and is available in one of the pre-packaged kernels. There are exceptions, but they are exceedingly rare these days.

Not that I'm discouraging you from doing building your own kernel, I actually encourage you to do it. I think building your kernel from scratch is an invaluable practice for learning about how it all works down there. In part, because maybe one day you will be the exception that needs to. But it also teaches you a lot about the kernel & boot process in general. You will be a better person for having done it.

| improve this answer | |
  • 1
    Thankyou very much for the human-readable description of the process. I have a few doubts. My kernel compilation produced vmlinux and not vmlinuz. I think the difference is compression. Should I compress the image manually ? Is /vmlinuz a directory in the root folder ? when I do a make install will this directory be created and new kernel be placed there ? Will make modules_install replace my currently installed modules ? Suppose I place my vmlinux in /boot directory, do I need to do something else (like edit grub configuration files and do grub-update or something after that ?) – AnkurVj Sep 16 '11 at 15:18
  • 3
    You're right, the difference is compression. The command make bzimage is what does that. /vmlinuz is a binary file, not a directory. I have been making only packaged kernels for about the last 5 years, so I don't remember exactly the behavior of modules_install for a directly installed kernel. Grub will find your kernel in /boot without help. Yes you should always run grub-update after installing a new kernel. – bahamat Sep 16 '11 at 15:25
  • so I should have done make bzimage instead of make ? DO I need to do a make clean and make bzimage again ? By /vmlinuz do you mean the file will be created in the root directory or in the linux kernel source directory ? – AnkurVj Sep 16 '11 at 15:34
  • 1
    It doesn't really matter wether your kernel is compressed or not. Uncompressed it just takes up a little more disk space. Anything prefixed with / is an absolute path, so yes that's a file in the root. – bahamat Sep 16 '11 at 17:54
  • 1
    @GuyAvraham Modules answered Y are compiled in (i.e., they are part of vmlinuz). Modules answered M are compiled as loadable modules. Modules answered N are not compiled. make modules_install only applies to those answered M. – bahamat Sep 4 '18 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.