Addcryptsetup to initramfs, add debug flag

This commit is contained in:
Hal Emmerich 2019-09-29 20:16:30 -05:00
parent 69c91abbd2
commit 01ef15d1a0
3 changed files with 46 additions and 43 deletions

View File

@ -1,8 +1,13 @@
#!/bin/busybox sh #!/bin/busybox sh
echo In PrawnOS Init 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 >/dev/tty1 2>&1'
}
cmdline() { cmdline() {
local value local value
value=" $(cat /proc/cmdline) " value=" $(cat /proc/cmdline) "
@ -36,21 +41,32 @@ ROOT_DEV="${BLKID%1:*}"
echo ${ROOT_DEV} echo ${ROOT_DEV}
#uncomment for debugging
# exec setsid /bin/sh -c 'exec /bin/sh </dev/tty1 >/dev/tty1 2>&1'
# we use this to change what cmdline options get passed into # we use this to change what cmdline options get passed into
# the next boot stage, aka to enable root encryption # the next boot stage, aka to enable root encryption
CMDLINE='cat /proc/cmdline' CMDLINE='cat /proc/cmdline'
# mount new root [ -d /boot ] || mkdir -p /boot
[ -d /newroot ] || mkdir -p /newroot mount ${ROOT_DEV}2 /boot
mount ${ROOT_DEV}3 /newroot
#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 /sys
umount /proc umount /proc
# exec setsid /bin/sh -c 'exec /bin/sh </dev/tty1 >/dev/tty1 2>&1'
#swith to the new rootfs #swith to the new rootfs
exec switch_root /newroot /sbin/init ${CMDLINE} exec switch_root /newroot /sbin/init ${CMDLINE}

View File

@ -163,41 +163,6 @@ chroot $outmnt locale-gen
chroot $outmnt apt update chroot $outmnt apt update
chroot $outmnt apt install -y initscripts udev kmod net-tools inetutils-ping traceroute iproute2 isc-dhcp-client wpasupplicant iw alsa-utils cgpt vim-tiny less psmisc netcat-openbsd ca-certificates bzip2 xz-utils ifupdown nano apt-utils git kpartx gdisk parted rsync busybox-static cryptsetup chroot $outmnt apt install -y initscripts udev kmod net-tools inetutils-ping traceroute iproute2 isc-dhcp-client wpasupplicant iw alsa-utils cgpt vim-tiny less psmisc netcat-openbsd ca-certificates bzip2 xz-utils ifupdown nano apt-utils git kpartx gdisk parted rsync busybox-static cryptsetup
#make the initramfs image that gets copied to partiton 2
#this is not yet fully funtional, needs the kernel parts which are
#added in "injectKernelIntoFS.sh"
#make a skeleton filesystem
initramfs_src=$outmnt/InstallResources/initramfs_src
mkdir -p $initramfs_src
mkdir $initramfs_src/bin
mkdir $initramfs_src/dev
mkdir $initramfs_src/etc
mkdir $initramfs_src/newroot
mkdir $initramfs_src/proc
mkdir $initramfs_src/sys
mkdir $initramfs_src/sbin
mkdir $initramfs_src/run
mkdir $initramfs_src/lib
mkdir $initramfs_src/lib/arm-linux-gnueabihf
#install the few tools we need, and the supporting libs
cp $outmnt/bin/busybox $outmnt/sbin/cryptsetup $initramfs_src/bin/
cp $outmnt/lib/arm-linux-gnueabihf/libblkid.so.1 $initramfs_src/lib/arm-linux-gnueabihf/
cp $outmnt/lib/arm-linux-gnueabihf/libuuid.so.1 $initramfs_src/lib/arm-linux-gnueabihf/
cp $outmnt/lib/arm-linux-gnueabihf/libc.so.6 $initramfs_src/lib/arm-linux-gnueabihf/
cp $outmnt/lib/ld-linux-armhf.so.3 $initramfs_src/lib/
cp $outmnt/sbin/blkid $initramfs_src/bin/
#add the init script
cp $build_resources/initramfs-init $initramfs_src/init
chmod +x $initramfs_src/init
#compress and install
find $initramfs_src -print0 | cpio --null --create --verbose --format=newc | gzip --best > $outmnt/boot/PrawnOS-initramfs.cpio.gz
#add the live-boot fstab #add the live-boot fstab
cp -f $build_resources/external_fstab $outmnt/etc/fstab cp -f $build_resources/external_fstab $outmnt/etc/fstab
chmod 644 /etc/fstab chmod 644 /etc/fstab

View File

@ -64,6 +64,7 @@ mkdir $initramfs_src/bin
mkdir $initramfs_src/dev mkdir $initramfs_src/dev
mkdir $initramfs_src/etc mkdir $initramfs_src/etc
mkdir $initramfs_src/newroot mkdir $initramfs_src/newroot
mkdir $initramfs_src/boot
mkdir $initramfs_src/proc mkdir $initramfs_src/proc
mkdir $initramfs_src/sys mkdir $initramfs_src/sys
mkdir $initramfs_src/sbin mkdir $initramfs_src/sbin
@ -80,6 +81,27 @@ cp $outmnt/lib/arm-linux-gnueabihf/libc.so.6 $initramfs_src/lib/arm-linux-gnueab
cp $outmnt/lib/ld-linux-armhf.so.3 $initramfs_src/lib/ cp $outmnt/lib/ld-linux-armhf.so.3 $initramfs_src/lib/
cp $outmnt/sbin/blkid $initramfs_src/bin/ cp $outmnt/sbin/blkid $initramfs_src/bin/
cp $outmnt/usr/sbin/cryptsetup $initramfs_src/bin/
cp $outmnt/lib/arm-linux-gnueabihf/libm.so.6 $initramfs_src/lib/arm-linux-gnueabihf/libm.so.6
cp $outmnt/lib/arm-linux-gnueabihf/libcryptsetup.so.12 $initramfs_src/lib/arm-linux-gnueabihf/libcryptsetup.so.12
cp $outmnt/lib/arm-linux-gnueabihf/libpopt.so.0 $initramfs_src/lib/arm-linux-gnueabihf/libpopt.so.0
cp $outmnt/lib/arm-linux-gnueabihf/libuuid.so.1 $initramfs_src/lib/arm-linux-gnueabihf/libuuid.so.1
cp $outmnt/lib/arm-linux-gnueabihf/libblkid.so.1 $initramfs_src/lib/arm-linux-gnueabihf/libblkid.so.1
cp $outmnt/lib/arm-linux-gnueabihf/libc.so.6 $initramfs_src/lib/arm-linux-gnueabihf/libc.so.6
cp $outmnt/lib/ld-linux-armhf.so.3 $initramfs_src/lib/ld-linux-armhf.so.3
cp $outmnt/lib/arm-linux-gnueabihf/libdevmapper.so.1.02.1 $initramfs_src/lib/arm-linux-gnueabihf/libdevmapper.so.1.02.1
cp $outmnt/lib/arm-linux-gnueabihf/libssl.so.1.1 $initramfs_src/lib/arm-linux-gnueabihf/libssl.so.1.1
cp $outmnt/lib/arm-linux-gnueabihf/libcrypto.so.1.1 $initramfs_src/lib/arm-linux-gnueabihf/libcrypto.so.1.1
cp $outmnt/lib/arm-linux-gnueabihf/libargon2.so.1 $initramfs_src/lib/arm-linux-gnueabihf/libargon2.so.1
cp $outmnt/lib/arm-linux-gnueabihf/librt.so.1 $initramfs_src/lib/arm-linux-gnueabihf/librt.so.1
cp $outmnt/lib/arm-linux-gnueabihf/libdl.so.2 $initramfs_src/lib/arm-linux-gnueabihf/libdl.so.2
cp $outmnt/lib/arm-linux-gnueabihf/libjson-c.so.3 $initramfs_src/lib/arm-linux-gnueabihf/libjson-c.so.3
cp $outmnt/lib/arm-linux-gnueabihf/libselinux.so.1 $initramfs_src/lib/arm-linux-gnueabihf/libselinux.so.1
cp $outmnt/lib/arm-linux-gnueabihf/libudev.so.1 $initramfs_src/lib/arm-linux-gnueabihf/libudev.so.1
cp $outmnt/lib/arm-linux-gnueabihf/libpthread.so.0 $initramfs_src/lib/arm-linux-gnueabihf/libpthread.so.0
cp $outmnt/lib/arm-linux-gnueabihf/libpcre.so.3 $initramfs_src/lib/arm-linux-gnueabihf/libpcre.so.3
#add the init script #add the init script
cp $build_resources/initramfs-init $initramfs_src/init cp $build_resources/initramfs-init $initramfs_src/init
chmod +x $initramfs_src/init chmod +x $initramfs_src/init