Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 trap - EXIT | 469 trap - EXIT |
| 470 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ | 470 ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ |
| 471 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}" | 471 -s "${STATEFUL_FS_DIR}" -e "${ESP_FS_DIR}" |
| 472 } | 472 } |
| 473 | 473 |
| 474 create_base_image() { | 474 create_base_image() { |
| 475 local image_name=$1 | 475 local image_name=$1 |
| 476 | 476 |
| 477 trap "cleanup && delete_prompt" EXIT | 477 trap "cleanup && delete_prompt" EXIT |
| 478 | 478 |
| 479 UUID=$(uuidgen) | |
| 480 | |
| 481 # Create and format the root file system. | 479 # Create and format the root file system. |
| 482 | 480 |
| 483 # Check for loop device before creating image. | 481 # Check for loop device before creating image. |
| 484 LOOP_DEV=$(sudo losetup -f) | 482 LOOP_DEV=$(sudo losetup -f) |
| 485 if [ -z "${LOOP_DEV}" ] ; then | 483 if [ -z "${LOOP_DEV}" ] ; then |
| 486 echo "No free loop device. Free up a loop device or reboot. exiting. " | 484 echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 487 exit 1 | 485 exit 1 |
| 488 fi | 486 fi |
| 489 | 487 |
| 490 # Create root file system disk image. | 488 # Create root file system disk image. |
| 491 ROOT_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_rootfs_size})) | 489 ROOT_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_rootfs_size})) |
| 492 | 490 |
| 493 # Pad out for the hash tree. | 491 # Pad out for the hash tree. |
| 494 ROOT_HASH_PAD=$((FLAGS_rootfs_hash_pad * 1024 * 1024)) | 492 ROOT_HASH_PAD=$((FLAGS_rootfs_hash_pad * 1024 * 1024)) |
| 495 info "Padding the rootfs image by ${ROOT_HASH_PAD} bytes for hash data" | 493 info "Padding the rootfs image by ${ROOT_HASH_PAD} bytes for hash data" |
| 496 | 494 |
| 497 dd if=/dev/zero of="${ROOT_FS_IMG}" bs=1 count=1 \ | 495 dd if=/dev/zero of="${ROOT_FS_IMG}" bs=1 count=1 \ |
| 498 seek=$((ROOT_SIZE_BYTES + ROOT_HASH_PAD - 1)) | 496 seek=$((ROOT_SIZE_BYTES + ROOT_HASH_PAD - 1)) |
| 499 sudo losetup "${LOOP_DEV}" "${ROOT_FS_IMG}" | 497 sudo losetup "${LOOP_DEV}" "${ROOT_FS_IMG}" |
| 500 # Specify a block size and block count to avoid using the hash pad. | 498 # Specify a block size and block count to avoid using the hash pad. |
| 501 sudo mkfs.ext3 -b 4096 "${LOOP_DEV}" "$((ROOT_SIZE_BYTES / 4096))" | 499 sudo mkfs.ext2 -b 4096 "${LOOP_DEV}" "$((ROOT_SIZE_BYTES / 4096))" |
| 502 | 500 |
| 503 # Tune and mount rootfs. | 501 # Tune and mount rootfs. |
| 504 # TODO(wad) rename the disk label to match the GPT since we | 502 DISK_LABEL="C-ROOT" |
| 505 # can't change it later. | 503 # Disable checking and minimize metadata differences across builds |
| 506 DISK_LABEL="C-KEYFOB" | 504 # and wasted reserved space. |
| 507 sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${LOOP_DEV}" | 505 sudo tune2fs -L "${DISK_LABEL}" \ |
| 506 -U clear \ | |
| 507 -T 20091119110000 \ | |
| 508 -c 0 \ | |
| 509 -i 0 \ | |
| 510 -m 0 \ | |
|
gauravsh
2010/10/20 19:06:55
do you expect any performance effected from changi
Will Drewry
2010/10/20 19:11:49
I actually just wanted to make sure we use our fil
| |
| 511 -r 0 \ | |
| 512 -e remount-ro \ | |
| 513 "${LOOP_DEV}" | |
| 514 # TODO(wad) call tune2fs prior to finalization to set the mount count to 0. | |
| 508 sudo mount "${LOOP_DEV}" "${ROOT_FS_DIR}" | 515 sudo mount "${LOOP_DEV}" "${ROOT_FS_DIR}" |
| 509 | 516 |
| 510 # Create stateful partition of the same size as the rootfs. | 517 # Create stateful partition of the same size as the rootfs. |
| 511 STATEFUL_LOOP_DEV=$(sudo losetup -f) | 518 STATEFUL_LOOP_DEV=$(sudo losetup -f) |
| 512 if [ -z "${STATEFUL_LOOP_DEV}" ] ; then | 519 if [ -z "${STATEFUL_LOOP_DEV}" ] ; then |
| 513 echo "No free loop device. Free up a loop device or reboot. exiting. " | 520 echo "No free loop device. Free up a loop device or reboot. exiting. " |
| 514 exit 1 | 521 exit 1 |
| 515 fi | 522 fi |
| 516 STATEFUL_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_statefulfs_size})) | 523 STATEFUL_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_statefulfs_size})) |
| 517 dd if=/dev/zero of="${STATEFUL_FS_IMG}" bs=1 count=1 \ | 524 dd if=/dev/zero of="${STATEFUL_FS_IMG}" bs=1 count=1 \ |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 753 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" | 760 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" |
| 754 fi | 761 fi |
| 755 | 762 |
| 756 print_time_elapsed | 763 print_time_elapsed |
| 757 | 764 |
| 758 echo "To copy to USB keyfob, do something like:" | 765 echo "To copy to USB keyfob, do something like:" |
| 759 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" | 766 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
| 760 echo "To convert to VMWare image, INSIDE the chroot, do something like:" | 767 echo "To convert to VMWare image, INSIDE the chroot, do something like:" |
| 761 echo " ./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD}" | 768 echo " ./image_to_vm.sh --from=${OUTSIDE_OUTPUT_DIR} --board=${BOARD}" |
| 762 echo "from the scripts directory where you entered the chroot." | 769 echo "from the scripts directory where you entered the chroot." |
| OLD | NEW |