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

Side by Side Diff: src/scripts/image_to_virtualbox.sh

Issue 502014: Add a script for creating a VirtualBox image. (Closed)
Patch Set: Added check to make sure that qemu-img and VBoxManage exist Created 11 years 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
(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
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