try to swich_root into the rootfs

This commit is contained in:
ading2210 2023-10-03 23:56:57 -07:00
parent b7ce81f3bd
commit e8d73c03a0
3 changed files with 53 additions and 9 deletions

View File

@ -1,3 +1,10 @@
# Chrome OS RMA Shim Bootloader
This is a set of scripts for patching a Chrome OS RMA shim to serve as a bootloader for a standard Linux disto.
## Current Development Roadmap:
- ~~build the image automatically~~
- ~~boot to a shell~~
- switch_root into an actual rootfs
- start X11 in the actual rootfs
- ui improvements in the bootloader

View File

@ -38,16 +38,56 @@ find_rootfs_partitions() {
if [ ! "${partitions}" ]; then
continue
fi
echo $partitions
echo "${disk}${partitions}"
done
}
#from original bootstrap.sh
move_mounts() {
local BASE_MOUNTS="/sys /proc /dev"
local NEWROOT_MNT="$1"
for mnt in $BASE_MOUNTS; do
# $mnt is a full path (leading '/'), so no '/' joiner
mkdir -p "$NEWROOT_MNT$mnt"
mount -n -o move "$mnt" "$NEWROOT_MNT$mnt"
done
}
#from original bootstrap.sh
use_new_root() {
local NEWROOT_MNT="$1"
move_mounts $NEWROOT_MNT
# Chroot into newroot, erase the contents of the old /, and exec real init.
echo "About to switch root... Check VT2/3/4 if you stuck for a long time."
# If you have problem getting console after switch_root, try to debug by:
# 1. Try a simple shell.
# exec <"${TTY}" >"${TTY}" 2>&1
# exec switch_root "${NEWROOT_MNT}" /bin/sh
# 2. Try to invoke factory installer directly
# exec switch_root "${NEWROOT_MNT}" /usr/sbin/factory_shim_service.sh
# -v prints upstart info in kmsg (available in INFO_TTY).
exec switch_root "${NEWROOT_MNT}" /sbin/init
}
main() {
echo "...:::||| Bootstrapping ChromeOS Factory Shim |||:::..."
echo "TTY: ${TTY}, LOG: ${LOG_TTY}, echo: ${echo_TTY}, DEBUG: ${DEBUG_TTY}"
echo "idk please work"
find_rootfs_partitions
sleep 5
local rootfs_partitions=$(find_rootfs_partitions)
for rootfs_partition in $rootfs_partitions; do
local IFS=: read -r part_path part_name <<< $rootfs_partition
echo "found bootable partition ${part_path}: ${part_name}"
done
sleep 5
mkdir /newroot
mount /dev/sda4 /newroot
use_new_root /newroot
enable_debug_console "/dev/pts/0"
}

View File

@ -11,7 +11,7 @@ fi
. ./build_image.sh
print_help() {
echo "Usage: ./build.sh output_path shim_path"
echo "Usage: ./build.sh output_path shim_path rootfs_dir"
}
check_deps() {
@ -43,6 +43,7 @@ fi
output_path=$(realpath "${1}")
shim_path=$(realpath "${2}")
rootfs_dir=$(realpath "${3}")
echo "created loop device for shim"
shim_loop=$(create_loop "${shim_path}")
@ -87,7 +88,7 @@ echo "patching initramfs"
patch_initramfs $initramfs_dir
echo "creating disk image"
create_image $output_path 20 200
create_image $output_path 20 1200
echo "creating loop device for the image"
image_loop=$(create_loop ${output_path})
@ -96,10 +97,6 @@ echo "creating partitions on the disk image"
create_partitions $image_loop "${kernel_dir}/kernel.bin"
echo "copying data into the image"
rootfs_dir=/tmp/rootfs
rm $rootfs_dir -rf
mkdir $rootfs_dir
touch $rootfs_dir/testfile
populate_partitions $image_loop $initramfs_dir $rootfs_dir
echo "cleaning up loop devices"