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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 dd if=/dev/zero of="${OEM_FS_IMG}" bs=1 count=1 seek=$((OEM_SIZE_BYTES - 1)) | 396 dd if=/dev/zero of="${OEM_FS_IMG}" bs=1 count=1 seek=$((OEM_SIZE_BYTES - 1)) |
397 | 397 |
398 # Tune and mount OEM partner partition. | 398 # Tune and mount OEM partner partition. |
399 UUID=$(uuidgen) | 399 UUID=$(uuidgen) |
400 DISK_LABEL="C-OEM" | 400 DISK_LABEL="C-OEM" |
401 sudo losetup "${OEM_LOOP_DEV}" "${OEM_FS_IMG}" | 401 sudo losetup "${OEM_LOOP_DEV}" "${OEM_FS_IMG}" |
402 sudo mkfs.ext3 "${OEM_LOOP_DEV}" | 402 sudo mkfs.ext3 "${OEM_LOOP_DEV}" |
403 sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${OEM_LOOP_DEV}" | 403 sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${OEM_LOOP_DEV}" |
404 sudo mount "${OEM_LOOP_DEV}" "${OEM_FS_DIR}" | 404 sudo mount "${OEM_LOOP_DEV}" "${OEM_FS_DIR}" |
405 | 405 |
406 # Turn root file system into bootable image. | |
407 if [[ "${ARCH}" = "x86" ]]; then | |
408 # Setup extlinux configuration. | |
409 # TODO: For some reason the /dev/disk/by-uuid is not being generated by udev | |
410 # in the initramfs. When we figure that out, switch to root=UUID=${UUID}. | |
411 sudo mkdir -p "${ROOT_FS_DIR}"/boot | |
412 # TODO(adlr): use initramfs for booting. | |
413 cat <<EOF | sudo dd of="${ROOT_FS_DIR}"/boot/extlinux.conf | |
414 DEFAULT chromeos-usb | |
415 PROMPT 0 | |
416 TIMEOUT 0 | |
417 | |
418 label chromeos-usb | |
419 menu label chromeos-usb | |
420 kernel vmlinuz | |
421 append quiet console=tty2 init=/sbin/init boot=local rootwait root=/dev/sdb3 r
o noresume noswap i915.modeset=1 loglevel=1 cros_legacy | |
422 | |
423 label chromeos-hd | |
424 menu label chromeos-hd | |
425 kernel vmlinuz | |
426 append quiet console=tty2 init=/sbin/init boot=local rootwait root=HDROOT ro n
oresume noswap i915.modeset=1 loglevel=1 cros_legacy | |
427 EOF | |
428 | |
429 # Make partition bootable and label it. | |
430 sudo extlinux -z --install "${ROOT_FS_DIR}/boot" | |
431 fi | |
432 | |
433 # -- Install packages into the root file system -- | 406 # -- Install packages into the root file system -- |
434 | 407 |
435 # We need to install libc manually from the cross toolchain. | 408 # We need to install libc manually from the cross toolchain. |
436 # TODO: Improve this? We only want libc and not the whole toolchain. | 409 # TODO: Improve this? We only want libc and not the whole toolchain. |
437 PKGDIR="/var/lib/portage/pkgs/cross/" | 410 PKGDIR="/var/lib/portage/pkgs/cross/" |
438 sudo tar jxvpf \ | 411 sudo tar jxvpf \ |
439 "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \ | 412 "${PKGDIR}/${CHOST}/cross-${CHOST}"/glibc-${LIBC_VERSION}.tbz2 \ |
440 -C "${ROOT_FS_DIR}" --strip-components=3 \ | 413 -C "${ROOT_FS_DIR}" --strip-components=3 \ |
441 --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o | 414 --exclude=usr/include --exclude=sys-include --exclude=*.a --exclude=*.o |
442 | 415 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 # We'll hard-code it to 16M for now. | 451 # We'll hard-code it to 16M for now. |
479 ESP_BLOCKS=16384 | 452 ESP_BLOCKS=16384 |
480 /usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS} | 453 /usr/sbin/mkfs.vfat -C ${OUTPUT_DIR}/esp.image ${ESP_BLOCKS} |
481 ESP_LOOP_DEV=$(sudo losetup -f) | 454 ESP_LOOP_DEV=$(sudo losetup -f) |
482 if [ -z "${ESP_LOOP_DEV}" ] ; then | 455 if [ -z "${ESP_LOOP_DEV}" ] ; then |
483 echo "No free loop device. Free up a loop device or reboot. exiting. " | 456 echo "No free loop device. Free up a loop device or reboot. exiting. " |
484 exit 1 | 457 exit 1 |
485 fi | 458 fi |
486 sudo losetup "${ESP_LOOP_DEV}" "${ESP_FS_IMG}" | 459 sudo losetup "${ESP_LOOP_DEV}" "${ESP_FS_IMG}" |
487 sudo mount "${ESP_LOOP_DEV}" "${ESP_FS_DIR}" | 460 sudo mount "${ESP_LOOP_DEV}" "${ESP_FS_DIR}" |
488 sudo mkdir -p "${ESP_FS_DIR}/efi/boot" | |
489 sudo grub-mkimage -p /efi/boot -o "${ESP_FS_DIR}/efi/boot/bootx64.efi" \ | |
490 part_gpt fat ext2 normal boot sh chain configfile linux | |
491 cat <<'EOF' | sudo dd of="${ESP_FS_DIR}/efi/boot/grub.cfg" | |
492 set default=0 | |
493 set timeout=2 | |
494 | 461 |
495 # NOTE: These magic grub variables are a Chrome OS hack. They are not portable. | 462 # Populates the root filesystem with legacy bootloader templates |
| 463 # appropriate for the platform. The autoupdater and installer will |
| 464 # use those templates to update the legacy boot partition (12/ESP) |
| 465 # on update. |
| 466 # (This script does not populate vmlinuz.A and .B needed by syslinux.) |
| 467 use_vboot= |
| 468 ${SCRIPTS_DIR}/create_legacy_bootloader_templates.sh \ |
| 469 --arch=${ARCH} \ |
| 470 --to="${ROOT_FS_DIR}"/boot \ |
| 471 --install \ |
| 472 ${use_vboot} |
496 | 473 |
497 menuentry "local image A" { | 474 # Create a working copy so we don't need the rootfs mounted |
498 linux $grubpartA/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local ro
otwait root=/dev/$linuxpartA ro noresume noswap i915.modeset=1 loglevel=1 cros_e
fi | 475 sudo mkdir -p "${OUTPUT_DIR}"/boot |
499 } | 476 # This will include any built files dropped in /boot as well. |
| 477 # Like the current vmlinuz. |
| 478 sudo cp -r "${ROOT_FS_DIR}"/boot/. "${OUTPUT_DIR}"/boot/ |
500 | 479 |
501 menuentry "local image B" { | 480 # Until bootloader management is unified, copy EFI in here. |
502 linux $grubpartB/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local ro
otwait root=/dev/$linuxpartB ro noresume noswap i915.modeset=1 loglevel=1 cros_e
fi | 481 sudo mkdir -p "${ESP_FS_IMG}"/efi |
503 } | 482 sudo cp -r "${ROOT_FS_DIR}"/boot/efi/. "${ESP_FS_IMG}"/efi |
504 | |
505 menuentry "Alternate USB Boot" { | |
506 linux (hd0,3)/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local rootw
ait root=/dev/sdb3 ro noresume noswap i915.modeset=1 loglevel=1 cros_efi | |
507 } | |
508 | |
509 EOF | |
510 # TODO(wad) add baseline syslinux files to ESP and install the syslinux loader | |
511 | 483 |
512 # Builds the kernel partition image. The temporary files are kept around | 484 # Builds the kernel partition image. The temporary files are kept around |
513 # so that we can perform a load_kernel_test later on the final image. | 485 # so that we can perform a load_kernel_test later on the final image. |
514 # TODO(wad) add dm-verity boot args (--boot_args, --root) | 486 # TODO(wad) add dm-verity boot args (--boot_args, --root) |
515 ${SCRIPTS_DIR}/build_kernel_image.sh \ | 487 ${SCRIPTS_DIR}/build_kernel_image.sh \ |
516 --arch="${ARCH}" \ | 488 --arch="${ARCH}" \ |
517 --to="${OUTPUT_DIR}/vmlinuz.image" \ | 489 --to="${OUTPUT_DIR}/vmlinuz.image" \ |
518 --vmlinuz="${ROOT_FS_DIR}/boot/vmlinuz" \ | 490 --vmlinuz="${ROOT_FS_DIR}/boot/vmlinuz" \ |
519 --working_dir="${OUTPUT_DIR}" \ | 491 --working_dir="${OUTPUT_DIR}" \ |
520 --keep_work \ | 492 --keep_work \ |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" | 589 echo "Developer image created as ${DEVELOPER_IMAGE_NAME}" |
618 fi | 590 fi |
619 | 591 |
620 print_time_elapsed | 592 print_time_elapsed |
621 | 593 |
622 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" | 594 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" |
623 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" | 595 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
624 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" | 596 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" |
625 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" | 597 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" |
626 echo "from the scripts directory where you entered the chroot." | 598 echo "from the scripts directory where you entered the chroot." |
OLD | NEW |