Skip to content

Instantly share code, notes, and snippets.

@ThinGuy
Last active November 22, 2022 15:00
Show Gist options
  • Save ThinGuy/d2672d6b1eafa4e07ebf985587675a2c to your computer and use it in GitHub Desktop.
Save ThinGuy/d2672d6b1eafa4e07ebf985587675a2c to your computer and use it in GitHub Desktop.
Modify ChromeOS Recovery Media to just run a script to put ChromeBook back in dev mode and enable legacy USB booting. Workaround for Issue 362105 (https://crbug.com/362105)
#!/bin/bash
###NOTE###
# This requires:
# 1) ChromeOS Recovery Media for your machine (see https://bit.ly/makechromeos-media)
# 2) A separate linux machine to alter the ChromeOS recovery media
# 99.999% of this script was lifted wholesale from http://bit.ly/2oFvluu
# This just automtes the manual parts in the guidance provided
#
# Workaround for Issue 362105 (https://crbug.com/362105)
# If you've completely replaced or disabled Chrome OS and your ChromeBook battery runs all
# the way down, the USB Legacy Boot flag (stored in NVRAM) is lost, thereby locking you out
# of your own device.
#
# If this happens to you, make ChromeOS recovery Media (see https://bit.ly/makechromeos-media),
# then use this script to renable dev-mode and legacy USB booting without wiping the
# non-Chrome OS that you installed.
#
# Grab https://bit.ly/makechromeos-media to make ChromeOS Recovery media from a linux computer.
# OR
# Make Recovery media by install the ChromeOS Recovery extension (https://www.google.com/chromeos/recovery)
# in Chrome a chrome browser and make the Recovery media with the Web tool.
clear
printf "\e[2G\e[1mWorkaround for Issue 362105\e[0m ( see: https://crbug.com/362105 )\n\n"
printf "\e[2G\e[1mAlter ChromeOS Recovery media to put CB back in dev-mode\n\e[2Gand enable USB legacy booting\e[0m\n\n"
printf "\e[2G - Do the double beeps after CTRL+L got you down?\n\n"
printf "\e[2G - Did you know the CTL+L flag is stored in NVRAM, which\n\e[5Gmeans you lose it when the battery completely dies?\n\n"
printf "\e[2G - Worried that the spiffy new linux that you installed\n\e[5Gon your ChromeBook is gone?\n\n"
printf "\e[2G - Don't fret fam, we got you! \n\n\n"
read -p "$(printf "\e[2G\e[1mPlease ensure that your ChromeOS Recovery USB media is plugged in\n\e[2Gthen hit \e[1;36mENTER\e[0m (or ctrl+c to quit): ")" CONT
is_ext2() {
local rootfs="$1"
local offset="${2-0}"
printf "\e[2G - Making sure we are working on a ext2 image...\n\n"
# Make sure we're checking an ext2 image
local sb_magic_offset=$((0x438))
local sb_value=$(sudo dd if="$rootfs" skip=$((offset + sb_magic_offset)) \
count=2 bs=1 2>/dev/null)
local expected_sb_value=$(printf '\123\357')
if [ "$sb_value" = "$expected_sb_value" ]; then
return 0
fi
return 1
}
enable_rw_mount() {
local rootfs="$1"
local offset="${2-0}"
# Make sure we're checking an ext2 image
if ! is_ext2 "$rootfs" $offset; then
echo "enable_rw_mount called on non-ext2 filesystem: $rootfs $offset" 1>&2
return 1
fi
printf "\e[2G - Clearing unsupported ext2 flags so we can mount and alter ChromeOS Recovery disk...\n\n"
local ro_compat_offset=$((0x464 + 3)) # Set 'highest' byte
# Dash can't do echo -ne, but it can do printf "\NNN"
# We could use /dev/zero here, but this matches what would be
# needed for disable_rw_mount (printf '\377').
printf '\000' |
sudo dd of="$rootfs" seek=$((offset + ro_compat_offset)) conv=notrunc count=1 bs=1 2>/dev/null
[[ $? -eq 0 ]] && return 0 || return 1
}
unset DISK OFFSET
DISK=$(readlink 2>/dev/null -f /dev/disk/by-label/ROOT-A)
OFFSET=$(sudo parted 2>/dev/null -s ${DISK%[0-9]} unit B print|awk '/^ 3/{gsub(/B/,"",$2);print $2}')
if [[ -n ${DISK} && -n ${OFFSET} ]];then
printf "\n\n\e[2G\e[1mFound ChromeOS Recovery media on ${DISK%[0-9]}\e[0m\n\n"
else
printf "\n\n\e[2G\e[1;31mERROR: \e[0mCould not determine device name or offset of recovery disk. Exiting.\n\n"
exit 1
fi
enable_rw_mount ${DISK%[0-9]} ${OFFSET}
[[ $? -eq 0 ]] || { printf "\n\n\e[2G\e[1;31mERROR:\e[0m Function \"enable_rw_mount\" failed. Exiting.\n\n";exit 1; }
printf "\e[2G - Creating temporary directory ~/rmnt to mount ChromeOSRecovery media...\n\n"
mkdir -p ~/rmnt
printf "\e[2G - Mounting ${DISK} @ ~/rmnt...\n\n"
sudo mount ${DISK} ~/rmnt
printf "\e[2G - Replacing chromeos-install script...\n\n"
cat <<EOF|sudo tee 1>/dev/null ~/rmnt/usr/sbin/chromeos-install
#!/bin/bash
crossystem dev_boot_legacy=1 dev_boot_usb=1
sleep 5
exit
EOF
printf "\e[2G - Making new chromeos-install script executable...\n\n"
sudo chmod +x ~/rmnt/usr/sbin/chromeos-install
printf "\e[2G - Printing new chromeos-install script...\n\n"
cat ~/rmnt/usr/sbin/chromeos-install
printf "\n\e[2G - Listing file properties of new chromeos-install script...\n\n"
ls -altr ~/rmnt/usr/sbin/chromeos-install
cd ~
printf "\e[2G - Unmounting ~/rmnt...\n\n"
sudo umount ~/rmnt
if [[ $? -eq 0 ]];then
printf "\e[2G - Deleting temporary directory ~/rmnt...\n\n"
sudo rm -rf ~/rmnt
printf "\e[2G - Ejecting ${DISK%[0-9]}...\n\n"
sudo eject ${DISK%[0-9]}
printf "\n\n\e[2G\e[1mChromeOS Recovery media has been altered successfully! \e[0m\n\n"
printf "\e[2G - Please boot this media in recovery mode (ESC + Refresh + Power)\n\e[5Gto renable dev mode and legacy booting\n\n"
printf "\e[2G - Do not panic when System Recovery runs, it will run the modified\n\e[5Gscript instead reinstalling ChromeOS\n\n"
printf "\e[2G - Once it completes, remove the media\n\n"
printf '\e[2G - After your Chromebook reboots, CTRL+L and CTRL+U should work again (yay!) n\n\n'
exit 0
else
printf "\n\e[2G\e[1;31mERROR:\e[0m Unmounting of ~/rmnt failed. Exiting.\n\n"
exit 1
fi
@ThinGuy
Copy link
Author

ThinGuy commented Sep 5, 2018

Workaround for Issue 362105 (https://crbug.com/362105)
If you've completely replaced or disabled Chrome OS and your ChromeBook battery runs all
the way down, the USB Legacy Boot flag (stored in NVRAM) is lost, thereby locking you out
of your own device.

This will affect a lot of users with newer chromebooks
Starting with Apollo Lake, the write-protect screw/jumper is now a battery pin, which means you have to remove the battery to disable WP mode. Some Chromebooks refuse to boot with just the AC connected and the battery disconnected.

There's hideous, er, tedious fix (listed in in the bug) to move the legacy boot flag out of NV RAM, but it appears to 1) be for Pixels, and 2) a major PITA. This is far easier.

If this happens to you, make ChromeOS recovery Media (see https://bit.ly/makechromeos-media),
then use this script to renable dev-mode and legacy USB booting without wiping the
non-Chrome OS that you installed.

Chromebook Linux
CTRL+L double beep
Chromebook Linux no longer boots
Apollo Lake ChromeOS missing or damaged
Acer CB515-1HT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment