| #!/bin/sh -ue |
| # Copyright (c) 2010 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. |
| # |
| # A script to locate the rootfs that corresponds to the kernel. Used in the |
| # initramfs on the recovery image. The hard drive *should* be constant and so |
| # won't need an initramfs. |
| |
| # Load functions and constants for chromeos-install. |
| . "$(dirname "$0")/chromeos-common.sh" || exit 1 |
| |
| if [ "0" == $(id -u) ]; then |
| local sudo="" |
| else |
| local sudo=sudo |
| fi |
| |
| # Extract the kernel partition's UniqueGuid from the command line. |
| guid=$(sed 's/.*kern_guid=\([0-9a-fA-F-]\+\).*/\1/' /proc/cmdline) |
| |
| # Look through all the known devices to find that one partition. |
| kern_dev=$($sudo cgpt find -1 -u $guid) |
| |
| # That's the kernel, so increment the partition number to find the rootfs. |
| base_dev=$(get_block_dev_from_partition_dev $kern_dev) |
| kern_num=$(get_partition_number $kern_dev) |
| root_num=$(expr $kern_num + 1) |
| root_dev=$(make_partition_dev $base_dev $root_num) |
| |
| # done |
| echo $root_dev |