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

Side by Side Diff: src/scripts/build_image

Issue 1594020: Replace "mount -o loop" with explict losetup use in build_image. (Closed)
Patch Set: 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 | « no previous file | 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 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" 64 OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}"
65 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" 65 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs"
66 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" 66 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image"
67 OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/chromiumos_image.bin} 67 OUTPUT_IMG=${FLAGS_to:-${OUTPUT_DIR}/chromiumos_image.bin}
68 68
69 BOARD="${FLAGS_board}" 69 BOARD="${FLAGS_board}"
70 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" 70 BOARD_ROOT="${FLAGS_build_root}/${BOARD}"
71 71
72 LOOP_DEV= 72 LOOP_DEV=
73 STATEFUL_LOOP_DEV= 73 STATEFUL_LOOP_DEV=
74 ESP_LOOP_DEV=
74 75
75 # What cross-build are we targeting? 76 # What cross-build are we targeting?
76 . "${BOARD_ROOT}/etc/make.conf.board_setup" 77 . "${BOARD_ROOT}/etc/make.conf.board_setup"
77 LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"} 78 LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"}
78 79
79 # Figure out ARCH from the given toolchain. 80 # Figure out ARCH from the given toolchain.
80 # TODO: Move to common.sh as a function after scripts are switched over. 81 # TODO: Move to common.sh as a function after scripts are switched over.
81 TC_ARCH=$(echo "$CHOST" | awk -F'-' '{ print $1 }') 82 TC_ARCH=$(echo "$CHOST" | awk -F'-' '{ print $1 }')
82 case "$TC_ARCH" in 83 case "$TC_ARCH" in
83 arm*) 84 arm*)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 cleanup_stateful_fs_loop() { 121 cleanup_stateful_fs_loop() {
121 sudo umount "${ROOT_FS_DIR}/usr/local" 122 sudo umount "${ROOT_FS_DIR}/usr/local"
122 sudo umount "${ROOT_FS_DIR}/var" 123 sudo umount "${ROOT_FS_DIR}/var"
123 sudo umount "${STATEFUL_DIR}" 124 sudo umount "${STATEFUL_DIR}"
124 sleep 1 # follows from cleanup_root_fs_loop. 125 sleep 1 # follows from cleanup_root_fs_loop.
125 sudo losetup -d "$STATEFUL_LOOP_DEV" 126 sudo losetup -d "$STATEFUL_LOOP_DEV"
126 } 127 }
127 128
128 cleanup_esp_loop() { 129 cleanup_esp_loop() {
129 sudo umount "$ESP_DIR" 130 sudo umount "$ESP_DIR"
131 sleep 1 # me belong cargo
adlr 2010/04/08 18:22:26 write a better comment?
Bill Richardson 2010/04/08 18:23:48 I *knew* you'd say something about this!
132 sudo losetup -d "$ESP_LOOP_DEV"
130 } 133 }
131 134
132 cleanup() { 135 cleanup() {
133 # Disable die on error. 136 # Disable die on error.
134 set +e 137 set +e
135 138
136 if [[ -n "$STATEFUL_LOOP_DEV" ]]; then 139 if [[ -n "$STATEFUL_LOOP_DEV" ]]; then
137 cleanup_stateful_fs_loop 140 cleanup_stateful_fs_loop
138 fi 141 fi
139 142
140 if [[ -n "$LOOP_DEV" ]]; then 143 if [[ -n "$LOOP_DEV" ]]; then
141 cleanup_rootfs_loop 144 cleanup_rootfs_loop
142 fi 145 fi
143 146
144 if [[ -n "$ESP_DIR" ]]; then 147 if [[ -n "$ESP_LOOP_DEV" ]]; then
145 cleanup_esp_loop 148 cleanup_esp_loop
146 fi 149 fi
147 150
148 # Turn die on error back on. 151 # Turn die on error back on.
149 set -e 152 set -e
150 } 153 }
151 154
152 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will 155 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will
153 # be installed on the stateful dir. On a Chromium OS system, this will 156 # be installed on the stateful dir. On a Chromium OS system, this will
154 # translate to /usr/local 157 # translate to /usr/local
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 341
339 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI 342 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI
340 # BIOS). We only need this for x86, but it's simpler and safer to keep the disk 343 # BIOS). We only need this for x86, but it's simpler and safer to keep the disk
341 # images the same for both x86 and ARM. 344 # images the same for both x86 and ARM.
342 ESP_IMG=${OUTPUT_DIR}/esp.image 345 ESP_IMG=${OUTPUT_DIR}/esp.image
343 # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code 346 # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code
344 # it to 16M for now. 347 # it to 16M for now.
345 ESP_BLOCKS=16384 348 ESP_BLOCKS=16384
346 /usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS} 349 /usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS}
347 ESP_DIR=${OUTPUT_DIR}/esp 350 ESP_DIR=${OUTPUT_DIR}/esp
348 mkdir -p ${ESP_DIR} 351 ESP_LOOP_DEV=$(sudo losetup -f)
349 sudo mount -o loop ${ESP_IMG} ${ESP_DIR} 352 if [ -z "$ESP_LOOP_DEV" ] ; then
350 sudo mkdir -p ${ESP_DIR}/efi/boot 353 echo "No free loop device. Free up a loop device or reboot. exiting. "
351 sudo grub-mkimage -p /efi/boot -o ${ESP_DIR}/efi/boot/bootx64.efi \ 354 exit 1
355 fi
356 mkdir -p "${ESP_DIR}"
357 sudo losetup "${ESP_LOOP_DEV}" "${ESP_IMG}"
358 sudo mount "${ESP_LOOP_DEV}" "${ESP_DIR}"
359 sudo mkdir -p "${ESP_DIR}/efi/boot"
360 sudo grub-mkimage -p /efi/boot -o "${ESP_DIR}/efi/boot/bootx64.efi" \
352 part_gpt fat ext2 normal boot sh chain configfile linux 361 part_gpt fat ext2 normal boot sh chain configfile linux
353 sudo cp ${ROOT_FS_DIR}/boot/vmlinuz ${ESP_DIR}/efi/boot/vmlinuz 362 sudo cp "${ROOT_FS_DIR}/boot/vmlinuz" "${ESP_DIR}/efi/boot/vmlinuz"
354 cat <<EOF | sudo dd of=${ESP_DIR}/efi/boot/grub.cfg 363 cat <<EOF | sudo dd of="${ESP_DIR}/efi/boot/grub.cfg"
355 set timeout=2 364 set timeout=2
356 set default=0 365 set default=0
357 366
358 menuentry "32-bit serial" { 367 menuentry "serial debug" {
359 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 368 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
360 } 369 }
370
371 menuentry "normal" {
372 linux /efi/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sda3 ro noresume noswap i915.modeset=1 loglevel=1
373 }
374
361 EOF 375 EOF
362 376
363 # Enable dev mode on the target system and re-run ldconfig 377 # Enable dev mode on the target system and re-run ldconfig
364 # for rootfs's ld.so.cache 378 # for rootfs's ld.so.cache
365 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then 379 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then
366 # Flag will mount /usr/local on target device 380 # Flag will mount /usr/local on target device
367 sudo mkdir -p "$ROOT_FS_DIR/root" 381 sudo mkdir -p "$ROOT_FS_DIR/root"
368 sudo touch "$ROOT_FS_DIR/root/.dev_mode" 382 sudo touch "$ROOT_FS_DIR/root/.dev_mode"
369 383
370 # Re-run ldconfig to fix /etc/ldconfig.so.cache 384 # Re-run ldconfig to fix /etc/ldconfig.so.cache
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 419
406 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" 420 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}"
407 echo "Done. Image created in ${OUTPUT_DIR}" 421 echo "Done. Image created in ${OUTPUT_DIR}"
408 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" 422 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:"
409 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdb" 423 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdb"
410 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" 424 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:"
411 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" 425 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}"
412 echo "from the scripts directory where you entered the chroot." 426 echo "from the scripts directory where you entered the chroot."
413 427
414 trap - EXIT 428 trap - EXIT
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698