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 convert the output of build_image.sh to a VMware image. | 7 # Script to convert the output of build_image.sh to a VMware image and write a |
| 8 # corresponding VMware config file. |
8 | 9 |
9 # Load common constants. This should be the first executable line. | 10 # Load common constants. This should be the first executable line. |
10 # The path to common.sh should be relative to your script's location. | 11 # The path to common.sh should be relative to your script's location. |
11 . "$(dirname "$0")/common.sh" | 12 . "$(dirname "$0")/common.sh" |
12 | 13 |
13 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" | 14 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" |
14 # Default to the most recent image | 15 # Default to the most recent image |
15 DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`" | 16 DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`" |
16 DEFAULT_TO="${DEFAULT_FROM}/ide.vmdk" | 17 DEFAULT_TO="${DEFAULT_FROM}" |
| 18 DEFAULT_VMDK="ide.vmdk" |
| 19 DEFAULT_VMX="chromeos.vmx" |
| 20 # Memory units are in MBs |
| 21 DEFAULT_MEM="1024" |
17 | 22 |
18 # Flags | 23 # Flags |
19 DEFINE_string from "$DEFAULT_FROM" \ | 24 DEFINE_string from "$DEFAULT_FROM" \ |
20 "Directory containing rootfs.image and mbr.image" | 25 "Directory containing rootfs.image and mbr.image" |
21 DEFINE_string to "$DEFAULT_TO" \ | 26 DEFINE_string to "$DEFAULT_TO" \ |
22 "Destination file for VMware image" | 27 "Destination folder for VMware files" |
| 28 DEFINE_boolean make_vmx true \ |
| 29 "Create a vmx file for use with vmplayer." |
| 30 DEFINE_string vmdk "$DEFAULT_VMDK" \ |
| 31 "Filename for the vmware disk image" |
| 32 DEFINE_string vmx "$DEFAULT_VMX" \ |
| 33 "Filename for the vmware config" |
| 34 DEFINE_integer mem "$DEFAULT_MEM" \ |
| 35 "Memory size for the vmware config in MBs." |
23 | 36 |
24 # Parse command line | 37 # Parse command line |
25 FLAGS "$@" || exit 1 | 38 FLAGS "$@" || exit 1 |
26 eval set -- "${FLAGS_ARGV}" | 39 eval set -- "${FLAGS_ARGV}" |
27 | 40 |
28 # Die on any errors. | 41 # Die on any errors. |
29 set -e | 42 set -e |
30 | 43 |
31 # Convert args to paths. Need eval to un-quote the string so that shell | 44 # 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. | 45 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. |
33 FLAGS_from=`eval readlink -f $FLAGS_from` | 46 FLAGS_from=`eval readlink -f $FLAGS_from` |
34 FLAGS_to=`eval readlink -f $FLAGS_to` | 47 FLAGS_to=`eval readlink -f $FLAGS_to` |
35 | 48 |
36 # Make two sparse files. One for an empty partition, another for | 49 # Make two sparse files. One for an empty partition, another for |
37 # stateful partition. | 50 # stateful partition. |
38 PART_SIZE=$(stat -c%s "${FLAGS_from}/rootfs.image") | 51 PART_SIZE=$(stat -c%s "${FLAGS_from}/rootfs.image") |
39 dd if=/dev/zero of="${FLAGS_from}/empty.image" bs=1 count=1 \ | 52 dd if=/dev/zero of="${FLAGS_from}/empty.image" bs=1 count=1 \ |
40 seek=$(( $PART_SIZE - 1 )) | 53 seek=$(( $PART_SIZE - 1 )) |
41 dd if=/dev/zero of="${FLAGS_from}/state.image" bs=1 count=1 \ | 54 dd if=/dev/zero of="${FLAGS_from}/state.image" bs=1 count=1 \ |
42 seek=$(( $PART_SIZE - 1 )) | 55 seek=$(( $PART_SIZE - 1 )) |
43 mkfs.ext3 -F -L C-STATE "${FLAGS_from}/state.image" | 56 mkfs.ext3 -F -L C-STATE "${FLAGS_from}/state.image" |
44 | 57 |
45 # Copy MBR and rootfs to output image | 58 # Copy MBR and rootfs to output image |
46 qemu-img convert -f raw \ | 59 qemu-img convert -f raw \ |
47 "${FLAGS_from}/mbr.image" "${FLAGS_from}/state.image" \ | 60 "${FLAGS_from}/mbr.image" "${FLAGS_from}/state.image" \ |
48 "${FLAGS_from}/empty.image" "${FLAGS_from}/rootfs.image" \ | 61 "${FLAGS_from}/empty.image" "${FLAGS_from}/rootfs.image" \ |
49 -O vmdk "${FLAGS_to}" | 62 -O vmdk "${FLAGS_to}/${FLAGS_vmdk}" |
50 | 63 |
51 rm -f "${FLAGS_from}/empty.image" "${FLAGS_from}/state.image" | 64 rm -f "${FLAGS_from}/empty.image" "${FLAGS_from}/state.image" |
52 | 65 |
53 echo "Done. Created VMware image ${FLAGS_to}" | 66 echo "Created VMware image ${FLAGS_to}" |
54 | 67 |
| 68 # Generate the vmware config file |
| 69 # A good reference doc: http://www.sanbarrow.com/vmx.html |
| 70 VMX_CONFIG=$(cat <<END |
| 71 #!/usr/bin/vmware |
| 72 .encoding = "UTF-8" |
| 73 config.version = "8" |
| 74 virtualHW.version = "4" |
| 75 memsize = "${FLAGS_mem}" |
| 76 ide0:0.present = "TRUE" |
| 77 ide0:0.fileName = "${FLAGS_vmdk}" |
| 78 ethernet0.present = "TRUE" |
| 79 usb.present = "TRUE" |
| 80 sound.present = "TRUE" |
| 81 sound.virtualDev = "es1371" |
| 82 displayName = "ChromeOS" |
| 83 guestOS = "otherlinux" |
| 84 ethernet0.addressType = "generated" |
| 85 floppy0.present = "FALSE" |
| 86 END) |
| 87 |
| 88 if [[ ${FLAGS_make_vmx} ]]; then |
| 89 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" |
| 90 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" |
| 91 echo "${VMX_CONFIG}" |
| 92 fi |
| 93 |
OLD | NEW |