Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: bin/cros_mount_gpt_image.sh

Issue 6413012: chromeos-installer: delete unused files (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/installer.git@master
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bin/cros_mod_image_for_test.sh ('k') | bin/cros_resign_image.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 # 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).
9
10 . "/usr/lib/crosutils/common.sh"
11
12 # For functions related to gpt images.
13 . "/usr/lib/installer/chromeos-common.sh"
14 locate_gpt
15
16 get_default_board
17
18 # Flags.
19 DEFINE_string board "$DEFAULT_BOARD" \
20 "The board for which the image was built." b
21 DEFINE_boolean unmount $FLAGS_FALSE \
22 "Unmount previously mounted dir." u
23 DEFINE_string from "/dev/sdc" \
24 "Directory containing image or device with image on it" f
25 DEFINE_string image "chromiumos_image.bin"\
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"
28 DEFINE_string "stateful_mountpt" "/tmp/s" \
29 "Mount point for stateful partition" "s"
30 DEFINE_string "esp_mountpt" "" \
31 "Mount point for esp partition" "e"
32 DEFINE_boolean most_recent ${FLAGS_FALSE} "Use the most recent image dir" m
33
34 # Parse flags
35 FLAGS "$@" || exit 1
36 eval set -- "${FLAGS_ARGV}"
37
38 # Die on error
39 set -e
40
41 # Common unmounts for either a device or directory
42 function unmount_image() {
43 echo "Unmounting image from ${FLAGS_stateful_mountpt}" \
44 "and ${FLAGS_rootfs_mountpt}"
45 # Don't die on error to force cleanup
46 set +e
47 # Reset symlinks in /usr/local.
48 setup_symlinks_on_root "/usr/local" "/var" \
49 "${FLAGS_stateful_mountpt}"
50 fix_broken_symlinks "${FLAGS_rootfs_mountpt}"
51 sudo umount "${FLAGS_rootfs_mountpt}/usr/local"
52 sudo umount "${FLAGS_rootfs_mountpt}/var"
53 if [[ -n "${FLAGS_esp_mountpt}" ]]; then
54 sudo umount -d "${FLAGS_esp_mountpt}"
55 fi
56 sudo umount -d "${FLAGS_stateful_mountpt}"
57 sudo umount -d "${FLAGS_rootfs_mountpt}"
58 set -e
59 }
60
61 function get_usb_partitions() {
62 sudo mount "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}"
63 sudo mount "${FLAGS_from}1" "${FLAGS_stateful_mountpt}"
64 if [[ -n "${FLAGS_esp_mountpt}" ]]; then
65 sudo mount "${FLAGS_from}12" "${FLAGS_esp_mountpt}"
66 fi
67 }
68
69 function get_gpt_partitions() {
70 local filename="${FLAGS_image}"
71
72 # Mount the rootfs partition using a loopback device.
73 local offset=$(partoffset "${FLAGS_from}/${filename}" 3)
74 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \
75 "${FLAGS_rootfs_mountpt}"
76
77 # Mount the stateful partition using a loopback device.
78 offset=$(partoffset "${FLAGS_from}/${filename}" 1)
79 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \
80 "${FLAGS_stateful_mountpt}"
81
82 # Mount the stateful partition using a loopback device.
83 if [[ -n "${FLAGS_esp_mountpt}" ]]; then
84 offset=$(partoffset "${FLAGS_from}/${filename}" 12)
85 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \
86 "${FLAGS_esp_mountpt}"
87 fi
88 }
89
90 # Mount a gpt based image.
91 function mount_image() {
92 mkdir -p "${FLAGS_rootfs_mountpt}"
93 mkdir -p "${FLAGS_stateful_mountpt}"
94 if [[ -n "${FLAGS_esp_mountpt}" ]]; then
95 mkdir -p "${FLAGS_esp_mountpt}"
96 fi
97
98 # Get the partitions for the image / device.
99 if [ -b ${FLAGS_from} ] ; then
100 get_usb_partitions
101 else
102 get_gpt_partitions
103 fi
104
105 # Mount directories and setup symlinks.
106 sudo mount --bind "${FLAGS_stateful_mountpt}/var" \
107 "${FLAGS_rootfs_mountpt}/var"
108 sudo mount --bind "${FLAGS_stateful_mountpt}/dev_image" \
109 "${FLAGS_rootfs_mountpt}/usr/local"
110 # Setup symlinks in /usr/local so you can emerge packages into /usr/local.
111 setup_symlinks_on_root "${FLAGS_stateful_mountpt}/dev_image" \
112 "${FLAGS_stateful_mountpt}/var" "${FLAGS_stateful_mountpt}"
113 echo "Image specified by ${FLAGS_from} mounted at"\
114 "${FLAGS_rootfs_mountpt} successfully."
115 }
116
117 # Find the last image built on the board.
118 if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then
119 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
120 FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)"
121 fi
122
123 # Turn path into an absolute path.
124 FLAGS_from=`eval readlink -f ${FLAGS_from}`
125
126 # Perform desired operation.
127 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then
128 unmount_image
129 else
130 mount_image
131 fi
OLDNEW
« no previous file with comments | « bin/cros_mod_image_for_test.sh ('k') | bin/cros_resign_image.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698