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" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 echo "Unmounting image from ${FLAGS_stateful_mountpt}" \ | 43 echo "Unmounting image from ${FLAGS_stateful_mountpt}" \ |
44 "and ${FLAGS_rootfs_mountpt}" | 44 "and ${FLAGS_rootfs_mountpt}" |
45 # Don't die on error to force cleanup | 45 # Don't die on error to force cleanup |
46 set +e | 46 set +e |
47 # Reset symlinks in /usr/local. | 47 # Reset symlinks in /usr/local. |
48 setup_symlinks_on_root "/usr/local" "/var" \ | 48 setup_symlinks_on_root "/usr/local" "/var" \ |
49 "${FLAGS_stateful_mountpt}" | 49 "${FLAGS_stateful_mountpt}" |
50 fix_broken_symlinks "${FLAGS_rootfs_mountpt}" | 50 fix_broken_symlinks "${FLAGS_rootfs_mountpt}" |
51 sudo umount "${FLAGS_rootfs_mountpt}/usr/local" | 51 sudo umount "${FLAGS_rootfs_mountpt}/usr/local" |
52 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}" | 53 if [[ -n "${FLAGS_esp_mountpt}" ]]; then |
| 54 sudo umount -d "${FLAGS_esp_mountpt}" |
| 55 fi |
54 sudo umount -d "${FLAGS_stateful_mountpt}" | 56 sudo umount -d "${FLAGS_stateful_mountpt}" |
55 sudo umount -d "${FLAGS_rootfs_mountpt}" | 57 sudo umount -d "${FLAGS_rootfs_mountpt}" |
56 set -e | 58 set -e |
57 } | 59 } |
58 | 60 |
59 function get_usb_partitions() { | 61 function get_usb_partitions() { |
60 sudo mount "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}" | 62 sudo mount "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}" |
61 sudo mount "${FLAGS_from}1" "${FLAGS_stateful_mountpt}" | 63 sudo mount "${FLAGS_from}1" "${FLAGS_stateful_mountpt}" |
62 test -n "${FLAGS_esp_mountpt}" && \ | 64 if [[ -n "${FLAGS_esp_mountpt}" ]]; then |
63 sudo mount "${FLAGS_from}12" "${FLAGS_esp_mountpt}" | 65 sudo mount "${FLAGS_from}12" "${FLAGS_esp_mountpt}" |
| 66 fi |
64 } | 67 } |
65 | 68 |
66 function get_gpt_partitions() { | 69 function get_gpt_partitions() { |
67 local filename="${FLAGS_image}" | 70 local filename="${FLAGS_image}" |
68 | 71 |
69 # Mount the rootfs partition using a loopback device. | 72 # Mount the rootfs partition using a loopback device. |
70 local offset=$(partoffset "${FLAGS_from}/${filename}" 3) | 73 local offset=$(partoffset "${FLAGS_from}/${filename}" 3) |
71 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ | 74 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ |
72 "${FLAGS_rootfs_mountpt}" | 75 "${FLAGS_rootfs_mountpt}" |
73 | 76 |
74 # Mount the stateful partition using a loopback device. | 77 # Mount the stateful partition using a loopback device. |
75 offset=$(partoffset "${FLAGS_from}/${filename}" 1) | 78 offset=$(partoffset "${FLAGS_from}/${filename}" 1) |
76 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ | 79 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ |
77 "${FLAGS_stateful_mountpt}" | 80 "${FLAGS_stateful_mountpt}" |
78 | 81 |
79 # Mount the stateful partition using a loopback device. | 82 # Mount the stateful partition using a loopback device. |
80 if [[ -n "${FLAGS_esp_mountpt}" ]]; then | 83 if [[ -n "${FLAGS_esp_mountpt}" ]]; then |
81 offset=$(partoffset "${FLAGS_from}/${filename}" 12) | 84 offset=$(partoffset "${FLAGS_from}/${filename}" 12) |
82 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ | 85 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ |
83 "${FLAGS_esp_mountpt}" | 86 "${FLAGS_esp_mountpt}" |
84 fi | 87 fi |
85 } | 88 } |
86 | 89 |
87 # Mount a gpt based image. | 90 # Mount a gpt based image. |
88 function mount_image() { | 91 function mount_image() { |
89 mkdir -p "${FLAGS_rootfs_mountpt}" | 92 mkdir -p "${FLAGS_rootfs_mountpt}" |
90 mkdir -p "${FLAGS_stateful_mountpt}" | 93 mkdir -p "${FLAGS_stateful_mountpt}" |
91 test -n "${FLAGS_esp_mountpt}" && \ | 94 if [[ -n "${FLAGS_esp_mountpt}" ]]; then |
92 mkdir -p "${FLAGS_esp_mountpt}" | 95 mkdir -p "${FLAGS_esp_mountpt}" |
| 96 fi |
93 | 97 |
94 # Get the partitions for the image / device. | 98 # Get the partitions for the image / device. |
95 if [ -b ${FLAGS_from} ] ; then | 99 if [ -b ${FLAGS_from} ] ; then |
96 get_usb_partitions | 100 get_usb_partitions |
97 else | 101 else |
98 get_gpt_partitions | 102 get_gpt_partitions |
99 fi | 103 fi |
100 | 104 |
101 # Mount directories and setup symlinks. | 105 # Mount directories and setup symlinks. |
102 sudo mount --bind "${FLAGS_stateful_mountpt}/var" \ | 106 sudo mount --bind "${FLAGS_stateful_mountpt}/var" \ |
(...skipping 15 matching lines...) Expand all Loading... |
118 | 122 |
119 # Turn path into an absolute path. | 123 # Turn path into an absolute path. |
120 FLAGS_from=`eval readlink -f ${FLAGS_from}` | 124 FLAGS_from=`eval readlink -f ${FLAGS_from}` |
121 | 125 |
122 # Perform desired operation. | 126 # Perform desired operation. |
123 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then | 127 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then |
124 unmount_image | 128 unmount_image |
125 else | 129 else |
126 mount_image | 130 mount_image |
127 fi | 131 fi |
OLD | NEW |