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 and write a | 7 # Script to convert the output of build_image.sh to a VMware image and write a |
8 # corresponding VMware config file. | 8 # corresponding VMware config file. |
9 | 9 |
10 # Load common constants. This should be the first executable line. | 10 # Load common constants. This should be the first executable line. |
11 # 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. |
12 . "$(dirname "$0")/common.sh" | 12 . "$(dirname "$0")/common.sh" |
| 13 . "$(dirname "$0")/chromeos-common.sh" |
13 | 14 |
14 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" | 15 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" |
15 # Default to the most recent image | 16 # Default to the most recent image |
16 DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`" | 17 DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`" |
17 DEFAULT_TO="${DEFAULT_FROM}" | 18 DEFAULT_TO="${DEFAULT_FROM}" |
18 DEFAULT_VMDK="ide.vmdk" | 19 DEFAULT_VMDK="ide.vmdk" |
19 DEFAULT_VMX="chromeos.vmx" | 20 DEFAULT_VMX="chromeos.vmx" |
20 DEFAULT_VBOX_DISK="os.vdi" | 21 DEFAULT_VBOX_DISK="os.vdi" |
21 # Memory units are in MBs | 22 # Memory units are in MBs |
22 DEFAULT_MEM="1024" | 23 DEFAULT_MEM="1024" |
(...skipping 29 matching lines...) Expand all Loading... |
52 | 53 |
53 if [ "$FLAGS_format" != "vmware" ]; then | 54 if [ "$FLAGS_format" != "vmware" ]; then |
54 FLAGS_make_vmx=${FLAGS_FALSE} | 55 FLAGS_make_vmx=${FLAGS_FALSE} |
55 fi | 56 fi |
56 | 57 |
57 # Convert args to paths. Need eval to un-quote the string so that shell | 58 # Convert args to paths. Need eval to un-quote the string so that shell |
58 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. | 59 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. |
59 FLAGS_from=`eval readlink -f $FLAGS_from` | 60 FLAGS_from=`eval readlink -f $FLAGS_from` |
60 FLAGS_to=`eval readlink -f $FLAGS_to` | 61 FLAGS_to=`eval readlink -f $FLAGS_to` |
61 | 62 |
62 # Make two sparse files. One for an empty partition, another for | 63 # Make sure we have the gpt tool |
63 # stateful partition. | 64 if [ -z "$GPT" ]; then |
64 PART_SIZE=$(stat -c%s "${FLAGS_from}/rootfs.image") | 65 echo Unable to find gpt |
65 dd if=/dev/zero of="${FLAGS_from}/empty.image" bs=1 count=1 \ | 66 exit 1 |
66 seek=$(( $PART_SIZE - 1 )) | 67 fi |
67 dd if=/dev/zero of="${FLAGS_from}/state.image" bs=1 count=1 \ | |
68 seek=$(( $PART_SIZE - 1 )) | |
69 mkfs.ext3 -F -L C-STATE "${FLAGS_from}/state.image" | |
70 | 68 |
71 # Fix bootloader config. | 69 # Fix bootloader config. |
72 TEMP_IMG=$(mktemp) | 70 TEMP_IMG=$(mktemp) |
73 TEMP_MNT=$(mktemp -d) | 71 TEMP_MNT=$(mktemp -d) |
74 cp "${FLAGS_from}/rootfs.image" "$TEMP_IMG" | 72 |
| 73 LOOP_DEV=$(sudo losetup -f) |
| 74 if [ -z "$LOOP_DEV" ]; then |
| 75 echo "No free loop device" |
| 76 exit 1 |
| 77 fi |
| 78 |
| 79 # Get rootfs offset |
| 80 OFFSET=$(( $(partoffset "${FLAGS_from}/chromiumos_image.bin" 3) * 512 )) # bytes |
| 81 |
| 82 echo Copying to temp file |
| 83 cp "${FLAGS_from}/chromiumos_image.bin" "$TEMP_IMG" |
| 84 |
| 85 cleanup() { |
| 86 sudo umount "$TEMP_MNT" || true |
| 87 sudo losetup -d "$LOOP_DEV" |
| 88 } |
| 89 trap cleanup INT TERM EXIT |
| 90 sudo losetup -o $OFFSET "$LOOP_DEV" "$TEMP_IMG" |
75 mkdir -p "$TEMP_MNT" | 91 mkdir -p "$TEMP_MNT" |
76 sudo mount -o loop "$TEMP_IMG" "$TEMP_MNT" | 92 sudo mount "$LOOP_DEV" "$TEMP_MNT" |
77 sudo "$TEMP_MNT"/postinst /dev/sda3 | 93 sudo "$TEMP_MNT"/postinst /dev/sda3 |
78 sudo umount "$TEMP_MNT" | 94 trap - INT TERM EXIT |
| 95 cleanup |
79 rmdir "$TEMP_MNT" | 96 rmdir "$TEMP_MNT" |
80 | 97 |
| 98 echo Creating final image |
| 99 # Convert image to output format |
81 if [ "$FLAGS_format" = "virtualbox" ]; then | 100 if [ "$FLAGS_format" = "virtualbox" ]; then |
82 # Copy MBR and rootfs to output image | 101 qemu-img convert -f raw $TEMP_IMG \ |
83 qemu-img convert -f raw \ | |
84 "${FLAGS_from}/mbr.image" "${FLAGS_from}/state.image" \ | |
85 "${FLAGS_from}/empty.image" "$TEMP_IMG" \ | |
86 -O raw "${VBOX_TEMP_IMAGE}" | 102 -O raw "${VBOX_TEMP_IMAGE}" |
87 VBoxManage convertdd "${VBOX_TEMP_IMAGE}" "${FLAGS_to}/${FLAGS_vbox_disk}" | 103 VBoxManage convertdd "${VBOX_TEMP_IMAGE}" "${FLAGS_to}/${FLAGS_vbox_disk}" |
88 elif [ "$FLAGS_format" = "vmware" ]; then | 104 elif [ "$FLAGS_format" = "vmware" ]; then |
89 # Copy MBR and rootfs to output image | 105 qemu-img convert -f raw $TEMP_IMG \ |
90 qemu-img convert -f raw \ | |
91 "${FLAGS_from}/mbr.image" "${FLAGS_from}/state.image" \ | |
92 "${FLAGS_from}/empty.image" "$TEMP_IMG" \ | |
93 -O vmdk "${FLAGS_to}/${FLAGS_vmdk}" | 106 -O vmdk "${FLAGS_to}/${FLAGS_vmdk}" |
94 else | 107 else |
95 echo invalid format: "$FLAGS_format" | 108 echo invalid format: "$FLAGS_format" |
96 exit 1 | 109 exit 1 |
97 fi | 110 fi |
98 | 111 |
99 rm -f "${FLAGS_from}/empty.image" "${FLAGS_from}/state.image" \ | 112 rm -f "$TEMP_IMG" "${VBOX_TEMP_IMAGE}" |
100 "$TEMP_IMG" "${VBOX_TEMP_IMAGE}" | |
101 | 113 |
102 echo "Created image ${FLAGS_to}" | 114 echo "Created image ${FLAGS_to}" |
103 | 115 |
104 # Generate the vmware config file | 116 # Generate the vmware config file |
105 # A good reference doc: http://www.sanbarrow.com/vmx.html | 117 # A good reference doc: http://www.sanbarrow.com/vmx.html |
106 VMX_CONFIG="#!/usr/bin/vmware | 118 VMX_CONFIG="#!/usr/bin/vmware |
107 .encoding = \"UTF-8\" | 119 .encoding = \"UTF-8\" |
108 config.version = \"8\" | 120 config.version = \"8\" |
109 virtualHW.version = \"4\" | 121 virtualHW.version = \"4\" |
110 memsize = \"${FLAGS_mem}\" | 122 memsize = \"${FLAGS_mem}\" |
111 ide0:0.present = \"TRUE\" | 123 ide0:0.present = \"TRUE\" |
112 ide0:0.fileName = \"${FLAGS_vmdk}\" | 124 ide0:0.fileName = \"${FLAGS_vmdk}\" |
113 ethernet0.present = \"TRUE\" | 125 ethernet0.present = \"TRUE\" |
114 usb.present = \"TRUE\" | 126 usb.present = \"TRUE\" |
115 sound.present = \"TRUE\" | 127 sound.present = \"TRUE\" |
116 sound.virtualDev = \"es1371\" | 128 sound.virtualDev = \"es1371\" |
117 displayName = \"Chromium OS\" | 129 displayName = \"Chromium OS\" |
118 guestOS = \"otherlinux\" | 130 guestOS = \"otherlinux\" |
119 ethernet0.addressType = \"generated\" | 131 ethernet0.addressType = \"generated\" |
120 floppy0.present = \"FALSE\"" | 132 floppy0.present = \"FALSE\"" |
121 | 133 |
122 if [[ ${FLAGS_make_vmx} = ${FLAGS_TRUE} ]]; then | 134 if [[ ${FLAGS_make_vmx} = ${FLAGS_TRUE} ]]; then |
123 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" | 135 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" |
124 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" | 136 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" |
125 echo "${VMX_CONFIG}" | 137 echo "${VMX_CONFIG}" |
126 fi | 138 fi |
127 | 139 |
OLD | NEW |