patch shim initramfs

This commit is contained in:
ading2210 2023-10-01 23:08:31 -07:00
parent 77b9e1a9c9
commit fc4c6b5e51
4 changed files with 93 additions and 1 deletions

44
bootloader/bootstrap.sh Normal file
View File

@ -0,0 +1,44 @@
#!/bin/busybox sh
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# To bootstrap the factory installer on rootfs. This file must be executed as
# PID=1 (exec).
# Note that this script uses the busybox shell (not bash, not dash).
#original: https://chromium.googlesource.com/chromiumos/platform/initramfs/+/refs/heads/main/factory_shim/bootstrap.sh
set +x
invoke_terminal() {
local tty="$1"
local title="$2"
shift
shift
# Copied from factory_installer/factory_shim_service.sh.
echo "${title}" >>${tty}
setsid sh -c "exec script -afqc '$*' /dev/null <${tty} >>${tty} 2>&1 &"
}
enable_debug_console() {
local tty="$1"
info -e '\033[1;33m[cros_debug] enabled on '${tty}'.\033[m'
invoke_terminal "${tty}" "[Bootstrap Debug Console]" "/bin/busybox sh"
}
main() {
# Setup environment.
#kill_frecon
#tty_init
info "...:::||| Bootstrapping ChromeOS Factory Shim |||:::..."
info "TTY: ${TTY}, LOG: ${LOG_TTY}, INFO: ${INFO_TTY}, DEBUG: ${DEBUG_TTY}"
echo "idk please work"
enable_debug_console "/dev/pts/0"
}
main "$@"
sleep 1d

30
bootloader/init.sh Normal file
View File

@ -0,0 +1,30 @@
#!/bin/busybox sh
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# /init script for use in factory install shim.
# Note that this script uses the busybox shell (not bash, not dash).
#original: https://chromium.googlesource.com/chromiumos/platform/initramfs/+/refs/heads/main/factory_shim/init
set -x
. /lib/init.sh
setup_environment() {
initialize
# Install additional utility programs.
/bin/busybox --install /bin || true
}
main() {
setup_environment
# In case an error is not handled by bootstrapping, stop here
# so that an operator can see installation stop.
exec bootstrap.sh || sleep 1d
}
main "$@"
exit 1

View File

@ -56,10 +56,13 @@ echo "extracting initramfs cpio archive"
initramfs_dir=/tmp/shim_initramfs initramfs_dir=/tmp/shim_initramfs
rm -rf $initramfs_dir rm -rf $initramfs_dir
cat $cpio_file | cpio -D $initramfs_dir -imd --quiet cat $cpio_file | cpio -D $initramfs_dir -imd --quiet
echo "shim initramfs extracted to ${initramfs_dir}" echo "shim initramfs extracted to ${initramfs_dir}"
#leave /tmp
cd $previous_dir cd $previous_dir
echo "patching initramfs"
exec ./patch_initramfs.sh $initramfs_dir
echo "cleaning up loop devices" echo "cleaning up loop devices"
losetup -d $shim_loop losetup -d $shim_loop

15
patch_initramfs.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
#patch the shim initramfs to add the bootloader
set -e
if [ "$DEBUG" ]; then
set -x
fi
initramfs_path=$(realpath $1)
rm "${initramfs_path}/init" -f
cp bootloader/init.sh "${initramfs_path}/sbin/init"
cp bootloader/bootstrap.sh "${initramfs_path}/sbin/bootstrap.sh"
chmod +x "${initramfs_path}/sbin/*.sh"