partially working pivot_root into chrome os

This commit is contained in:
ading2210 2023-11-05 02:02:29 -08:00
parent 5cac377c71
commit cd493864ec
2 changed files with 56 additions and 3 deletions

View File

@ -167,6 +167,37 @@ get_selection() {
return 1 return 1
} }
contains_word() {
local substr="$1"
local str="$2"
for word in $str; do
if [ "$word" = "$substr" ]; then
return 0
fi
done
return 1
}
#might be useful in case we need to disable the tpm
#currently this causes a kernel panic when we try to boot cros
unbind_driver() {
local driver_path="$1"
local sys_files="$(ls $driver_path)"
local excluded_files="bind uevent unbind"
for file in $sys_files; do
if ! contains_word "$file" "$excluded_files"; then
echo "$file" > "${driver_path}/unbind"
fi
done
}
unbind_tpm() {
unbind_driver "/sys/bus/spi/drivers/tpm_tis_spi"
unbind_driver "/sys/bus/pnp/drivers/tpm_tis"
unbind_driver "/sys/bus/platform/drivers/tpm_tis"
}
boot_target() { boot_target() {
local target="$1" local target="$1"
@ -183,8 +214,30 @@ boot_target() {
} }
boot_chromeos() { boot_chromeos() {
echo "not implemented yet :(" local target="$1"
echo "WARNING: this functionality is unfinished and you will only get a bash shell"
echo "starting the init system currently does not work and will cause it to hang"
sleep 5 sleep 5
echo "mounting target"
mkdir /newroot
mount -o ro $target /newroot
echo "mounting tmpfs"
mount -t tmpfs -o mode=1777 none /newroot/tmp
mount -t tmpfs -o mode=0555 run /newroot/run
mkdir -p -m 0755 /newroot/run/lock
echo "moving mounts"
move_mounts /newroot
echo "switching root"
sleep 5
mkdir -p /newroot/tmp/bootloader
pivot_root /newroot /newroot/tmp/bootloader
local tty="/dev/pts/0"
exec /bin/bash < "$tty" >> "$tty" 2>&1
} }
main() { main() {

View File

@ -47,7 +47,7 @@
│ Chrome OS RMA Shim Bootloader │ │ Chrome OS RMA Shim Bootloader │
└───────────────────────────────┘ └───────────────────────────────┘
<a href="#info" style="text-decoration: none;">1) Info</a> <a href="#info" style="text-decoration: none;">1) Info</a>
<a href="#explaination" style="text-decoration: none;">2) Explanation</a> <a href="#explanation" style="text-decoration: none;">2) Explanation</a>
<a href="#prebuilt" style="text-decoration: none;">3) Prebuilt Images</a> <a href="#prebuilt" style="text-decoration: none;">3) Prebuilt Images</a>
<a href="#build" style="text-decoration: none;">4) Build Instructions</a> <a href="#build" style="text-decoration: none;">4) Build Instructions</a>
<a href="#usage" style="text-decoration: none;">5) Usage</a> <a href="#usage" style="text-decoration: none;">5) Usage</a>
@ -58,7 +58,7 @@ For more detailed information, please see the project's <a href="https://github.
<b id="info">Info:</b> <b id="info">Info:</b>
Shimboot is a collection of scripts for patching a Chrome OS RMA shim to serve as a bootloader for a standard Linux distribution. It allows you to boot a full desktop Debian install on a Chromebook, without needing to unenroll it or modify the firmware. Shimboot is a collection of scripts for patching a Chrome OS RMA shim to serve as a bootloader for a standard Linux distribution. It allows you to boot a full desktop Debian install on a Chromebook, without needing to unenroll it or modify the firmware.
<b id="info">Explanation:</b> <b id="explanation">Explanation:</b>
Chrome OS RMA shims are bootable disk images which are designed to run a variety of diagnostic utilities on Chromebooks, and they'll work even if the device is enterprise enrolled. Unfortunately for Google, there exists a <a href="https://sh1mmer.me/">security flaw</a> in which the root filesystem of the RMA shim is not verified. This lets us replace the rootfs with anything we want, including a full Linux distribution. Chrome OS RMA shims are bootable disk images which are designed to run a variety of diagnostic utilities on Chromebooks, and they'll work even if the device is enterprise enrolled. Unfortunately for Google, there exists a <a href="https://sh1mmer.me/">security flaw</a> in which the root filesystem of the RMA shim is not verified. This lets us replace the rootfs with anything we want, including a full Linux distribution.
Simply replacing the shim's rootfs doesn't work, however, as it boots to an environment friendly to the RMA shim, not regular Linux distros. To get around this, a separate bootloader is required to transition from the shim environment to the main rootfs. This bootloader then does a <a href="https://man7.org/linux/man-pages/man8/pivot_root.8.html">pivot_root</a> to enter the rootfs, where it runs the init system. Simply replacing the shim's rootfs doesn't work, however, as it boots to an environment friendly to the RMA shim, not regular Linux distros. To get around this, a separate bootloader is required to transition from the shim environment to the main rootfs. This bootloader then does a <a href="https://man7.org/linux/man-pages/man8/pivot_root.8.html">pivot_root</a> to enter the rootfs, where it runs the init system.