shimboot/build_squashfs.sh

68 lines
1.6 KiB
Bash
Raw Normal View History

#!/bin/bash
#build a rootfs that uses a squashfs + unionfs
#consists of a minimal busybox system containing:
# - FUSE kernel modules from the shim
# - unionfs-fuse statically compiled
# - the main squashfs, compressed with gzip
2023-12-21 01:48:32 -05:00
set -e
if [ "$DEBUG" ]; then
set -x
fi
. ./common.sh
2023-12-21 01:48:32 -05:00
. ./image_utils.sh
. ./shim_utils.sh
print_help() {
echo "Usage: ./build_squashfs.sh rootfs_dir uncompressed_rootfs_dir path_to_shim"
}
assert_root
assert_deps "git make gcc binwalk pcregrep"
assert_args "$3"
2023-12-21 01:48:32 -05:00
compile_unionfs() {
local out_path="$1"
local working_path="$2"
local repo_url="https://github.com/rpodgorny/unionfs-fuse"
local original_dir="$(pwd)"
2023-12-22 01:51:47 -05:00
local core_count="$(nproc --all)"
2023-12-21 01:48:32 -05:00
rm -rf $working_path
git clone $repo_url -b master --depth=1 $working_path
cd $working_path
env LDFLAGS="-static" CFLAGS="-O3" make -j$core_count
2023-12-21 01:48:32 -05:00
local binary_path="$working_path/src/unionfs"
cp $binary_path $out_path
2023-12-22 01:51:47 -05:00
cd $original_dir
2023-12-21 01:48:32 -05:00
}
2024-01-25 16:19:25 -05:00
rootfs_dir=$(realpath -m $1)
old_dir=$(realpath -m $2)
shim_path=$(realpath -m $3)
2023-12-21 01:48:32 -05:00
shim_rootfs="/tmp/shim_rootfs"
2023-12-21 19:58:08 -05:00
root_squashfs="$rootfs_dir/root.squashfs"
modules_squashfs="$rootfs_dir/modules.squashfs"
unionfs_dir="/tmp/unionfs-fuse"
2023-12-21 01:48:32 -05:00
print_info "compiling unionfs-fuse"
2023-12-21 19:58:08 -05:00
compile_unionfs $unionfs_dir/unionfs $unionfs_dir
2023-12-21 01:48:32 -05:00
print_info "reading the shim image"
extract_initramfs_full $shim_path $rootfs_dir
2023-12-21 19:58:08 -05:00
rm -rf $rootfs_dir/init
print_info "compressing old rootfs"
2023-12-21 19:58:08 -05:00
mksquashfs $old_dir $root_squashfs -noappend -comp gzip
2023-12-21 01:48:32 -05:00
print_info "patching new rootfs"
2023-12-21 19:58:08 -05:00
mv $unionfs_dir/unionfs $rootfs_dir/bin/unionfs
2023-12-22 01:51:47 -05:00
cp -ar squashfs/* $rootfs_dir/
chmod +x $rootfs_dir/bin/*
2023-12-21 01:48:32 -05:00
print_info "done"