#!/bin/busybox sh echo In PrawnOS Init #add this to start shell at desired point rescue_shell() { [ $1 != "debug" ] && echo "Something went wrong. Dropping to a shell." exec setsid /bin/sh -c 'exec /bin/sh /dev/tty1 2>&1' } cmdline() { local value value=" $(cat /proc/cmdline) " value="${value##* ${1}=}" value="${value%% *}" [ "${value}" != "" ] && echo "${value}" } rootpartuuid() { local value value=$1 value="${value%/*}" value="${value#*=}" [ "${value}" != "" ] && echo "${value}" } # mount the bare necesities mount -n -t proc proc /proc mount -n -t sysfs sysfs /sys mount -n -t devtmpfs devtmpfs /dev # get the root device, so we can find the boot partiton UNPARSED=$(cmdline root) ROOT_PARTUUID=$(rootpartuuid $UNPARSED) echo ${ROOT_PARTUUID} BLKID=$(/bin/blkid | grep $ROOT_PARTUUID ) echo ${BLKID} #If its an mmcblk device, the partiton will p1. If it is a usb device, the partiton will just be 1 #Just want everything before the 1: so this will work ROOT_DEV="${BLKID%1:*}" echo ${ROOT_DEV} # we use this to change what cmdline options get passed into # the next boot stage, aka to enable root encryption CMDLINE='cat /proc/cmdline' [ -d /boot ] || mkdir -p /boot mount ${ROOT_DEV}2 /boot #Debugging can be facilitated by creating /boot/debug [ -f /boot/debug ] && rescue_shell debug if [ -f /boot/root_encryption ] then #decrypt and mount the root filesystem cryptsetup --tries 5 luksOpen /dev/{ROOT_DEV}3 luksroot || rescue_shell mount /dev/mapper/luksroot /newroot #TODO: UPDATE THE CMDLINE?? else # mount the unencrypted root filesystem [ -d /newroot ] || mkdir -p /newroot mount ${ROOT_DEV}3 /newroot fi umount /sys umount /proc #swith to the new rootfs exec switch_root /newroot /sbin/init ${CMDLINE}