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. |
| 13 . "$(dirname "$0")/chromeos-common.sh" |
| 14 |
12 get_default_board | 15 get_default_board |
13 | 16 |
14 # Flags. | 17 # Flags. |
15 DEFINE_string board "$DEFAULT_BOARD" \ | 18 DEFINE_string board "$DEFAULT_BOARD" \ |
16 "The board for which the image was built." b | 19 "The board for which the image was built." b |
17 DEFINE_boolean unmount $FLAGS_FALSE \ | 20 DEFINE_boolean unmount $FLAGS_FALSE \ |
18 "Unmount previously mounted dir." u | 21 "Unmount previously mounted dir." u |
19 DEFINE_string from "/dev/sdc" \ | 22 DEFINE_string from "/dev/sdc" \ |
20 "Directory containing image or device with image on it" f | 23 "Directory containing image or device with image on it" f |
21 DEFINE_boolean test $FLAGS_FALSE "Use chromiumos_test_image.bin" t | 24 DEFINE_string image "chromiumos_image.bin"\ |
| 25 "Name of the bin file if a directory is specified in the from flag" i |
22 DEFINE_string "rootfs_mountpt" "/tmp/m" "Mount point for rootfs" "r" | 26 DEFINE_string "rootfs_mountpt" "/tmp/m" "Mount point for rootfs" "r" |
23 DEFINE_string "stateful_mountpt" "/tmp/s" \ | 27 DEFINE_string "stateful_mountpt" "/tmp/s" \ |
24 "Mount point for stateful partition" "s" | 28 "Mount point for stateful partition" "s" |
25 DEFINE_boolean most_recent ${FLAGS_FALSE} "Use the most recent image dir" m | 29 DEFINE_boolean most_recent ${FLAGS_FALSE} "Use the most recent image dir" m |
26 | 30 |
27 # Parse flags | 31 # Parse flags |
28 FLAGS "$@" || exit 1 | 32 FLAGS "$@" || exit 1 |
29 eval set -- "${FLAGS_ARGV}" | 33 eval set -- "${FLAGS_ARGV}" |
30 | 34 |
31 # Die on error | 35 # Die on error |
32 set -e | 36 set -e |
33 | 37 |
34 # Common umounts for either a device or directory | 38 # Common unmounts for either a device or directory |
35 function unmount_common() { | 39 function unmount_image() { |
36 echo "Unmounting image from ${FLAGS_stateful_mountpt}" \ | 40 echo "Unmounting image from ${FLAGS_stateful_mountpt}" \ |
37 "and ${FLAGS_rootfs_mountpt}" | 41 "and ${FLAGS_rootfs_mountpt}" |
38 # Don't die on error to force cleanup | 42 # Don't die on error to force cleanup |
39 set +e | 43 set +e |
40 if [ -e "${FLAGS_rootfs_mountpt}/root/.dev_mode" ] ; then | 44 if [ -e "${FLAGS_rootfs_mountpt}/root/.dev_mode" ] ; then |
| 45 # Reset symlinks in /usr/local. |
| 46 setup_symlinks_on_root "/usr/local" "/var" \ |
| 47 "${FLAGS_stateful_mountpt}" |
41 sudo umount "${FLAGS_rootfs_mountpt}/usr/local" | 48 sudo umount "${FLAGS_rootfs_mountpt}/usr/local" |
42 fi | 49 fi |
43 sudo umount "${FLAGS_rootfs_mountpt}/var" | 50 sudo umount "${FLAGS_rootfs_mountpt}/var" |
44 sudo umount -d "${FLAGS_stateful_mountpt}" | 51 sudo umount -d "${FLAGS_stateful_mountpt}" |
45 sudo umount -d "${FLAGS_rootfs_mountpt}" | 52 sudo umount -d "${FLAGS_rootfs_mountpt}" |
46 set -e | 53 set -e |
47 } | 54 } |
48 | 55 |
49 # Sets up the rootfs and stateful partitions specified by | 56 function get_usb_partitions() { |
50 # ${FLAGS_from}${prefix}[31] to the given mount points and sets up var and | 57 sudo mount "${FLAGS_from}3" "${FLAGS_rootfs_mountpt}" |
51 # usr/local | 58 sudo mount "${FLAGS_from}1" "${FLAGS_stateful_mountpt}" |
52 # ${1} - prefix name for the partition | 59 } |
53 # ${2} - extra mount options for the partitions | 60 |
54 function mount_common() { | 61 function get_gpt_partitions() { |
| 62 local filename="${FLAGS_image}" |
| 63 |
| 64 # Mount the rootfs partition using a loopback device. |
| 65 local offset=$(partoffset "${FLAGS_from}/${filename}" 3) |
| 66 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ |
| 67 "${FLAGS_rootfs_mountpt}" |
| 68 |
| 69 # Mount the stateful partition using a loopback device. |
| 70 offset=$(partoffset "${FLAGS_from}/${filename}" 1) |
| 71 sudo mount -o loop,offset=$(( offset * 512 )) "${FLAGS_from}/${filename}" \ |
| 72 "${FLAGS_stateful_mountpt}" |
| 73 } |
| 74 |
| 75 # Mount a gpt based image. |
| 76 function mount_image() { |
55 mkdir -p "${FLAGS_rootfs_mountpt}" | 77 mkdir -p "${FLAGS_rootfs_mountpt}" |
56 mkdir -p "${FLAGS_stateful_mountpt}" | 78 mkdir -p "${FLAGS_stateful_mountpt}" |
57 sudo mount ${2} "${FLAGS_from}${1}3" "${FLAGS_rootfs_mountpt}" | 79 |
58 sudo mount ${2} "${FLAGS_from}${1}1" "${FLAGS_stateful_mountpt}" | 80 # Get the partitions for the image / device. |
| 81 if [ -b ${FLAGS_from} ] ; then |
| 82 get_usb_partitions |
| 83 else |
| 84 get_gpt_partitions |
| 85 fi |
| 86 |
| 87 # Mount var unconditionally and then setup /usr/local for user of dev mode. |
59 sudo mount --bind "${FLAGS_stateful_mountpt}/var" \ | 88 sudo mount --bind "${FLAGS_stateful_mountpt}/var" \ |
60 "${FLAGS_rootfs_mountpt}/var" | 89 "${FLAGS_rootfs_mountpt}/var" |
61 if [ -e "${FLAGS_rootfs_mountpt}/root/.dev_mode" ] ; then | 90 if [ -e "${FLAGS_rootfs_mountpt}/root/.dev_mode" ] ; then |
62 sudo mount --bind "${FLAGS_stateful_mountpt}/dev_image" \ | 91 sudo mount --bind "${FLAGS_stateful_mountpt}/dev_image" \ |
63 "${FLAGS_rootfs_mountpt}/usr/local" | 92 "${FLAGS_rootfs_mountpt}/usr/local" |
| 93 # Setup symlinks in /usr/local so you can emerge packages into /usr/local. |
| 94 setup_symlinks_on_root "${FLAGS_stateful_mountpt}/dev_image" \ |
| 95 "${FLAGS_stateful_mountpt}/var" "${FLAGS_stateful_mountpt}" |
64 fi | 96 fi |
65 echo "Root FS specified by "${FLAGS_from}${1}3" mounted at"\ | 97 echo "Image specified by ${FLAGS_from} mounted at"\ |
66 "${FLAGS_rootfs_mountpt} successfully." | 98 "${FLAGS_rootfs_mountpt} successfully." |
67 } | 99 } |
68 | 100 |
69 # Find the last image built on the board | 101 # Find the last image built on the board. |
70 if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then | 102 if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then |
71 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" | 103 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" |
72 FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)" | 104 FLAGS_from="${IMAGES_DIR}/$(ls -t ${IMAGES_DIR} 2>&-| head -1)" |
73 fi | 105 fi |
74 | 106 |
75 # Turn into absolute path | 107 # Turn path into an absolute path. |
76 FLAGS_from=`eval readlink -f ${FLAGS_from}` | 108 FLAGS_from=`eval readlink -f ${FLAGS_from}` |
77 | 109 |
78 # Set the file name of the image if ${FLAGS_from} is not a device and cd | 110 # Perform desired operation. |
79 if [ -d "${FLAGS_from}" ] ; then | 111 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then |
80 cd "${FLAGS_from}" | 112 unmount_image |
81 IMAGE_NAME=chromiumos_image.bin | 113 else |
82 [ ${FLAGS_test} -eq ${FLAGS_TRUE} ] && IMAGE_NAME=chromiumos_test_image.bin | 114 mount_image |
83 fi | 115 fi |
84 | |
85 if [ ${FLAGS_unmount} -eq ${FLAGS_TRUE} ] ; then | |
86 unmount_common | |
87 if [ -d "${FLAGS_from}" ] ; then | |
88 echo "Re-packing partitions onto ${FLAGS_from}/${IMAGE_NAME}" | |
89 ./pack_partitions.sh ${IMAGE_NAME} 2> /dev/null | |
90 sudo rm part_* | |
91 fi | |
92 else | |
93 if [ -b ${FLAGS_from} ] ; then | |
94 mount_common "" "" | |
95 else | |
96 echo "Unpacking partitions from ${FLAGS_from}/${IMAGE_NAME}" | |
97 ./unpack_partitions.sh ${IMAGE_NAME} 2> /dev/null | |
98 mount_common "/part_" "-o loop" | |
99 fi | |
100 fi | |
OLD | NEW |