2019-09-18 03:50:27 +02:00
|
|
|
#!/bin/busybox sh
|
|
|
|
|
2019-10-03 07:40:14 +02:00
|
|
|
# This is the init script built into the PrawnOS initramfs
|
|
|
|
|
|
|
|
# This file is part of PrawnOS (http://www.prawnos.com)
|
|
|
|
# Copyright (c) 2018 Hal Emmerich <hal@halemmerich.com>
|
|
|
|
|
|
|
|
# PrawnOS is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
# PrawnOS is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with PrawnOS. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2019-09-21 06:50:08 +02:00
|
|
|
echo In PrawnOS Init
|
|
|
|
|
2019-09-30 03:16:30 +02:00
|
|
|
#add this to start shell at desired point
|
|
|
|
rescue_shell() {
|
2019-10-13 00:39:17 +02:00
|
|
|
echo "Something went wrong. Dropping to a shell." > /dev/tty1
|
2019-09-30 03:16:30 +02:00
|
|
|
exec setsid /bin/sh -c 'exec /bin/sh </dev/tty1 >/dev/tty1 2>&1'
|
|
|
|
}
|
|
|
|
|
2019-10-03 07:40:14 +02:00
|
|
|
#used to parse the kernel cmdline
|
2019-09-18 03:50:27 +02:00
|
|
|
cmdline() {
|
|
|
|
local value
|
|
|
|
value=" $(cat /proc/cmdline) "
|
|
|
|
value="${value##* ${1}=}"
|
|
|
|
value="${value%% *}"
|
|
|
|
[ "${value}" != "" ] && echo "${value}"
|
|
|
|
}
|
|
|
|
|
2019-10-03 07:40:14 +02:00
|
|
|
#used to get the uuid of the root partiton since findfs isn't in debian busybox-static
|
2019-09-18 03:50:27 +02:00
|
|
|
rootpartuuid() {
|
|
|
|
local value
|
|
|
|
value=$1
|
|
|
|
value="${value%/*}"
|
|
|
|
value="${value#*=}"
|
|
|
|
[ "${value}" != "" ] && echo "${value}"
|
|
|
|
}
|
|
|
|
|
2019-10-13 00:39:17 +02:00
|
|
|
# mount the bare necesities
|
2019-09-18 03:50:27 +02:00
|
|
|
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)
|
2019-10-03 07:40:14 +02:00
|
|
|
echo ${ROOT_PARTUUID} > /dev/tty1
|
2019-09-18 03:50:27 +02:00
|
|
|
BLKID=$(/bin/blkid | grep $ROOT_PARTUUID )
|
2019-10-03 07:40:14 +02:00
|
|
|
echo ${BLKID} > /dev/tty1
|
|
|
|
#If its an mmcblk device, the kernel partiton will p1. If it is a usb device, the partiton will just be 1
|
|
|
|
#Just want everything before the 1
|
2019-09-18 03:50:27 +02:00
|
|
|
ROOT_DEV="${BLKID%1:*}"
|
|
|
|
|
2019-10-03 07:40:14 +02:00
|
|
|
echo ${ROOT_DEV} > /dev/tty1
|
2019-09-18 03:50:27 +02:00
|
|
|
|
2019-10-03 07:40:14 +02:00
|
|
|
# we can use this to change what cmdline options get passed into
|
|
|
|
# the next boot stage
|
2019-09-18 03:50:27 +02:00
|
|
|
CMDLINE='cat /proc/cmdline'
|
|
|
|
|
2019-10-13 00:39:17 +02:00
|
|
|
if [ -n "$(blkid ${ROOT_DEV}2 | grep crypto_LUKS)" ]
|
2019-09-30 03:16:30 +02:00
|
|
|
then
|
|
|
|
#decrypt and mount the root filesystem
|
2019-10-03 07:40:14 +02:00
|
|
|
echo "Opening encrypted root partition, this will take 30s..."
|
2019-10-13 00:39:17 +02:00
|
|
|
cryptsetup --tries 5 luksOpen ${ROOT_DEV}2 luksroot || rescue_shell
|
2019-09-30 03:16:30 +02:00
|
|
|
mount /dev/mapper/luksroot /newroot
|
|
|
|
else
|
|
|
|
# mount the unencrypted root filesystem
|
2019-10-03 07:40:14 +02:00
|
|
|
[ -d "/newroot" ] || mkdir -p /newroot
|
2019-10-13 00:39:17 +02:00
|
|
|
mount ${ROOT_DEV}2 /newroot
|
2019-09-30 03:16:30 +02:00
|
|
|
fi
|
2019-09-18 03:50:27 +02:00
|
|
|
|
|
|
|
umount /sys
|
|
|
|
umount /proc
|
2019-09-21 06:50:08 +02:00
|
|
|
|
2019-09-18 03:50:27 +02:00
|
|
|
#swith to the new rootfs
|
2019-10-03 07:40:14 +02:00
|
|
|
exec switch_root /newroot /sbin/init ${CMDLINE}
|