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

Side by Side Diff: src/scripts/image_to_usb.sh

Issue 848002: Changes to enable dev in stateful partition for usb and startup (Closed)
Patch Set: Add legacy support Created 10 years, 9 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
« no previous file with comments | « src/scripts/file_copy.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2009 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 # Script to convert the output of build_image.sh to a usb image. 7 # Script to convert the output of build_image.sh to a usb image.
8 8
9 # Load common constants. This should be the first executable line. 9 # Load common constants. This should be the first executable line.
10 # The path to common.sh should be relative to your script's location. 10 # The path to common.sh should be relative to your script's location.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 fi 72 fi
73 fi 73 fi
74 74
75 # Convert args to paths. Need eval to un-quote the string so that shell 75 # Convert args to paths. Need eval to un-quote the string so that shell
76 # chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work. 76 # chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work.
77 FLAGS_from=`eval readlink -f ${FLAGS_from}` 77 FLAGS_from=`eval readlink -f ${FLAGS_from}`
78 FLAGS_to=`eval readlink -f ${FLAGS_to}` 78 FLAGS_to=`eval readlink -f ${FLAGS_to}`
79 79
80 # Uses this rootfs image as the source image to copy 80 # Uses this rootfs image as the source image to copy
81 ROOTFS_IMAGE="${FLAGS_from}/rootfs.image" 81 ROOTFS_IMAGE="${FLAGS_from}/rootfs.image"
82 PART_SIZE=$(stat -c%s "${ROOTFS_IMAGE}") # Bytes
83
84 # Setup stateful partition variables
85 STATEFUL_IMG="${FLAGS_from}/stateful_partition.image"
86 STATEFUL_DIR="${FLAGS_from}/stateful_partition"
87
88 # TODO(sosa@chromium.org) - Remove legacy support.
89 if [ ! -f "${STATEFUL_IMG}" ] ; then
90 echo "WARNING! Stateful partition not found. Creating clean stateful"
91 STATEFUL_LOOP_DEV=$(sudo losetup -f)
92 if [ -z "${STATEFUL_LOOP_DEV}" ] ; then
93 echo "No free loop device. Free up a loop device or reboot. exiting. "
94 exit 1
95 fi
96 set -x
97 dd if=/dev/zero of="${STATEFUL_IMG}" bs=1 count=1 \
98 seek=$(( (${PART_SIZE} - 1) ))
99 set +x
100 sudo losetup "$STATEFUL_LOOP_DEV" "$STATEFUL_IMG"
101 sudo mkfs.ext3 "$STATEFUL_LOOP_DEV"
102 sudo tune2fs -L "C-STATE" -c 0 -i 0 "$STATEFUL_LOOP_DEV"
103 sudo losetup -d "${STATEFUL_LOOP_DEV}"
104 fi
82 105
83 # Modifies image for test if requested 106 # Modifies image for test if requested
84 if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then 107 if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then
85 if [ ! -f "${FLAGS_from}/rootfs_test.image" ] ; then 108 if [ ! -f "${FLAGS_from}/rootfs_test.image" ] ; then
86 echo "Test image not found, creating test image from original ... " 109 echo "Test image not found, creating test image from original ... "
87 cp "${FLAGS_from}/rootfs.image" "${FLAGS_from}/rootfs_test.image" 110 cp "${FLAGS_from}/rootfs.image" "${FLAGS_from}/rootfs_test.image"
88 "${SCRIPTS_DIR}/mod_image_for_test.sh" \ 111 "${SCRIPTS_DIR}/mod_image_for_test.sh" \
89 --image "${FLAGS_from}/rootfs_test.image" 112 --image "${FLAGS_from}/rootfs_test.image"
90 fi 113 fi
91 # Use the test image instead 114 # Use the test image instead
92 ROOTFS_IMAGE="${FLAGS_from}/rootfs_test.image" 115 ROOTFS_IMAGE="${FLAGS_from}/rootfs_test.image"
93 fi 116 fi
94 117
95 function do_cleanup { 118 function do_cleanup {
96 sudo losetup -d "${LOOP_DEV}" 119 sudo losetup -d "${LOOP_DEV}"
97 } 120 }
98 121
99 STATEFUL_DIR=${FLAGS_from}/stateful_partition
100 mkdir -p "${STATEFUL_DIR}"
101
102 function install_autotest { 122 function install_autotest {
103 if [ -d ${AUTOTEST_SRC} ] 123 if [ -d ${AUTOTEST_SRC} ]
104 then 124 then
125 local stateful_loop_dev=$(sudo losetup -f)
126 if [ -z "${stateful_loop_dev}" ]
127 then
128 echo "No free loop device. Free up a loop device or reboot. exiting."
129 exit 1
130 fi
131
132 sudo mount "${stateful_loop_dev}" "${STATEFUL_DIR}"
133
105 echo -ne "Install autotest into stateful partition..." 134 echo -ne "Install autotest into stateful partition..."
106 local autotest_client="/home/autotest-client" 135 local autotest_client="/home/autotest-client"
107 sudo mkdir -p "${STATEFUL_DIR}${autotest_client}" 136 sudo mkdir -p "${STATEFUL_DIR}${autotest_client}"
108 sudo cp -fpru ${AUTOTEST_SRC}/client/* \ 137 sudo cp -fpru ${AUTOTEST_SRC}/client/* \
109 "${STATEFUL_DIR}${autotest_client}" 138 "${STATEFUL_DIR}${autotest_client}"
110 sudo chmod 755 "${STATEFUL_DIR}${autotest_client}" 139 sudo chmod 755 "${STATEFUL_DIR}${autotest_client}"
111 sudo chown -R 1000:1000 "${STATEFUL_DIR}${autotest_client}" 140 sudo chown -R 1000:1000 "${STATEFUL_DIR}${autotest_client}"
112 echo "Done." 141
113 sudo umount "${STATEFUL_DIR}" 142 sudo umount ${STATEFUL_DIR}
143 sudo losetup -d "${stateful_loop_dev}"
114 else 144 else
115 echo "/usr/local/autotest under ${DEFAULT_CHROOT_DIR} is not installed." 145 echo "/usr/local/autotest under ${DEFAULT_CHROOT_DIR} is not installed."
116 echo "Please call make_autotest.sh inside chroot first." 146 echo "Please call make_autotest.sh inside chroot first."
117 sudo umount "${STATEFUL_DIR}" 147 sudo umount "${STATEFUL_DIR}"
118 exit -1 148 exit -1
119 fi 149 fi
120 } 150 }
121 151
122 # Copy MBR and rootfs to output image 152 # Copy MBR and rootfs to output image
123 if [ -b "${FLAGS_to}" ] 153 if [ -b "${FLAGS_to}" ]
(...skipping 26 matching lines...) Expand all
150 exit 1 180 exit 1
151 fi 181 fi
152 fi 182 fi
153 183
154 echo "attempting to unmount any mounts on the USB device" 184 echo "attempting to unmount any mounts on the USB device"
155 for i in "${FLAGS_to}"* 185 for i in "${FLAGS_to}"*
156 do 186 do
157 ! sudo umount "$i" 187 ! sudo umount "$i"
158 done 188 done
159 sleep 3 189 sleep 3
160 190
161 PART_SIZE=$(stat -c%s "${ROOTFS_IMAGE}") # Bytes 191 if [ ${FLAGS_install_autotest} -eq ${FLAGS_TRUE} ] ; then
162
163 echo "Copying root fs..."
164 sudo "${SCRIPTS_DIR}"/file_copy.py \
165 if="${ROOTFS_IMAGE}" \
166 of="${FLAGS_to}" bs=4M \
167 seek_bytes=$(( (${PART_SIZE} * 2) + 512 ))
168
169 # Set up loop device
170 LOOP_DEV=$(sudo losetup -f)
171 if [ -z "${LOOP_DEV}" ]
172 then
173 echo "No free loop device. Free up a loop device or reboot. exiting."
174 exit 1
175 fi
176
177 trap do_cleanup EXIT
178
179 echo "Creating stateful partition..."
180 sudo losetup -o 512 "${LOOP_DEV}" "${FLAGS_to}"
181 sudo mkfs.ext3 -F -b 4096 -L C-STATE "${LOOP_DEV}" $(( ${PART_SIZE} / 4096 ))
182 if [ ${FLAGS_install_autotest} -eq ${FLAGS_TRUE} ]
183 then
184 sudo mount "${LOOP_DEV}" "${STATEFUL_DIR}"
185 install_autotest 192 install_autotest
186 fi 193 fi
187 sync 194
188 sudo losetup -d "${LOOP_DEV}" 195 # Write stateful partition to first partition.
189 sync 196 echo "Copying stateful partition ..."
197 sudo "${SCRIPTS_DIR}"/file_copy.py \
198 if="${STATEFUL_IMG}" of="${FLAGS_to}" bs=4M \
199 seek_bytes=512
190 200
201 # Write root fs to third partition.
202 echo "Copying root fs partition ..."
203 sudo "${SCRIPTS_DIR}"/file_copy.py \
204 if="${ROOTFS_IMAGE}" of="${FLAGS_to}" bs=4M \
205 seek_bytes=$(( (${PART_SIZE} * 2) + 512 ))
206
191 trap - EXIT 207 trap - EXIT
192 208
193 if [ ${FLAGS_copy_kernel} -eq ${FLAGS_TRUE} ] 209 if [ ${FLAGS_copy_kernel} -eq ${FLAGS_TRUE} ]
194 then 210 then
195 echo "Copying Kernel..." 211 echo "Copying Kernel..."
196 "${SCRIPTS_DIR}"/kernel_fetcher.sh \ 212 "${SCRIPTS_DIR}"/kernel_fetcher.sh \
197 --from "${FLAGS_from}" \ 213 --from "${FLAGS_from}" \
198 --to "${FLAGS_to}" \ 214 --to "${FLAGS_to}" \
199 --offset "$(( (${PART_SIZE} * 3) + 512 ))" 215 --offset "$(( (${PART_SIZE} * 3) + 512 ))"
200 fi 216 fi
201 217
202 echo "Copying MBR..." 218 echo "Copying MBR..."
203 sudo "${SCRIPTS_DIR}"/file_copy.py \ 219 sudo "${SCRIPTS_DIR}"/file_copy.py \
204 if="${FLAGS_from}/mbr.image" of="${FLAGS_to}" 220 if="${FLAGS_from}/mbr.image" of="${FLAGS_to}"
205 sync 221 sync
206 echo "Done." 222 echo "Done."
207 else 223 else
208 # Output to a file, so just cat the source images together 224 # Output to a file, so just cat the source images together
209 225
210 PART_SIZE=$(stat -c%s "${ROOTFS_IMAGE}") 226 PART_SIZE=$(stat -c%s "${ROOTFS_IMAGE}")
211 227
212 echo "Creating empty stateful partition" 228 if [ ${FLAGS_install_autotest} -eq ${FLAGS_TRUE} ] ; then
213 dd if=/dev/zero of="${FLAGS_from}/stateful_partition.image" bs=1 count=1 \
214 seek=$((${PART_SIZE} - 1))
215 mkfs.ext3 -F -L C-STATE "${FLAGS_from}/stateful_partition.image"
216
217 if [ ${FLAGS_install_autotest} -eq ${FLAGS_TRUE} ]
218 then
219 sudo mount -o loop "${FLAGS_from}/stateful_partition.image" \
220 "${STATEFUL_DIR}"
221 install_autotest 229 install_autotest
222 fi 230 fi
223 231
224 # Create a sparse output file 232 # Create a sparse output file
225 dd if=/dev/zero of="${FLAGS_to}" bs=1 count=1 \ 233 dd if=/dev/zero of="${FLAGS_to}" bs=1 count=1 \
226 seek=$(( (${PART_SIZE} * 2) + 512 - 1)) 234 seek=$(( (${PART_SIZE} * 2) + 512 - 1))
227 235
228 echo "Copying USB image to file ${FLAGS_to}..." 236 echo "Copying USB image to file ${FLAGS_to}..."
229 237
230 dd if="${FLAGS_from}/mbr.image" of="${FLAGS_to}" conv=notrunc 238 dd if="${FLAGS_from}/mbr.image" of="${FLAGS_to}" conv=notrunc
231 dd if="${FLAGS_from}/stateful_partition.image" of="${FLAGS_to}" seek=1 bs=512 \ 239 dd if="${FLAGS_from}/stateful_partition.image" of="${FLAGS_to}" seek=1 bs=512 \
232 conv=notrunc 240 conv=notrunc
233 cat "${ROOTFS_IMAGE}" >> "${FLAGS_to}" 241 cat "${ROOTFS_IMAGE}" >> "${FLAGS_to}"
234 242
235 echo "Done. To copy to USB keyfob, outside the chroot, do something like:" 243 echo "Done. To copy to USB keyfob, outside the chroot, do something like:"
236 echo " sudo dd if=${FLAGS_to} of=/dev/sdb bs=4M" 244 echo " sudo dd if=${FLAGS_to} of=/dev/sdb bs=4M"
237 echo "where /dev/sdb is the entire keyfob." 245 echo "where /dev/sdb is the entire keyfob."
238 if [ ${INSIDE_CHROOT} -eq 1 ] 246 if [ ${INSIDE_CHROOT} -eq 1 ]
239 then 247 then
240 echo "NOTE: Since you are currently inside the chroot, and you'll need to" 248 echo "NOTE: Since you are currently inside the chroot, and you'll need to"
241 echo "run dd outside the chroot, the path to the USB image will be" 249 echo "run dd outside the chroot, the path to the USB image will be"
242 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/usb.img)." 250 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/usb.img)."
243 fi 251 fi
244 fi 252 fi
OLDNEW
« no previous file with comments | « src/scripts/file_copy.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698