mkinitramfs uses plugins to work with LVM, EVMS, RAID and other storage systems.
Plugin is just a chunk of bash code that is sourced when initramfs's init starts execution. Plugin may implement two functions - discover and scan which are called by init. discover function is called once when udev even race is started, and scan function is called periodically while search for root device is performed.
Plugins are located at /usr/share/mkinitramfs. Each plugin is usually a separated file corresponding to plugin name.
The main plugin is disk. Its always included. The plugin implements only scan function. Here what it does
- check whether /dev/disk/by-uuid/$UUID exists
- if it does, run fsck on it
- if fsck reports no critical errors, mount /dev/disk/by-uuid/$UUID to $SYSROOT. The value of $SYSROOT is defined by init
- if mount succeeds, return success. In all other cases failure is returned.
Its very important to understand disk plugin operation. You can see now that all other plugins left to do is to make sure proper links appear under /dev/disk/by-uuid. For example, this makes dmraid support plugin as simple as this:
#> cat /usr/share/mkinitramfs/dmraid # Register our scan function SCAN="dmraid_scan $SCAN" function dmraid_scan() { dmraid -ay >/dev/null || die return 1 }
NOTE 1: die function is defined by init. Call it when criticall error occurred. See more in function index.
NOTE 2: the function always returns 1, because it does not perform mounts. It actually causes additional entries appear under /dev/disk/by-uuid and lets disk? plugin do the rest.