Skip to content

Latest commit

 

History

History
50 lines (40 loc) · 1.85 KB

File metadata and controls

50 lines (40 loc) · 1.85 KB

Initramfs

Initramfs is a filesystem that gets loaded early in the boot process.
It's purpose is to load important modules for storage devices, filesystems, graphics, etc..
However it can also be used for other things such as recovery, graphical splash screens, disk decryption, etc..

Traditionally initramfs is a cruical part of the linux boot process for most systems.
But some systems (eg. embedded) tend to skip that part altogether!

How?

You can typically bake in important modules directly into your kernel.
In most cases this would be storage and filesystem ones as seen on a Raspberry Pi for instance.

Why?

In the case of embedded systems it's to reduce dependencies and resource usage.
In other cases it would be to simply skip it if you don't need any fancy bells and whisles.

Creating an initramfs

To create a very basic initramfs you would have to do the following:

  1. mkdir -p initramfs/{dev,proc,sys,tmp,root,usr/bin,usr/sbin}
  2. cd initramfs; ln -sr ./usr/bin ./bin; ln -sr ./usr/sbin ./sbin
  3. Download busybox into ./usr/bin/busybox
  4. sudo chmod +x ./usr/bin/busybox
  5. sudo chroot . /usr/bin/busybox --install
  6. rm ./linuxrc (if it exists)
  7. Create a new file called init and paste the following in it:
#!/bin/sh

# Mount psuedo filesystems.
mount -t devtmpfs none /dev
mount -t sysfs none /sys
mount -t proc none /proc

# Mount the root filesystem.
mount -o rw /dev/mmcblk0p1 /root

# Clean up.
umount /dev
umount /sys
umount /proc

# Boot the real thing.
exec switch_root /root /sbin/init
  1. Be sure to chmod +x ./init otherwise it won't work
  2. cd .. Then use the provided script to create and compress the initramfs.

And you're done!
This file can be now used to initialize linux.