Skip to content

Instantly share code, notes, and snippets.

@DennisLfromGA
Created April 19, 2014 02:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save DennisLfromGA/11072037 to your computer and use it in GitHub Desktop.
Save DennisLfromGA/11072037 to your computer and use it in GitHub Desktop.
A Chromebook init script to mount the CROUTON partition - made possible via @drinkcat's crouton/separate_partition branch
# Copyright (c) 2012 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.
description "mount CROUTON on /var/crouton"
author "drinkcat & DennisLfromGA"
start on starting boot-services
task
script
# Exits the script with return code $1, spitting out message $@ to stderr
error() {
local ecode="$1"
shift
echo "$*" 1>&2
exit "$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
}
# Define CROUTON mountpoint
MOUNTCROUTON='/var/crouton'
# Try to mount the CROUTON partition, if it exists, on $MOUNTCROUTON.
mountcrouton() {
if [ -z "$ROOTDEVICE" ]; then
findrootdevice
fi
local croutonpart="`sudo cgpt find -n -l CROUTON "$ROOTDEVICE"`"
if [ -z "$croutonpart" ]; then
return 1
fi
# Check if crouton is mounted already
if grep -q "^${ROOTDEVICEPREFIX}$croutonpart " /proc/mounts; then
# If mounted, it must be mounted to $mountpoint
if ! grep -q "^${ROOTDEVICEPREFIX}$croutonpart $MOUNTCROUTON " \
/proc/mounts; then
error 1 "Error: CROUTON partition is not mounted on $MOUNTCROUTON."
else
PRIOR=' already'
fi
else
sudo mkdir -p "$MOUNTCROUTON" || error 1 "Cannot create $MOUNTCROUTON."
sudo mount "${ROOTDEVICEPREFIX}$croutonpart" "$MOUNTCROUTON" || \
error 1 "Cannot mount $MOUNTCROUTON"
fi
return 0
}
# Now mount the CROUTON partition
mountcrouton
end script
@DennisLfromGA
Copy link
Author

For starting a crouton chroot auto-magically without entering the shell, see companion file crouton.conf.

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