| OLD | NEW |
| (Empty) | |
| 1 #!/bin/bash |
| 2 |
| 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 |
| 5 # found in the LICENSE file. |
| 6 |
| 7 # Script to convert the output of build_image.sh to a VirtualBox image. |
| 8 # Load common constants. This should be the first executable line. |
| 9 # The path to common.sh should be relative to your script's location. |
| 10 . "$(dirname "$0")/common.sh" |
| 11 |
| 12 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" |
| 13 # Default to the most recent image |
| 14 DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`" |
| 15 DEFAULT_TO="${DEFAULT_FROM}/os.vdi" |
| 16 TEMP_IMAGE="${IMAGES_DIR}/temp.img" |
| 17 |
| 18 # Flags |
| 19 DEFINE_string from "$DEFAULT_FROM" \ |
| 20 "Directory containing rootfs.image and mbr.image" |
| 21 DEFINE_string to "$DEFAULT_TO" \ |
| 22 "Destination file for VirtualBox image" |
| 23 |
| 24 # Parse command line |
| 25 FLAGS "$@" || exit 1 |
| 26 eval set -- "${FLAGS_ARGV}" |
| 27 |
| 28 # Die on any errors. |
| 29 set -e |
| 30 |
| 31 # Convert args to paths. Need eval to un-quote the string so that shell |
| 32 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. |
| 33 FLAGS_from=`eval readlink -f $FLAGS_from` |
| 34 FLAGS_to=`eval readlink -f $FLAGS_to` |
| 35 |
| 36 # Check if qemu-img and VBoxManage are available. |
| 37 for EXTERNAL_tools in qemu-img VBoxManage; do |
| 38 if ! type ${EXTERNAL_tools} >/dev/null 2>&1; then |
| 39 echo "Error: This script requires ${EXTERNAL_tools}." |
| 40 exit 1 |
| 41 fi |
| 42 done |
| 43 |
| 44 # Make two sparse files. One for an empty partition, another for |
| 45 # stateful partition. |
| 46 PART_SIZE=$(stat -c%s "${FLAGS_from}/rootfs.image") |
| 47 dd if=/dev/zero of="${FLAGS_from}/empty.image" bs=1 count=1 \ |
| 48 seek=$(( $PART_SIZE - 1 )) |
| 49 dd if=/dev/zero of="${FLAGS_from}/state.image" bs=1 count=1 \ |
| 50 seek=$(( $PART_SIZE - 1 )) |
| 51 mkfs.ext3 -F -L C-STATE "${FLAGS_from}/state.image" |
| 52 |
| 53 # Copy MBR and rootfs to output image |
| 54 qemu-img convert -f raw \ |
| 55 "${FLAGS_from}/mbr.image" "${FLAGS_from}/state.image" \ |
| 56 "${FLAGS_from}/empty.image" "${FLAGS_from}/rootfs.image" \ |
| 57 -O raw "${TEMP_IMAGE}" |
| 58 VBoxManage convertdd "${TEMP_IMAGE}" "${FLAGS_to}" |
| 59 |
| 60 rm -f "${FLAGS_from}/empty.image" "${FLAGS_from}/state.image" "${TEMP_IMAGE}" |
| 61 |
| 62 echo "Done. Created VirtualBox image ${FLAGS_to}" |
| 63 |
| OLD | NEW |