2020-05-09 11:00:02 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -x
|
|
|
|
set -e
|
2019-09-21 06:50:08 +02:00
|
|
|
|
|
|
|
#Build initramfs image
|
|
|
|
|
|
|
|
|
2020-06-15 23:27:21 +02:00
|
|
|
# This file is part of PrawnOS (https://www.prawnos.com)
|
2019-09-21 06:50:08 +02:00
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
|
|
|
|
outmnt=$(mktemp -d -p `pwd`)
|
|
|
|
outdev=/dev/loop7
|
2020-01-11 21:56:45 +01:00
|
|
|
if [ -z "$1" ]
|
|
|
|
then
|
|
|
|
echo "No base file system image filename supplied"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
BASE=$1
|
2019-09-21 06:50:08 +02:00
|
|
|
ROOT_DIR=`pwd`
|
|
|
|
build_resources=$ROOT_DIR/resources/BuildResources
|
|
|
|
|
2020-01-11 21:56:45 +01:00
|
|
|
if [ ! -f $ROOT_DIR/$BASE ]
|
2019-09-21 06:50:08 +02:00
|
|
|
then
|
|
|
|
echo "No base filesystem, run 'make filesystem' first"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#A hacky way to ensure the loops are properly unmounted and the temp files are properly deleted.
|
|
|
|
#Without this, a reboot is sometimes required to properly clean the loop devices and ensure a clean build
|
|
|
|
cleanup() {
|
|
|
|
set +e
|
|
|
|
|
|
|
|
umount -l $outmnt > /dev/null 2>&1
|
|
|
|
rmdir $outmnt > /dev/null 2>&1
|
|
|
|
losetup -d $outdev > /dev/null 2>&1
|
|
|
|
|
|
|
|
set +e
|
|
|
|
|
|
|
|
umount -l $outmnt > /dev/null 2>&1
|
|
|
|
rmdir $outmnt > /dev/null 2>&1
|
|
|
|
losetup -d $outdev > /dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup INT TERM EXIT
|
|
|
|
|
2019-10-03 07:40:14 +02:00
|
|
|
[ ! -d build ] && mkdir build
|
|
|
|
|
2020-01-11 21:56:45 +01:00
|
|
|
losetup -P $outdev $ROOT_DIR/$BASE
|
2019-09-21 06:50:08 +02:00
|
|
|
#mount the root filesystem
|
2019-10-15 15:59:40 +02:00
|
|
|
mount -o noatime ${outdev}p2 $outmnt
|
2019-09-21 06:50:08 +02:00
|
|
|
|
|
|
|
#make a skeleton filesystem
|
|
|
|
initramfs_src=$outmnt/InstallResources/initramfs_src
|
|
|
|
rm -rf $initramfs_src*
|
|
|
|
mkdir -p $initramfs_src
|
|
|
|
mkdir $initramfs_src/bin
|
|
|
|
mkdir $initramfs_src/dev
|
|
|
|
mkdir $initramfs_src/etc
|
|
|
|
mkdir $initramfs_src/newroot
|
2019-09-30 03:16:30 +02:00
|
|
|
mkdir $initramfs_src/boot
|
2019-09-21 06:50:08 +02:00
|
|
|
mkdir $initramfs_src/proc
|
|
|
|
mkdir $initramfs_src/sys
|
|
|
|
mkdir $initramfs_src/sbin
|
|
|
|
mkdir $initramfs_src/run
|
2019-10-03 07:40:14 +02:00
|
|
|
mkdir $initramfs_src/run/cryptsetup
|
2019-09-21 06:50:08 +02:00
|
|
|
mkdir $initramfs_src/lib
|
|
|
|
mkdir $initramfs_src/lib/arm-linux-gnueabihf
|
|
|
|
|
2020-03-05 07:15:36 +01:00
|
|
|
mknod -m 622 $initramfs_src/dev/console c 5 1
|
|
|
|
mknod -m 622 $initramfs_src/dev/tty c 4 0
|
2019-10-03 07:40:14 +02:00
|
|
|
|
2019-09-21 06:50:08 +02:00
|
|
|
#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/
|
|
|
|
|
2020-03-05 07:15:36 +01:00
|
|
|
cp $outmnt/usr/lib/arm-linux-gnueabihf/libpopt.so.0 $initramfs_src/lib/arm-linux-gnueabihf/libpopt.so.0
|
|
|
|
cp $outmnt/usr/lib/arm-linux-gnueabihf/libssl.so.1.1 $initramfs_src/lib/arm-linux-gnueabihf/libssl.so.1.1
|
|
|
|
cp $outmnt/usr/lib/arm-linux-gnueabihf/libcrypto.so.1.1 $initramfs_src/lib/arm-linux-gnueabihf/libcrypto.so.1.1
|
|
|
|
cp $outmnt/usr/lib/arm-linux-gnueabihf/libargon2.so.1 $initramfs_src/lib/arm-linux-gnueabihf/libargon2.so.1
|
|
|
|
cp $outmnt/usr/lib/arm-linux-gnueabihf/libjson-c.so.3 $initramfs_src/lib/arm-linux-gnueabihf/libjson-c.so.3
|
2019-09-30 03:16:30 +02:00
|
|
|
|
|
|
|
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/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/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/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
|
2019-10-03 07:40:14 +02:00
|
|
|
cp $outmnt/lib/arm-linux-gnueabihf/libgcc_s.so.1 $initramfs_src/lib/arm-linux-gnueabihf/libgcc_s.so.1
|
2019-09-21 06:50:08 +02:00
|
|
|
#add the init script
|
|
|
|
cp $build_resources/initramfs-init $initramfs_src/init
|
|
|
|
chmod +x $initramfs_src/init
|
2019-09-26 20:10:47 +02:00
|
|
|
cp $initramfs_src/init $initramfs_src/sbin/init
|
2019-09-21 06:50:08 +02:00
|
|
|
|
|
|
|
#compress and install
|
|
|
|
rm -rf $outmnt/boot/PrawnOS-initramfs.cpio.gz
|
|
|
|
cd $initramfs_src
|
|
|
|
ln -s busybox bin/cat
|
|
|
|
ln -s busybox bin/mount
|
|
|
|
ln -s busybox bin/sh
|
|
|
|
ln -s busybox bin/switch_root
|
|
|
|
ln -s busybox bin/umount
|
|
|
|
|
|
|
|
# store for kernel building
|
2019-10-03 07:40:14 +02:00
|
|
|
find . -print0 | cpio --null --create --verbose --format=newc | gzip --best > $ROOT_DIR/build/PrawnOS-initramfs.cpio.gz
|
|
|
|
|