Really small kernel

Oliver Grawert ogra at ubuntu.com
Sat Nov 2 11:05:32 UTC 2019


hi,
Am Montag, den 28.10.2019, 11:02 -0700 schrieb MR ZenWiz:
> Is it possible to build the ubuntu 18.04 kernel such that it will run
> effectively with 64MB or less?
> 
> While I personally have no need for this, someone asked on Quora and
> I'm curious now.
> 
> I don't think this is feasible, but....

it definitely is ... even without recompiling the ubuntu kernel you
should be able to boot it in 64MB RAM ... the problem here isnt the
kernel but userspace bits required during boot. 

most modern linux installs use an initramfs, this means you load a
small ramdisk into memory alongside the kernel before switching to your
root filesystem.

originally this was designed to be able to load all controller user
space bits (raid tools, controller modules etc) to find your disk. back
then even an initramfs could still fit into 64MB RAM along your
kernel... 

ubuntu is designed to be generic and to run on as many hardware
combinations as possible in a stable way, so you need to ship a lot
more drivers and user space tools alongside the kernel itself than a
system tailored for a single purpose on just one hardware setup would
ever need.

over time new features showed up. people want to encrypt their disks so
you need to add (usb) keyboard support, key maps, some basic language
support and all the bells and whistles to enable them to type in a pass
phrase... someone wants to net boot the rootfs from a remote server. so
you need a networking stack and all the possible NIC drivers included
... then there are boot-splashes to make your screen for pass phrase
typing prettier, show a progress bar during boot etc etc

i guess nowadays the initramfs itself is even bigger than a complete
server install was 15y ago but if you are able to adjust the initrd to
be exactly tailored for your hardware to only do the very simple task
of just mounting your rootfs on this one machine you should be able to
get through the boot to a running rootfs even on 64MB.

later in the boot process the system will also load modules and
firmware into ram, here you have again a lot of generic stuff ... say
your system has USB support, the kernel might load some generic bits
into ram for potential use cases (i.e. usb-storage support in case you
want to plug in an usb stick eventually) all these bits will eat up
your ram right *after* the boot, so you need to tailor the
configuration on the rootfs to avoid this.

each tty login prompt that idles on your system eats ram, so you want
to disable them ... bash uses up ~5MB of ram when running, you want to
make your login shell dash, ash or busybox which were designed for low
ram usage. turn off all non-existential services that could occupy ram.

now ... even if you got to a login prompt and can log in the one
question remains: what exactly do you want to run on this system that
has only enough ram to barely boot it, can you even find software for
the task you plan for this system that is small enough to fit into the
remaining ram ?

with the snap based Ubuntu Core (very often used for single purpose
tasks (Wifi APs, routers, IoT gateways, digital signage displays) on
dedicated hardware) which is very cut down but still ships some bits
for the generic parts described above i can easily boot in 128MB (i
guess even 96MB would work), but after boot just the idling processes
of the OS itself use up ~48MB. that leaves very low space for running
any additional software.

so yes, i guess booting in 64MB RAM is still possible, but requires
jumping through a lot of hoops and that you have a lot of basic
knowledge about what you are doing when modifying it.

ciao
	oli
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20191102/d3534d1e/attachment.sig>


More information about the ubuntu-users mailing list