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

Side by Side Diff: src/scripts/build_image

Issue 1513019: Create EFI System Partition on USB image during build. (Closed)
Patch Set: Cleanup, add image_to_vmware.sh changes Created 10 years, 8 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/build_gpt.sh ('k') | src/scripts/image_to_vmware.sh » ('j') | 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 build a bootable keyfob-based chromeos system image from within 7 # Script to build a bootable keyfob-based chromeos system image from within
8 # a chromiumos setup. This assumes that all needed packages have been built into 8 # a chromiumos setup. This assumes that all needed packages have been built into
9 # the given target's root with binary packages turned on. This script will 9 # the given target's root with binary packages turned on. This script will
10 # build the Chrome OS image using only pre-built binary packages. 10 # build the Chrome OS image using only pre-built binary packages.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 # Only now can we die on error. shflags functions leak non-zero error codes, 49 # Only now can we die on error. shflags functions leak non-zero error codes,
50 # so will die prematurely if 'set -e' is specified before now. 50 # so will die prematurely if 'set -e' is specified before now.
51 set -e 51 set -e
52 52
53 if [ -z "$FLAGS_board" ] ; then 53 if [ -z "$FLAGS_board" ] ; then
54 error "--board is required." 54 error "--board is required."
55 exit 1 55 exit 1
56 fi 56 fi
57 57
58 # Sanity check: statefuldev cannot be true if withdev is false. 58 # Sanity check: statefuldev cannot be true if withdev is false.
59 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] && 59 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] &&
60 [ $FLAGS_withdev -eq $FLAGS_FALSE ] ; then 60 [ $FLAGS_withdev -eq $FLAGS_FALSE ] ; then
61 echo "ERROR: statefuldev flag cannot be set to true without withdev" 61 echo "ERROR: statefuldev flag cannot be set to true without withdev"
62 exit 1 62 exit 1
63 fi 63 fi
64 64
65 # Determine build version. 65 # Determine build version.
66 . "${SCRIPTS_DIR}/chromeos_version.sh" 66 . "${SCRIPTS_DIR}/chromeos_version.sh"
67 67
68 # Use canonical path since some tools (e.g. mount) do not like symlinks. 68 # Use canonical path since some tools (e.g. mount) do not like symlinks.
69 # Append build attempt to output directory. 69 # Append build attempt to output directory.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 sleep 1 # in case $LOOP_DEV is in use (TODO: Try umount -l?). 122 sleep 1 # in case $LOOP_DEV is in use (TODO: Try umount -l?).
123 sudo losetup -d "$LOOP_DEV" 123 sudo losetup -d "$LOOP_DEV"
124 } 124 }
125 125
126 cleanup_stateful_fs_loop() { 126 cleanup_stateful_fs_loop() {
127 sudo umount "$STATEFUL_LOOP_DEV" 127 sudo umount "$STATEFUL_LOOP_DEV"
128 sleep 1 # follows from cleanup_root_fs_loop. 128 sleep 1 # follows from cleanup_root_fs_loop.
129 sudo losetup -d "$STATEFUL_LOOP_DEV" 129 sudo losetup -d "$STATEFUL_LOOP_DEV"
130 } 130 }
131 131
132 cleanup_esp_loop() {
133 sudo umount "$ESP_DIR"
134 }
135
132 cleanup() { 136 cleanup() {
133 # Disable die on error. 137 # Disable die on error.
134 set +e 138 set +e
135 139
136 # Unmount stateful partition from usr/local if bound. 140 # Unmount stateful partition from usr/local if bound.
137 if [ -s "$ROOT_FS_DIR/usr/local/bin" ] ; then 141 if [ -s "$ROOT_FS_DIR/usr/local/bin" ] ; then
138 sudo umount $ROOT_FS_DIR/usr/local 142 sudo umount $ROOT_FS_DIR/usr/local
139 fi 143 fi
140 144
141 if [[ -n "$STATEFUL_LOOP_DEV" ]]; then 145 if [[ -n "$STATEFUL_LOOP_DEV" ]]; then
142 cleanup_stateful_fs_loop 146 cleanup_stateful_fs_loop
143 fi 147 fi
144 148
145 if [[ -n "$LOOP_DEV" ]]; then 149 if [[ -n "$LOOP_DEV" ]]; then
146 cleanup_rootfs_loop 150 cleanup_rootfs_loop
147 fi 151 fi
148 152
153 if [[ -n "$ESP_DIR" ]]; then
154 cleanup_esp_loop
155 fi
156
149 # Turn die on error back on. 157 # Turn die on error back on.
150 set -e 158 set -e
151 } 159 }
152 160
153 trap cleanup EXIT 161 trap cleanup EXIT
154 162
155 mkdir -p "$ROOT_FS_DIR" 163 mkdir -p "$ROOT_FS_DIR"
156 164
157 # Create and format the root file system. 165 # Create and format the root file system.
158 166
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 251
244 if [[ $FLAGS_jobs -ne -1 ]]; then 252 if [[ $FLAGS_jobs -ne -1 ]]; then
245 EMERGE_JOBS="--jobs=$FLAGS_jobs" 253 EMERGE_JOBS="--jobs=$FLAGS_jobs"
246 fi 254 fi
247 255
248 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then 256 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then
249 # Creating stateful partition. 257 # Creating stateful partition.
250 echo "Setting up symlinks for stateful partition install" 258 echo "Setting up symlinks for stateful partition install"
251 DEV_IMAGE_ROOT="$STATEFUL_DIR/dev_image" 259 DEV_IMAGE_ROOT="$STATEFUL_DIR/dev_image"
252 sudo mkdir -p "$DEV_IMAGE_ROOT/usr" 260 sudo mkdir -p "$DEV_IMAGE_ROOT/usr"
253 261
254 # Setup symlinks in stateful partition. 262 # Setup symlinks in stateful partition.
255 for path in bin include lib libexec sbin share; do 263 for path in bin include lib libexec sbin share; do
256 sudo mkdir "$DEV_IMAGE_ROOT/$path" 264 sudo mkdir "$DEV_IMAGE_ROOT/$path"
257 sudo ln -s "$DEV_IMAGE_ROOT/$path" "$DEV_IMAGE_ROOT/usr/$path" 265 sudo ln -s "$DEV_IMAGE_ROOT/$path" "$DEV_IMAGE_ROOT/usr/$path"
258 done 266 done
259 267
260 # Setup symlinks that don't conform to above model. 268 # Setup symlinks that don't conform to above model.
261 sudo ln -s "$DEV_IMAGE_ROOT/lib" "$DEV_IMAGE_ROOT/usr/lib64" 269 sudo ln -s "$DEV_IMAGE_ROOT/lib" "$DEV_IMAGE_ROOT/usr/lib64"
262 sudo ln -s "$DEV_IMAGE_ROOT" "$DEV_IMAGE_ROOT/usr/local" 270 sudo ln -s "$DEV_IMAGE_ROOT" "$DEV_IMAGE_ROOT/usr/local"
263 271
264 # Bind to rootfs. 272 # Bind to rootfs.
265 echo "Binding stateful partition to rootfs's /usr/local" 273 echo "Binding stateful partition to rootfs's /usr/local"
266 sudo mkdir -p "$ROOT_FS_DIR/usr/local" 274 sudo mkdir -p "$ROOT_FS_DIR/usr/local"
267 sudo mount -n --bind "$DEV_IMAGE_ROOT" "$ROOT_FS_DIR/usr/local" 275 sudo mount -n --bind "$DEV_IMAGE_ROOT" "$ROOT_FS_DIR/usr/local"
268 fi 276 fi
269 277
(...skipping 19 matching lines...) Expand all
289 sudo cp -a "$(which ldd)" "${ROOT_DEV_DIR}/usr/bin" 297 sudo cp -a "$(which ldd)" "${ROOT_DEV_DIR}/usr/bin"
290 fi 298 fi
291 299
292 # Install packages required for testing. 300 # Install packages required for testing.
293 if [[ $FLAGS_withtest -eq $FLAGS_TRUE ]] ; then 301 if [[ $FLAGS_withtest -eq $FLAGS_TRUE ]] ; then
294 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \ 302 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \
295 --root="$ROOT_DEV_DIR" --root-deps=rdeps \ 303 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
296 --usepkgonly chromeos-test $EMERGE_JOBS 304 --usepkgonly chromeos-test $EMERGE_JOBS
297 fi 305 fi
298 306
299 # Clean up links setup for stateful install of extra packages. 307 # Clean up links setup for stateful install of extra packages.
300 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then 308 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then
301 # Fix symlinks so they work on live system. 309 # Fix symlinks so they work on live system.
302 for path in bin include lib libexec sbin share; do 310 for path in bin include lib libexec sbin share; do
303 sudo unlink $DEV_IMAGE_ROOT/usr/$path 311 sudo unlink $DEV_IMAGE_ROOT/usr/$path
304 sudo ln -s /usr/local/$path $DEV_IMAGE_ROOT/usr/$path 312 sudo ln -s /usr/local/$path $DEV_IMAGE_ROOT/usr/$path
305 done 313 done
306 314
307 # Fix exceptions. 315 # Fix exceptions.
308 sudo unlink "$DEV_IMAGE_ROOT/usr/lib64" 316 sudo unlink "$DEV_IMAGE_ROOT/usr/lib64"
309 sudo unlink "$DEV_IMAGE_ROOT/usr/local" 317 sudo unlink "$DEV_IMAGE_ROOT/usr/local"
310 318
311 sudo ln -s "/usr/local/lib" "$DEV_IMAGE_ROOT/usr/lib64" 319 sudo ln -s "/usr/local/lib" "$DEV_IMAGE_ROOT/usr/lib64"
312 sudo ln -s "/usr/local" "$DEV_IMAGE_ROOT/usr/local" 320 sudo ln -s "/usr/local" "$DEV_IMAGE_ROOT/usr/local"
313 321
314 #TODO(sosa@chromium.org) - /usr/bin/xterm symlink not created in stateful. 322 #TODO(sosa@chromium.org) - /usr/bin/xterm symlink not created in stateful.
315 sudo ln -sf "/usr/local/bin/aterm" "/usr/bin/xterm" 323 sudo ln -sf "/usr/local/bin/aterm" "/usr/bin/xterm"
316 fi 324 fi
317 325
318 # Perform any customizations on the root file system that are needed. 326 # Perform any customizations on the root file system that are needed.
319 WITH_DEV="" 327 WITH_DEV=""
320 if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]]; then 328 if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]]; then
321 WITH_DEV="--withdev" 329 WITH_DEV="--withdev"
322 fi 330 fi
323 331
324 # Extract the kernel from the root filesystem for use by the GPT image. Legacy 332 # Extract the kernel from the root filesystem for use by the GPT image. Legacy
325 # BIOS will use the kernel in the rootfs (via syslinux), ChromeOS BIOS will use 333 # BIOS will use the kernel in the rootfs (via syslinux), Chrome OS BIOS will
326 # the kernel partition. 334 # use the kernel partition.
327 sudo cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image" 335 sudo cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image"
328 336
337 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI
338 # BIOS). We only need this for x86, but it's simpler and safer to keep the disk
339 # images the same for both x86 and ARM.
340 ESP_IMG=${OUTPUT_DIR}/esp.image
341 # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code
342 # it to 16M for now.
343 ESP_BLOCKS=16384
344 /usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS}
345 ESP_DIR=${OUTPUT_DIR}/esp
346 mkdir -p ${ESP_DIR}
347 sudo mount -o loop ${ESP_IMG} ${ESP_DIR}
348 sudo mkdir -p ${ESP_DIR}/efi/boot
349 sudo grub-mkimage -p /efi/boot -o ${ESP_DIR}/efi/boot/bootx64.efi \
350 part_gpt fat ext2 normal boot sh chain configfile linux
351 sudo cp ${ROOT_FS_DIR}/boot/vmlinuz ${ESP_DIR}/efi/boot/vmlinuz
352 cat <<EOF | sudo dd of=${ESP_DIR}/efi/boot/grub.cfg
353 set timeout=2
354 set default=0
355
356 menuentry "32-bit serial" {
357 linux /efi/boot/vmlinuz earlyprintk=serial,ttyS0,115200 i915.modeset=0 console =ttyS0,115200 acpi=off init=/sbin/init boot=local rootwait root=/dev/sda3 ro nor esume noswap loglevel=7
358 }
359 EOF
360
329 #TODO(sosa@chromium.org) - Does it make sense to leave /usr/local bound here? 361 #TODO(sosa@chromium.org) - Does it make sense to leave /usr/local bound here?
330 "${SCRIPTS_DIR}/customize_rootfs" \ 362 "${SCRIPTS_DIR}/customize_rootfs" \
331 --root="$ROOT_FS_DIR" \ 363 --root="$ROOT_FS_DIR" \
332 --target="$ARCH" \ 364 --target="$ARCH" \
333 --board="$BOARD" \ 365 --board="$BOARD" \
334 $WITH_DEV 366 $WITH_DEV
335 367
336 # Check that the image has been correctly created. 368 # Check that the image has been correctly created.
337 "${SCRIPTS_DIR}/test_image" \ 369 "${SCRIPTS_DIR}/test_image" \
338 --root="$ROOT_FS_DIR" \ 370 --root="$ROOT_FS_DIR" \
339 --target="$ARCH" 371 --target="$ARCH"
340 372
341 # Set dev_mode flag and update library cache. 373 # Set dev_mode flag and update library cache.
342 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then 374 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then
343 sudo touch "$ROOT_FS_DIR/root/.dev_mode" 375 sudo touch "$ROOT_FS_DIR/root/.dev_mode"
344 sudo /sbin/ldconfig -r "$ROOT_FS_DIR" 376 sudo /sbin/ldconfig -r "$ROOT_FS_DIR"
345 fi 377 fi
346 378
347 # Only bound if installing dev to stateful. 379 # Only bound if installing dev to stateful.
348 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then 380 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then
349 sudo umount "$ROOT_FS_DIR/usr/local" 381 sudo umount "$ROOT_FS_DIR/usr/local"
350 fi 382 fi
351 383
352 # Cleanup loop devices. 384 # Cleanup loop devices.
385 cleanup_esp_loop
353 cleanup_stateful_fs_loop 386 cleanup_stateful_fs_loop
354 cleanup_rootfs_loop 387 cleanup_rootfs_loop
355 388
356 # Create the GPT-formatted image 389 # Create the GPT-formatted image
357 ${SCRIPTS_DIR}/build_gpt.sh \ 390 ${SCRIPTS_DIR}/build_gpt.sh \
358 --arch=${ARCH} --board=${FLAGS_board} --board_root=${BOARD_ROOT} \ 391 --arch=${ARCH} --board=${FLAGS_board} --board_root=${BOARD_ROOT} \
359 "${OUTPUT_DIR}" "${OUTPUT_IMG}" 392 "${OUTPUT_DIR}" "${OUTPUT_IMG}"
360 393
361 # Clean up temporary files. 394 # Clean up temporary files.
362 rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" 395 rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \
363 rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" 396 "${ESP_IMG}"
397 rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}"
364 398
365 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" 399 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}"
366 echo "Done. Image created in ${OUTPUT_DIR}" 400 echo "Done. Image created in ${OUTPUT_DIR}"
367 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" 401 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:"
368 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdb" 402 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdb"
369 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" 403 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:"
370 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" 404 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}"
371 echo "from the scripts directory where you entered the chroot." 405 echo "from the scripts directory where you entered the chroot."
372 406
373 trap - EXIT 407 trap - EXIT
OLDNEW
« no previous file with comments | « src/scripts/build_gpt.sh ('k') | src/scripts/image_to_vmware.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698