# 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 CHRUBUNTU on /mnt/ChrUbuntu-sda7"
author "DennisLfromGA@github.com & drinkcat@github.com"
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 CHRUBUNTU mountpoint
MOUNTCHRUBUNTU='/var/chrubuntu'
# Try to mount the ChrUbuntu partition, if it exists, on $MOUNTCHRUBUNTU.
mountchrubuntu() {
if [ -z "$ROOTDEVICE" ]; then
findrootdevice
fi
local chrubuntupart="`sudo cgpt find -n -l ROOT-C "$ROOTDEVICE"`"
if [ -z "$chrubuntupart" ]; then
return 1
elif [ ! "`sudo cgpt show -i "$chrubuntupart" -s "$ROOTDEVICE"`" -gt 1 ]; then
return 1
fi
PRIOR=' now'
# Check if chrubuntu is mounted already
if grep -q "^${ROOTDEVICEPREFIX}$chrubuntupart " /proc/mounts; then
# If mounted, it must be mounted to $mountpoint
if ! grep -q "^${ROOTDEVICEPREFIX}$chrubuntupart $MOUNTCHRUBUNTU " \
/proc/mounts; then
error 1 "Error: CHRUBUNTU partition is not mounted on $MOUNTCHRUBUNTU."
else
PRIOR=' already'
fi
else
sudo mkdir -p "$MOUNTCHRUBUNTU" || error 1 "Cannot create $MOUNTCHRUBUNTU."
sudo mount "${ROOTDEVICEPREFIX}$chrubuntupart" "$MOUNTCHRUBUNTU" || \
error 1 "Cannot mount $MOUNTCHRUBUNTU"
fi
return 0
}
# Now mount the CHRUBUNTU partition
mountchrubuntu
end script