| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This is a minimal initrd for usage with Hocus. UUID based mounts are unreliable when used with conjuction with OverlayBD as most obd images don't have an disk UUID or have the same UUID. This initramfs is designed to mount virtio-blk disks by their serial number. To mount an rootfs please use:
mountdevice=SERIAL=<disk_serial> mount_target=/
Up to 32 boot time mounts are supported:
mountdevice=SERIAL=<disk1_serial> mount_target=/ mountdevice=SERIAL=<disk2_serial> mount_target=/mount2 ... mountdevice=SERIAL=<diskN_serial> mount_target=/mountN
Disks are mounted in the order specified on the kernel cmdline, if a mountpoint does not exist then the target directory including required parent directories will be created. Mount options are customisable:
mountdevice=SERIAL=<disk_serial> mount_target=<mount_target> mountflags=<optional_mount_options> mountfstype=<mount_filesystem_type>
By specifying mountfstype on the command line the OS will boot much faster as the initrd will avoid scanning the disk for the filesystem type.
To build this initrd please run ./docker-build.sh
This is a very minimalistic initramfs implementation for booting Linux systems. It has nearly no features, but is very small and very fast. It is written purely in C, but uses only parts of the standard library.
There are three primary use cases:
When compiled on an x86_64 system with the default -Og compiler flags, statically linked against dietlibc 0.33~cvs20120325-6, the binary stripped and the resulting initramfs (without any modules added) compressed with gzip -9, the images produced are between 9 kiB and 14 kiB, depending on the feature set selected.
Using musl instead of dietlibc adds between 1.8 and 2.4 kiB to the resulting initrd.img size (depending on the feature set).
Using glibc instead of dietlibc adds around 310 kiB to the resulting initrd image and is not recommended (although it will work).
Adding modules to the initramfs will increase the size, and many block device and file system drivers are 100s of kiB in size. On the other hand, the kernel would be larger if they were compiled in, so the actual amount of space lost due to using modules is quite a bit smaller.
If your setup falls into one of these cases, please use a full initramfs instead of tiny-initramfs. It is not meant to replace those, but provide a light-weight solution in cases where the complexities of a full initramfs are unnecessary.
Install an alternative libc implementation that's designed for embedded use cases, such as musl or dietlibc. This is strictly speaking not required, as the default glibc will also work, but then the binary size of the resulting binary will be far larger. If tiny-initramfs doesn't work with your favorite libc implementation, please report this, so that it may be fixed.
Find out the compile command required to use your C library. For example, with dietlibc it's "diet gcc", with musl it's musl-gcc.
Use
./configure CC="diet gcc" make
to compile the tiny_initramfs binary and
make initrd.img
to auto-create the initramfs image. Replace "diet gcc" with the appropriate command for your libc implementation.
Note that if you specify CFLAGS (potentially via your build system) you should take care to specify -Os and not to specify any debug (-g) options, as those tend to increase the binary size quite a bit. ./configure will warn you about it, but it not abort in that case, because the binary will work. Likewise, if you don't use an alternative libc implementation but glibc, ./configure will warn you about it, because that will increase the binary size by a factor of 10 to 20.
You may specify multiple options to enable/disable certain features in the initramfs. Specifically, you can disable UUID mounting support (enabled by default), and you can enable NFSv4 support (disabled by default). A list of possible options is displayed when using
./configure --help
The initramfs creation is really simple, you may also do so manually:
The following commands do just that:
mkdir initramfs cp tiny_initramfs initramfs/init strip initramfs/init mkdir initramfs/dev initramfs/proc initramfs/target cd initramfs ; find . | cpio -o --quiet -R 0:0 -H newc | gzip > ../initrd.img
With this there's now a (kernel-independent) initramfs image that may be used to boot the system. Note that as of now there is no integration with distributions, so configuring the boot loader etc. has to be done manually.
There is limited support for loading modules if --enable-modules is specified during the configure invocation. To use this feature, one needs to create a file /modules in the initramfs image that is of the following format:
/file.ko options
The modules should not be in a sub-directory, because the directory containing them will not be cleaned-up by tiny-initramfs after mounting the root file system. (Loading the modules will work though.)
For example, the virtio block device driver virtio_blk requires some additional modules to work. Using modprobe one may find out which:
$ /sbin/modprobe --all --ignore-install --quiet --show-depends virtio_blk insmod /lib/modules/[...]/kernel/drivers/virtio/virtio.ko insmod /lib/modules/[...]/kernel/drivers/virtio/virtio_ring.ko insmod /lib/modules/[...]/kernel/drivers/block/virtio_blk.ko
It turns out that this is not quite sufficient, because the virtio_pci driver is also required for virtio_blk to work (the driver loads without virtio_pci, but doesn't work), so one may use:
$ /sbin/modprobe --all --ignore-install --quiet --show-depends virtio_blk virtio_pci insmod /lib/modules/3.16.0-4-amd64/kernel/drivers/virtio/virtio.ko insmod /lib/modules/3.16.0-4-amd64/kernel/drivers/virtio/virtio_ring.ko insmod /lib/modules/3.16.0-4-amd64/kernel/drivers/block/virtio_blk.ko insmod /lib/modules/3.16.0-4-amd64/kernel/drivers/virtio/virtio.ko insmod /lib/modules/3.16.0-4-amd64/kernel/drivers/virtio/virtio_ring.ko insmod /lib/modules/3.16.0-4-amd64/kernel/drivers/virtio/virtio_pci.ko
(Note that in case soft dependencies are treated via install lines, these have to be resolved manually. This is typically not the case for drivers needed within initramfs, because other implementations also suffer from the same issue. install is deprecated anyway according to the manual page of modprobe.d.)
One may then copy these drivers to the initramfs image, and then add a module file with the following contents:
/virtio.ko /virtio_ring.ko /virtio_blk.ko /virtio.ko /virtio_ring.ko /virtio_pci.ko
The order is important, because dependency resolution is not performed by tiny-initramfs, it has to be done while creating the initramfs image. Duplicate entries are not a problem, because they will silently be ignored (but you may remove duplicate entries if you don't change the order otherwise).
Options may be specified when followed by a space (tab characters not supported), for example:
/libata.ko noacpi
If an error occurs, tiny-initramfs will print an error message indicating the problem and then sleep for 10s before exiting. This is because exiting will cause a kernel panic, but typical kernel traces are so large that they replace the entire screen contents on a standard terminal, so that the original message is not visible anymore. The 10s delay allows the user to see what the problem is.
Additionally, one may use the --enable-debug flag of ./configure to make initrd.img verbose (while increasing the size a bit). This makes debugging easier, especially if the system hangs at a certain point. When compiled with that option, tiny-initramfs will print the contents of /proc/self/mountinfo and sleep for 5s after mounting the root (and potentially /usr) file systems before executing init.
The design of tiny-initramfs is as minimalistic as possible. The buffered I/O functions from the stdio.h standard library are completely avoided, because they can increase the code size quite a bit, depending on the libc implementation. At one point an own minimalistic buffered I/O routine is implemented (much smaller than the full standard library linked in).
Dynamic allocations are avoided and buffers on the stack are used. Code that properly handles dynamic allocations tends to be longer, so this reduces code size. The buffers are sized generously (there are not that many buffers that the amount of RAM used is a concern just yet, even for small systems), so that no real flexibility is sacrificed.
None of this is extremely performance-critical (it is going to be quite fast regardless, because very little is done compared to even just running a shell), so no algorithm is optimized for speed directly. For example, the mount option parser table is somewhat compressed to reduce the code size (negation and recursive variants of mount options are not repeated), to the point where further reduction would likely sacrifice the readability of the code. Execution speed is achieved by doing very little, not by micro-optimizing algorithms.
Sometimes it is necessary to reimplement certain libc functions because using the libc variants increase the image size too much. For example, using inet_ntoa and inet_aton (to convert between ASCII to binary representations of IP addresses) from the musl C library will cause initramfs images (after compression) to be an additional 5 KiB larger as compared to the own implementation.
Of course, changes that reduce the current code size even further (as long as the code remains readable) are very welcome.
There is no goal of adding too many additional features here, because any additional feature is going to increase the binary size, and this is supposed to be minimalistic and not a replacement for a full initramfs. If you need advanced features, please use an already existing solution. That said, there are a couple of things that might be interesting regardless:
Note that the goal is to keep the initrd.img size smaller than 16 KiB on all platforms, so a cutoff of 15 KiB is used on x86_64, to leave room for different assembly code sizes etc., at least when used in a minimal configuration. Therefore, some features (such as UUID= and NFSv4 support) are compile-time optional.
Note: any features missing from tiny-initramfs that would be required in a space-constrained environment (i.e. mainly embedded), where it was designed for, stand an excellent chance of being included later, at least compile-time optional. Please make your case if you are missing something.
| Back | FazBrowse Home | New Git URL |