Last Updated:

Raspberry Pi - Script to create initramfs for early splash screen

If you want to create a inital ram filesystem to inject an early splashscreen, you can use this script to automatically create one. If errors occur it will likely be missing libraries or tools to compile fbv.

#!/bin/bash

SRC_PATH=/path/to/my/splash
IMG=mysplash.png

if [[ $EUID -ne 0 ]]; then 
   echo -e $"Please execute this script as root! Exit." 
   exit 1 
fi 

if [ -e /boot/initramfs.img ]; then 
   rm -f /boot/initramfs.img || true 
   rm -rf /tmp/initramfs || true 
fi 

if [ ! -e /bin/busybox ]; then 
   apt-get update 
   apt-get -y install busybox-static 
fi 

if [ -d /usr/src/fbv ]; then 
   cd /usr/src/fbv 
   make distclean 
   git pull 
   ./configure 
   make 
else
  apt-get update
  apt-get install build-essential autoconf \
busybox-static libjpeg8 libjpeg8-dev \
libjpeg9 libpng16-16 libpng-dev

   cd /usr/src 
  git clone https://github.com/godspeed1989/fbv.git 
  cd fbv 
  ./configure 
  make 
fi 

mkdir /tmp/initramfs 
cd /tmp/initramfs 
mkdir -p {proc,sys,etc/splash,usr/lib,bin,sbin,dev,root,mnt/root} 
cp -a /dev/{fb0,tty,console,mmcblk*,null} dev/ 
cp /bin/busybox bin/ 

MP=$(mountpoint -d /) 
ROOT_DEV=$(readlink -f /dev/block/${MP}) 

cat < /tmp/initramfs/init 
#!/bin/busybox sh 

/bin/busybox --install -s /bin 

Rescue_Shell(){ 
  clear 
  echo -e "Something went wrong...\e[?25h" > /dev/tty1 
  exec sh 
} 

mount -t proc none /proc 
mount -t sysfs none /sys 
mount -t devtmpfs none /dev 

mdev -s 

echo -e "\e[?251" 
echo "q" | /bin/fbv /etc/splash/${IMG} 

mount -o ro $ROOT_DEV /mnt/root || Rescue_Shell 

umount /proc /sys 
mount --move /dev /mnt/root/dev 

exec switch_root /mnt/root /sbin/init 
EOF 

chmod +x /tmp/initramfs/init 

cp ${SRC_PATH}/${IMG} etc/splash/ 
cp /usr/src/fbv/fbv bin/ 

LIBS=`ldd /usr/src/fbv/fbv | awk '{if ($3 != "") $1 = $3} {print $1}'` 

for l in $LIBS; do 
   if [ -e $l ]; then 
       cp $l usr/lib 
   fi 
done 

cp /usr/lib/arm-linux-gnueabihf/libarmmem-* \
/tmp/initramfs/usr/lib/ 

ln -s usr/lib lib 

find . | cpio -oH newc | gzip -9 > /boot/initramfs.img 

LINE='initramfs initramfs.img' 
FILE='/boot/config.txt' 
grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE"

Comments