LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-28-2018, 02:28 AM   #1
Unturned3
Member
 
Registered: Jan 2018
Posts: 39

Rep: Reputation: Disabled
[SOLVED] How can I make the kernel smaller?


Hello,
I am building a very small Linux system from scratch using just the kernel and busybox. So far I managed to setup a very basic bootable system with the components mentioned before and Syslinux, weighting at 12mb. I am trying to make it more tiny in order to squeeze it into a small virtual machine.
How can I make my kernel smaller? Currently, the compiled kernel takes up 8mb of space, and I found out that distributions like TinyCore Linux only uses a kernel of 3mb. I've tried to use the "make tinyconfig" option but the resulting kernel doesn't boot anymore (it seems like a lot of crucial components are missing)

Any help/advice would be greatly appreciated! Thank you very much.

Last edited by Unturned3; 02-05-2018 at 08:20 AM. Reason: solved problem
 
Old 01-28-2018, 08:46 PM   #2
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
make localmodconfig will strip out all the modules that you don't have hardware for, or don't have plugged in when issued. It makes it smaller and compile faster. But if you want things not attached, like other filesystems to mount and read. You'll need to compile your kernel again.
 
1 members found this post helpful.
Old 01-29-2018, 03:32 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,413

Rep: Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489
Maybe try some different compression on kernel.
 
Old 01-31-2018, 03:13 AM   #4
Unturned3
Member
 
Registered: Jan 2018
Posts: 39

Original Poster
Rep: Reputation: Disabled
Thanks for the help!
I may need to try a XZ compressed kernel instead of GZ. Maybe that will shrink it down by one or two megabytes.
I tried the "make localmodconfig" and the resulting kernel is only 1760kB! However when I swapped this tiny kernel with my existing 6mb kernel the machine won't boot anymore. Syslinux is working fine, but the kernel just doesn't boot. I checked the configuration and it seems like that the all the major components has been selected. What's going on here?
 
Old 01-31-2018, 04:47 AM   #5
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
Did you make bzImage or other traditional kernel types. Make sure the modules needed to read the storage device that contains the / system is in the initrd or in the kernel and not modules. To include the filesystem and the hardware the storage device is connected to. I tend to cut and paste entire sections (like filesystems) from the default /boot/config that comes with a distro to a resulting make localmodconfig .config file. Although these days I mostly block or modprobe -r that modules I'm not using (webcam / wireless / bluetooth / ...) after bootup. To lower CPU usage and maximize RAM. Not that significant these days with multicore CPUs and more than 2GB of RAM.
 
Old 02-01-2018, 06:35 AM   #6
Unturned3
Member
 
Registered: Jan 2018
Posts: 39

Original Poster
Rep: Reputation: Disabled
Yes I double checked that I selected all the important components (block layer, ext4 file system support, PCI devices, storage drivers, etc).
All of these are checked and I don't think any component is getting compiled as a separate kernel module (because I unchecked the "use loadable module" flag). However, the resulting kernel still won't load, for some reason. Is there any way that I can check what's going on in there? I can't see any error messages printing after the boot prompt of Syslinux.
 
Old 02-01-2018, 03:46 PM   #7
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
Assuming all the usual logging happened... /var/log/kern.log tends to contain a lot of boot gripes / events. Which might be blank if it never got past the bootloader or the kernel never gained the ability to write logs to anything other than RAM.
 
Old 02-01-2018, 04:03 PM   #8
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,413

Rep: Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489
Kind of a lot of unknown issues.

Syslinux may have some issues with any number of things. This kernel may have issue as well as the hardware it is running on. Not sure what way to go here.

Swapping loader or kernel or hardware or review your build example. ???


What web page are you using as a guide.


General ideas on this here. https://www.linuxjournal.com/content...-distributions

Last edited by jefro; 02-01-2018 at 08:17 PM.
 
Old 02-02-2018, 04:08 AM   #9
Unturned3
Member
 
Registered: Jan 2018
Posts: 39

Original Poster
Rep: Reputation: Disabled
@ Shadow 7
I mounted the disk image that the system was on and checked /var/log/messages, and there weren't anything there. It seems like that there's a problem when the Syslinux is handing the control over to the kernel. The kernel didn't seem to run at all.

@ jefro
I am using this guide to build my small Linux system: https://github.com/MichielDerhaeg/build-linux
I'll get rid of syslinux and test out the system using Grub and see if it works. Hopefully this can narrow down the problem.
Thanks for the link to the article!

BTW I am using QEMU to boot the system. The original kernel (the 8mb one) works both under QEMU and Oracle VirtualBox

Last edited by Unturned3; 02-02-2018 at 04:12 AM. Reason: adding some extra info about QEMU
 
Old 02-05-2018, 08:20 AM   #10
Unturned3
Member
 
Registered: Jan 2018
Posts: 39

Original Poster
Rep: Reputation: Disabled
After about four hours of work, I finally managed to check all the necessary compartments (block layer, file system, ramdisk, SATA drivers, etc) from scratch (using make tinyconfig) and the kernel now works! The resulting kernel is just under 3.5 megabytes!
Thanks for the help guys!
 
Old 02-06-2018, 08:14 AM   #11
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,748
Blog Entries: 4

Rep: Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515
When I was using Gentoo a lot, I started by booting a "rescue DVD" and noting exactly what kernel modules it identified. I'd also plug in and remove USB devices and note which drivers it selected for hotplugging. Then, I'd build a kernel configuration to suit ... taking care to make a backup copy of the hidden config-file ... in a non-hidden, locked, dated file which I never discarded. (This allowed me to use diff to instantly see how any config varied from any other.)

I would invariably "rename the hidden file out of the way," then run make distclean, then "rename it back" (after also making the aforesaid backup). In this way I could be certain that every kernel-compile started from scratch and recompiled everything at once.
Quote:
Originally Posted by Caution!!
make distclean will destroy(!) the kernel configuration file!
Hardware support for all the fixed hardware was compiled into the kernel, and support for USB devices was hotplug modules. (I compiled only the modules needed to support the removable devices that I actually owned.) Compiler options were set for the actual microprocessor-type, which was known. The initrd step was completely eliminated – it was unnecessary – and I wound up with a Linux that could start from cold in about seven seconds flat. The machine, which was originally sold with Windows-95 on it (poor thing ...), was suddenly ... fast!

Last edited by sundialsvcs; 02-06-2018 at 08:21 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Tiny Core Linux 4.7 overhauls the OnDemand system LXer Syndicated Linux News 0 11-02-2012 11:20 PM
I have a few questions about building a system to use for studying RHCE. ohlookpie Linux - Newbie 5 04-12-2012 12:25 AM
MYSQL questions - newbie building a system Latios Linux - Server 4 05-28-2011 10:30 AM
LXer: Tiny, modular Linux system targets embedded apps LXer Syndicated Linux News 0 06-20-2007 06:17 AM
LXer: Tiny Linux system boosted to 400MHz LXer Syndicated Linux News 0 10-24-2006 02:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration