OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Helper script that mounts chromium os image from a device or directory | 7 # Helper script that mounts chromium os image from a device or directory |
8 # and creates mount points for /var and /usr/local (if in dev_mode). | 8 # and creates mount points for /var and /usr/local (if in dev_mode). |
9 | 9 |
10 . "$(dirname "$0")/common.sh" | 10 . "$(dirname "$0")/common.sh" |
11 | 11 |
12 # For functions related to gpt images. | 12 # For functions related to gpt images. |
13 . "$(dirname "$0")/chromeos-common.sh" | 13 . "$(dirname "$0")/chromeos-common.sh" |
14 locate_gpt | 14 locate_gpt |
15 | 15 |
16 get_default_board | 16 get_default_board |
17 | 17 |
18 # Flags. | 18 # Flags. |
19 DEFINE_string board "$DEFAULT_BOARD" \ | 19 DEFINE_string board "$DEFAULT_BOARD" \ |
20 "The board for which the image was built." b | 20 "The board for which the image was built." b |
21 DEFINE_boolean unmount $FLAGS_FALSE \ | 21 DEFINE_boolean unmount $FLAGS_FALSE \ |
22 "Unmount previously mounted dir." u | 22 "Unmount previously mounted dir." u |
23 DEFINE_string from "/dev/sdc" \ | 23 DEFINE_string from "/dev/sdc" \ |
24 "Directory containing image or device with image on it" f | 24 "Directory containing image or device with image on it" f |
25 DEFINE_string image "chromiumos_image.bin"\ | 25 DEFINE_string image "chromiumos_image.bin"\ |
26 "Name of the bin file if a directory is specified in the from flag" i | 26 "Name of the bin file if a directory is specified in the from flag" i |
27 DEFINE_string "rootfs_mountpt" "/tmp/m" "Mount point for rootfs" "r" | 27 DEFINE_string "rootfs_mountpt" "/tmp/m" "Mount point for rootfs" "r" |
28 DEFINE_string "stateful_mountpt" "/tmp/s" \ | 28 DEFINE_string "stateful_mountpt" "/tmp/s" \ |
29 "Mount point for stateful partition" "s" | 29 "Mount point for stateful partition" "s" |
| 30 DEFINE_string "esp_mountpt" "" \ |
| 31 "Mount point for esp partition" "e" |
30 DEFINE_boolean most_recent ${FLAGS_FALSE} "Use the most recent image dir" m | 32 DEFINE_boolean most_recent ${FLAGS_FALSE} "Use the most recent image dir" m |
31 | 33 |
32 # Parse flags | 34 # Parse flags |
33 FLAGS "$@" || exit 1 | 35 FLAGS "$@" || exit 1 |
34 eval set -- "${FLAGS_ARGV}" | 36 eval set -- "${FLAGS_ARGV}" |
35 | 37 |
36 # Die on error | 38 # Die on error |
37 set -e | 39 set -e |
38 | 40 |
39 # Common unmounts for either a device or directory | 41 # Common unmounts for either a device or directory |
40 function unmount_image() { | 42 function unmount_image() { |
41 echo "Unmounting image from ${FLAGS_stateful_mountpt}" \ | 43 echo "Unmounting image from ${FLAGS_stateful_mountpt}" \ |
42 "and ${FLAGS_rootfs_mountpt}" | 44 "and ${FLAGS_rootfs_mountpt}" |
43 # Don't die on error to force cleanup | 45 # Don't die on error to force cleanup |
44 set +e | 46 set +e |
45 # Reset symlinks in /usr/local. | 47 # Reset symlinks in /usr/local. |
46 setup_symlinks_on_root "/usr/local" "/var" \ | 48 setup_symlinks_on_root "/usr/local" "/var" \ |
47 "${FLAGS_stateful_mountpt}" | 49 "${FLAGS_stateful_mountpt}" |
48 fix_broken_symlinks "${FLAGS_rootfs_mountpt}" | 50 fix_broken_symlinks "${FLAGS_rootfs_mountpt}" |
49 sudo umount "${FLAGS_rootfs_mountpt}/usr/local" | 51 sudo umount "${FLAGS_rootfs_mountpt}/usr/local" |
50 sudo umount "${FLAGS_rootfs_mountpt}/var" | 52 sudo umount "${FLAGS_rootfs_mountpt}/var" |
| 53 test -n "${FLAGS_esp_mountpt}" && sudo umount -d "${FLAGS_esp_mountpt}" |
51 sudo umount -d "${FLAGS_stateful_mountpt}" | 54 sudo umount -d "${FLAGS_stateful_mountpt}" |
52 sudo umount -d "${FLAGS_rootfs_mountpt}" | 55 sudo umount -d "${FLAGS_rootfs_mountpt}" |
53 set -e | 56 set -e |
54 } | 57 } |
55 | 58 |
56 function get_usb_partitions() { | 59 function get_usb_partitions() { |
57 sudo mount "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}" | 60 sudo mount "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}" |
58 sudo mount "${FLAGS_from}1" "${FLAGS_stateful_mountpt}" | 61 sudo mount "${FLAGS_from}1" "${FLAGS_stateful_mountpt}" |
| 62 test -n "${FLAGS_esp_mountpt}" && \ |
| 63 sudo mount "${FLAGS_from}12" "${FLAGS_esp_mountpt}" |
59 } | 64 } |
60 | 65 |
61 function get_gpt_partitions() { | 66 function get_gpt_partitions() { |
62 local filename="${FLAGS_image}" | 67 local filename="${FLAGS_image}" |
63 | 68 |
64 # Mount the rootfs partition using a loopback device. | 69 # Mount the rootfs partition using a loopback device. |
65 local offset=$(partoffset "${FLAGS_from}/${filename}" 3) | 70 local offset=$(partoffset "${FLAGS_from}/${filename}" 3) |
66 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ | 71 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ |
67 "${FLAGS_rootfs_mountpt}" | 72 "${FLAGS_rootfs_mountpt}" |
68 | 73 |
69 # Mount the stateful partition using a loopback device. | 74 # Mount the stateful partition using a loopback device. |
70 offset=$(partoffset "${FLAGS_from}/${filename}" 1) | 75 offset=$(partoffset "${FLAGS_from}/${filename}" 1) |
71 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ | 76 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ |
72 "${FLAGS_stateful_mountpt}" | 77 "${FLAGS_stateful_mountpt}" |
| 78 |
| 79 # Mount the stateful partition using a loopback device. |
| 80 if [[ -n "${FLAGS_esp_mountpt}" ]]; then |
| 81 offset=$(partoffset "${FLAGS_from}/${filename}" 12) |
| 82 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ |
| 83 "${FLAGS_esp_mountpt}" |
| 84 fi |
73 } | 85 } |
74 | 86 |
75 # Mount a gpt based image. | 87 # Mount a gpt based image. |
76 function mount_image() { | 88 function mount_image() { |
77 mkdir -p "${FLAGS_rootfs_mountpt}" | 89 mkdir -p "${FLAGS_rootfs_mountpt}" |
78 mkdir -p "${FLAGS_stateful_mountpt}" | 90 mkdir -p "${FLAGS_stateful_mountpt}" |
| 91 mkdir -p "${FLAGS_esp_mountpt}" |
79 | 92 |
80 # Get the partitions for the image / device. | 93 # Get the partitions for the image / device. |
81 if [ -b ${FLAGS_from} ] ; then | 94 if [ -b ${FLAGS_from} ] ; then |
82 get_usb_partitions | 95 get_usb_partitions |
83 else | 96 else |
84 get_gpt_partitions | 97 get_gpt_partitions |
85 fi | 98 fi |
86 | 99 |
87 # Mount directories and setup symlinks. | 100 # Mount directories and setup symlinks. |
88 sudo mount --bind "${FLAGS_stateful_mountpt}/var" \ | 101 sudo mount --bind "${FLAGS_stateful_mountpt}/var" \ |
(...skipping 15 matching lines...) Expand all Loading... |
104 | 117 |
105 # Turn path into an absolute path. | 118 # Turn path into an absolute path. |
106 FLAGS_from=`eval readlink -f ${FLAGS_from}` | 119 FLAGS_from=`eval readlink -f ${FLAGS_from}` |
107 | 120 |
108 # Perform desired operation. | 121 # Perform desired operation. |
109 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then | 122 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then |
110 unmount_image | 123 unmount_image |
111 else | 124 else |
112 mount_image | 125 mount_image |
113 fi | 126 fi |
OLD | NEW |