Bill Richardson | a082f4e | 2010-07-24 01:20:58 | [diff] [blame] | 1 | #!/bin/sh -ue |
| 2 | # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | # |
| 6 | # A script to locate the rootfs that corresponds to the kernel. Used in the |
| 7 | # initramfs on the recovery image. The hard drive *should* be constant and so |
| 8 | # won't need an initramfs. |
| 9 | |
| 10 | # Load functions and constants for chromeos-install. |
| 11 | . "$(dirname "$0")/chromeos-common.sh" || exit 1 |
| 12 | |
Bill Richardson | 6837233 | 2010-08-03 19:51:17 | [diff] [blame] | 13 | if [ "0" == $(id -u) ]; then |
| 14 | local sudo="" |
| 15 | else |
| 16 | local sudo=sudo |
| 17 | fi |
| 18 | |
Bill Richardson | a082f4e | 2010-07-24 01:20:58 | [diff] [blame] | 19 | # Extract the kernel partition's UniqueGuid from the command line. |
Bill Richardson | 6837233 | 2010-08-03 19:51:17 | [diff] [blame] | 20 | guid=$(sed 's/.*kern_guid=\([0-9a-fA-F-]\+\).*/\1/' /proc/cmdline) |
Bill Richardson | a082f4e | 2010-07-24 01:20:58 | [diff] [blame] | 21 | |
| 22 | # Look through all the known devices to find that one partition. |
Bill Richardson | 6837233 | 2010-08-03 19:51:17 | [diff] [blame] | 23 | kern_dev=$($sudo cgpt find -1 -u $guid) |
Bill Richardson | a082f4e | 2010-07-24 01:20:58 | [diff] [blame] | 24 | |
| 25 | # That's the kernel, so increment the partition number to find the rootfs. |
| 26 | base_dev=$(get_block_dev_from_partition_dev $kern_dev) |
| 27 | kern_num=$(get_partition_number $kern_dev) |
| 28 | root_num=$(expr $kern_num + 1) |
| 29 | root_dev=$(make_partition_dev $base_dev $root_num) |
| 30 | |
| 31 | # done |
| 32 | echo $root_dev |