simple overlayfs init script
source code
#!/bin/shPATH=/bin:/sbin:/usr/bin:/usr/sbinexport PATHfallback() {exec /sbin/init}# if your kernel haven't mount devtmpfs at bootup you need uncomment this:# mount -t devtmpfs devtmpfs /dev# this program need get cmdline from /proc# program mount use /proc to detect filesystem typemount -t proc proc /proccmdline() {cmdline_list=$(cat /proc/cmdline)for i in ${cmdline_list}; dokey="$(echo "${i}" | cut -d'=' -f1)"if [ "${1}" = "${key}" ]; thenecho "${i}" | cut -d'=' -f2-fidone}timeout=$(cmdline overlay_timeout)device=$(cmdline overlay_device)if [ -z "${device}" ]; thenfallbackfiif [ -z "${timeout}" ]; thentimeout=30fiwhile [ "${timeout}" -gt 0 ]doif [ "${timeout}" -eq 0 ]; thenfallbackfiif mount "${device}" /mnt; thenbreak;fisleep 1timeout=$((timeout - 1))donemkdir /mnt/upperrm -rf /mnt/work # make directory emptymkdir /mnt/workmkdir /mnt/newmount -t overlay overlay \-o lowerdir=/,upperdir=/mnt/upper,workdir=/mnt/work /mnt/new || fallbackmount -t devtmpfs devtmpfs /mnt/new/dev || fallbackexec chroot /mnt/new/ /sbin/init || fallback
how to use it
put it into your rootfs, then rename to ’ovinit’, then add execute perm
$EDITOR ovinitchmod +x ovinit
you need tell kernel use this init script:
example with uboot:
setenv bootargs init=/ovinit root=/dev/mmcblk0p2 overlay_device=/dev/mmclk0p3 overlay_timeout=5saveenv