OLD | NEW |
(Empty) | |
| 1 #!/bin/bash |
| 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 # Determine script directory |
| 8 SCRIPT_DIR=$(dirname $0) |
| 9 GPT=cgpt |
| 10 |
| 11 # Read GPT table to find the starting location of a specific partition. |
| 12 # Args: DEVICE PARTNUM |
| 13 # Returns: offset (in sectors) of partition PARTNUM |
| 14 partoffset() { |
| 15 sudo $GPT show -b -i $2 $1 |
| 16 } |
| 17 |
| 18 # Read GPT table to find the size of a specific partition. |
| 19 # Args: DEVICE PARTNUM |
| 20 # Returns: size (in sectors) of partition PARTNUM |
| 21 partsize() { |
| 22 sudo $GPT show -s -i $2 $1 |
| 23 } |
| 24 |
| 25 # Mount a partition from an image into a local directory |
| 26 # Args: IMAGE PARTNUM MOUNTDIRECTORY |
| 27 mount_image_partition() { |
| 28 local image=$1 |
| 29 local partnum=$2 |
| 30 local mount_dir=$3 |
| 31 local offset=$(partoffset "$image" "$partnum") |
| 32 sudo mount -o loop,offset=$((offset * 512)) "$image" "$mount_dir" |
| 33 } |
| 34 |
| 35 # Extract a partition to a file |
| 36 # Args: IMAGE PARTNUM OUTPUTFILE |
| 37 extract_image_partition() { |
| 38 local image=$1 |
| 39 local partnum=$2 |
| 40 local output_file=$3 |
| 41 local offset=$(partoffset "$image" "$partnum") |
| 42 local size=$(partsize "$image" "$partnum") |
| 43 dd if=$image of=$output_file bs=512 skip=$offset count=$size |
| 44 } |
| 45 |
OLD | NEW |