Script for ChromeOS Flex to add cros_debug / dev mode option in grub.cfg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Script to add cros_debug / dev mode option in grub.cfg | |
### ( Each Flex update removes cros_debug / dev mode option | |
### Be sure to run this script AFTER each update and BEFORE rebooting ) | |
ANS= | |
ROOTDEVICE= | |
ROOTDEVICEPREFIX= | |
P12MOUNTPOINT=/var/p12 | |
GRUBCFGPATH=$P12MOUNTPOINT/efi/boot | |
GRUBCFGFILE=grub.cfg | |
# Exits the script with return code $1, spitting out message $@ to stderr | |
error() { | |
local ecode="$1" | |
shift | |
echo "$*" 1>&2 | |
return "$ecode" | |
} | |
# Find the root device | |
# Sets: | |
# - $ROOTDEVICE as the root device (e.g. /dev/sda or /dev/mmcblk0) | |
# - $ROOTDEVICEPREFIX as a prefix for partitions (/dev/sda, /dev/mmcblk0p) | |
findrootdevice() { | |
ROOTDEVICE="`rootdev -d -s`" | |
if [ -z "$ROOTDEVICE" ]; then | |
error 1 "Cannot find root device." | |
fi | |
if [ ! -b "$ROOTDEVICE" ]; then | |
error 1 "$ROOTDEVICE is not a block device." | |
fi | |
# If $ROOTDEVICE ends with a number (e.g. mmcblk0), partitions are named | |
# ${ROOTDEVICE}pX (e.g. mmcblk0p1). If not (e.g. sda), they are named | |
# ${ROOTDEVICE}X (e.g. sda1). | |
ROOTDEVICEPREFIX="$ROOTDEVICE" | |
if [ "${ROOTDEVICE%[0-9]}" != "$ROOTDEVICE" ]; then | |
ROOTDEVICEPREFIX="${ROOTDEVICE}p" | |
fi | |
} | |
findrootdevice | |
if [ ! -d $P12MOUNTPOINT ]; then | |
# Make mountpoint | |
echo "Making directory to mount partition 12" | |
sudo mkdir -p $P12MOUNTPOINT | |
elif [ ! -d $GRUBCFGPATH ]; then | |
# Mount EFI partition | |
echo "Mounting ${ROOTDEVICEPREFIX}12 on $P12MOUNTPOINT" | |
sudo mount ${ROOTDEVICEPREFIX}12 $P12MOUNTPOINT | |
fi | |
# Check for cros_debug option, need 5 | |
DEBUGCOUNT="$(grep 'cros_efi cros_debug' $GRUBCFGPATH/$GRUBCFGFILE | wc -l)" | |
if [ "$DEBUGCOUNT" -eq 5 ]; then | |
echo "cros_debug has been added to $GRUBCFGFILE, no changes needed." | |
exit | |
fi | |
# grub.cfg needs editing | |
echo "Editing $GRUBCFGFILE to add 'cros_debug' option." | |
echo " | |
PLEASE NOTE: | |
I claim no responsibility for any damage or harm that may occur to your | |
device as a result of running this script. PROCEED AT YOR OWN RISK. | |
" | |
echo -n "[ press ENTER to continue - Ctrl-C to abort ] "; read ANS | |
cp $GRUBCFGPATH/$GRUBCFGFILE /tmp | |
# vi /tmp/$GRUBCFGFILE | |
sed -e 's/cros_efi /cros_efi cros_debug /' -e 's/cros_efi root/cros_efi cros_debug root/' /tmp/$GRUBCFGFILE | |
sudo cp $GRUBCFGPATH/$GRUBCFGFILE $GRUBCFGPATH/${GRUBCFGFILE}.bak | |
sudo cp /tmp/$GRUBCFGFILE $GRUBCFGPATH/ | |
echo "Done, you can reboot now." | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment