OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 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 . "$(dirname "$0")/chromeos-common.sh" |
14 | 14 |
15 get_default_board | 15 get_default_board |
| 16 assert_inside_chroot |
16 | 17 |
| 18 DEFAULT_MEM="1024" |
17 DEFAULT_VMDK="ide.vmdk" | 19 DEFAULT_VMDK="ide.vmdk" |
18 DEFAULT_VMX="chromiumos.vmx" | 20 DEFAULT_VMX="chromiumos.vmx" |
19 DEFAULT_VBOX_DISK="os.vdi" | 21 DEFAULT_VBOX_DISK="os.vdi" |
20 DEFAULT_QEMU_IMAGE="chromiumos_qemu_image.bin" | 22 DEFAULT_QEMU_IMAGE="chromiumos_qemu_image.bin" |
21 | 23 |
| 24 # Minimum sizes for full size vm images -- needed for update. |
| 25 MIN_VDISK_SIZE_FULL=6072 |
| 26 MIN_STATEFUL_FS_SIZE_FULL=2048 |
| 27 |
22 MOD_SCRIPTS_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" | 28 MOD_SCRIPTS_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" |
23 | 29 |
24 # Flags | 30 # Flags |
25 DEFINE_string board "${DEFAULT_BOARD}" \ | 31 DEFINE_string board "${DEFAULT_BOARD}" \ |
26 "Board for which the image was built" | 32 "Board for which the image was built" |
27 DEFINE_boolean factory $FLAGS_FALSE \ | 33 DEFINE_boolean factory $FLAGS_FALSE \ |
28 "Modify the image for manufacturing testing" | 34 "Modify the image for manufacturing testing" |
29 DEFINE_boolean factory_install $FLAGS_FALSE \ | 35 DEFINE_boolean factory_install $FLAGS_FALSE \ |
30 "Modify the image for factory install shim" | 36 "Modify the image for factory install shim" |
31 DEFINE_boolean force_copy ${FLAGS_FALSE} "Always rebuild test image" | 37 DEFINE_boolean force_copy ${FLAGS_FALSE} "Always rebuild test image" |
32 DEFINE_string format "qemu" \ | 38 DEFINE_string format "qemu" \ |
33 "Output format, either qemu, vmware or virtualbox" | 39 "Output format, either qemu, vmware or virtualbox" |
34 DEFINE_string from "" \ | 40 DEFINE_string from "" \ |
35 "Directory containing rootfs.image and mbr.image" | 41 "Directory containing rootfs.image and mbr.image" |
| 42 DEFINE_boolean full "${FLAGS_FALSE}" "Build full image with all partitions." |
36 DEFINE_boolean make_vmx ${FLAGS_TRUE} \ | 43 DEFINE_boolean make_vmx ${FLAGS_TRUE} \ |
37 "Create a vmx file for use with vmplayer (vmware only)." | 44 "Create a vmx file for use with vmplayer (vmware only)." |
38 DEFINE_integer mem "${DEFAULT_MEM}" \ | 45 DEFINE_integer mem "${DEFAULT_MEM}" \ |
39 "Memory size for the vm config in MBs (vmware only)." | 46 "Memory size for the vm config in MBs (vmware only)." |
40 DEFINE_integer rootfs_partition_size 1024 \ | 47 DEFINE_integer rootfs_partition_size 1024 \ |
41 "rootfs parition size in MBs." | 48 "rootfs parition size in MBs." |
42 DEFINE_string state_image "" \ | 49 DEFINE_string state_image "" \ |
43 "Stateful partition image (defaults to creating new statful partition)" | 50 "Stateful partition image (defaults to creating new statful partition)" |
44 DEFINE_integer statefulfs_size -1 \ | 51 DEFINE_integer statefulfs_size -1 \ |
45 "Stateful partition size in MBs." | 52 "Stateful partition size in MBs." |
(...skipping 14 matching lines...) Expand all Loading... |
60 FLAGS "$@" || exit 1 | 67 FLAGS "$@" || exit 1 |
61 eval set -- "${FLAGS_ARGV}" | 68 eval set -- "${FLAGS_ARGV}" |
62 | 69 |
63 # Die on any errors. | 70 # Die on any errors. |
64 set -e | 71 set -e |
65 | 72 |
66 if [ -z "${FLAGS_board}" ] ; then | 73 if [ -z "${FLAGS_board}" ] ; then |
67 die "--board is required." | 74 die "--board is required." |
68 fi | 75 fi |
69 | 76 |
| 77 if [ "${FLAGS_full}" -eq "${FLAGS_TRUE}" ] && \ |
| 78 ( [[ ${FLAGS_vdisk_size} < ${MIN_VDISK_SIZE_FULL} ]] || \ |
| 79 [[ ${FLAGS_statefulfs_size} < ${MIN_STATEFUL_FS_SIZE_FULL} ]]); then |
| 80 die "Disk is too small for full, please select a vdisk size greater than \ |
| 81 ${MIN_VDISK_SIZE_FULL} and statefulfs size greater than \ |
| 82 ${MIN_STATEFUL_FS_SIZE_FULL}." |
| 83 fi |
| 84 |
70 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" | 85 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" |
71 # Default to the most recent image | 86 # Default to the most recent image |
72 if [ -z "${FLAGS_from}" ] ; then | 87 if [ -z "${FLAGS_from}" ] ; then |
73 FLAGS_from="${IMAGES_DIR}/$(ls -t $IMAGES_DIR | head -1)" | 88 FLAGS_from="${IMAGES_DIR}/$(ls -t $IMAGES_DIR | head -1)" |
74 else | 89 else |
75 pushd "${FLAGS_from}" && FLAGS_from=`pwd` && popd | 90 pushd "${FLAGS_from}" && FLAGS_from=`pwd` && popd |
76 fi | 91 fi |
77 if [ -z "${FLAGS_to}" ] ; then | 92 if [ -z "${FLAGS_to}" ] ; then |
78 FLAGS_to="${FLAGS_from}" | 93 FLAGS_to="${FLAGS_from}" |
79 fi | 94 fi |
(...skipping 27 matching lines...) Expand all Loading... |
107 "${FLAGS_from}/chromiumos_test_image.bin" ${EXTRA_ARGS} --yes | 122 "${FLAGS_from}/chromiumos_test_image.bin" ${EXTRA_ARGS} --yes |
108 echo "Done with mod_image_for_test." | 123 echo "Done with mod_image_for_test." |
109 else | 124 else |
110 echo "Using cached test image." | 125 echo "Using cached test image." |
111 fi | 126 fi |
112 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" | 127 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" |
113 echo "Source test image is: ${SRC_IMAGE}" | 128 echo "Source test image is: ${SRC_IMAGE}" |
114 fi | 129 fi |
115 | 130 |
116 # Memory units are in MBs | 131 # Memory units are in MBs |
117 DEFAULT_MEM="1024" | |
118 TEMP_IMG="$(dirname ${SRC_IMAGE})/vm_temp_image.bin" | 132 TEMP_IMG="$(dirname ${SRC_IMAGE})/vm_temp_image.bin" |
119 | 133 |
120 # If we're not building for VMWare, don't build the vmx | 134 # If we're not building for VMWare, don't build the vmx |
121 if [ "${FLAGS_format}" != "vmware" ]; then | 135 if [ "${FLAGS_format}" != "vmware" ]; then |
122 FLAGS_make_vmx="${FLAGS_FALSE}" | 136 FLAGS_make_vmx="${FLAGS_FALSE}" |
123 fi | 137 fi |
124 | 138 |
125 # Convert args to paths. Need eval to un-quote the string so that shell | 139 # Convert args to paths. Need eval to un-quote the string so that shell |
126 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. | 140 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. |
127 FLAGS_from=`eval readlink -f $FLAGS_from` | 141 FLAGS_from=`eval readlink -f $FLAGS_from` |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 sudo umount -d "${TEMP_ESP_MNT}" | 189 sudo umount -d "${TEMP_ESP_MNT}" |
176 rmdir "${TEMP_MNT}" "${TEMP_ESP_MNT}" | 190 rmdir "${TEMP_MNT}" "${TEMP_ESP_MNT}" |
177 } | 191 } |
178 trap cleanup INT TERM EXIT | 192 trap cleanup INT TERM EXIT |
179 mkdir -p "${TEMP_MNT}" | 193 mkdir -p "${TEMP_MNT}" |
180 sudo mount -o loop "${TEMP_ROOTFS}" "${TEMP_MNT}" | 194 sudo mount -o loop "${TEMP_ROOTFS}" "${TEMP_MNT}" |
181 mkdir -p "${TEMP_ESP_MNT}" | 195 mkdir -p "${TEMP_ESP_MNT}" |
182 sudo mount -o loop "${TEMP_ESP}" "${TEMP_ESP_MNT}" | 196 sudo mount -o loop "${TEMP_ESP}" "${TEMP_ESP_MNT}" |
183 | 197 |
184 if [ "${FLAGS_format}" = "qemu" ]; then | 198 if [ "${FLAGS_format}" = "qemu" ]; then |
185 sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \ | 199 sudo python "$(dirname $0)/fixup_image_for_qemu.py" \ |
186 --enable_tablet=true | 200 --mounted_dir="${TEMP_MNT}" \ |
| 201 --enable_tablet=true |
187 else | 202 else |
188 sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \ | 203 sudo python "$(dirname $0)/fixup_image_for_qemu.py" \ |
189 --enable_tablet=false | 204 --mounted_dir="${TEMP_MNT}" \ |
| 205 --enable_tablet=false |
190 fi | 206 fi |
191 | 207 |
192 # Modify the unverified usb template which uses a default usb_disk of sdb3 | 208 # Modify the unverified usb template which uses a default usb_disk of sdb3 |
193 sudo sed -i -e 's/sdb3/sda3/g' "${TEMP_MNT}/boot/syslinux/usb.A.cfg" | 209 sudo sed -i -e 's/sdb3/sda3/g' "${TEMP_MNT}/boot/syslinux/usb.A.cfg" |
194 | 210 |
195 # Unmount everything prior to building a final image | 211 # Unmount everything prior to building a final image |
196 sync | 212 sync |
197 trap - INT TERM EXIT | 213 trap - INT TERM EXIT |
198 cleanup | 214 cleanup |
199 | 215 |
200 # Make 3 GiB output image | 216 # TOOD(adlr): pick a size that will for sure accomodate the partitions. |
201 # TOOD(adlr): pick a size that will for sure accomodate the partitions | |
202 dd if=/dev/zero of="${TEMP_IMG}" bs=1 count=1 \ | 217 dd if=/dev/zero of="${TEMP_IMG}" bs=1 count=1 \ |
203 seek=$((${FLAGS_vdisk_size} * 1024 * 1024 - 1)) | 218 seek=$((${FLAGS_vdisk_size} * 1024 * 1024 - 1)) |
204 | 219 |
| 220 GPT_FULL="false" |
| 221 [ "${FLAGS_full}" -eq "${FLAGS_TRUE}" ] && GPT_FULL="true" |
| 222 |
205 # Set up the partition table | 223 # Set up the partition table |
206 install_gpt "${TEMP_IMG}" "$(numsectors $TEMP_ROOTFS)" \ | 224 install_gpt "${TEMP_IMG}" "$(numsectors $TEMP_ROOTFS)" \ |
207 "$(numsectors $TEMP_STATE)" "${TEMP_PMBR}" "$(numsectors $TEMP_ESP)" \ | 225 "$(numsectors $TEMP_STATE)" "${TEMP_PMBR}" "$(numsectors $TEMP_ESP)" \ |
208 false ${FLAGS_rootfs_partition_size} | 226 "${GPT_FULL}" ${FLAGS_rootfs_partition_size} |
209 # Copy into the partition parts of the file | 227 # Copy into the partition parts of the file |
210 dd if="${TEMP_ROOTFS}" of="${TEMP_IMG}" conv=notrunc bs=512 \ | 228 dd if="${TEMP_ROOTFS}" of="${TEMP_IMG}" conv=notrunc bs=512 \ |
211 seek="${START_ROOTFS_A}" | 229 seek="${START_ROOTFS_A}" |
212 dd if="${TEMP_STATE}" of="${TEMP_IMG}" conv=notrunc bs=512 \ | 230 dd if="${TEMP_STATE}" of="${TEMP_IMG}" conv=notrunc bs=512 \ |
213 seek="${START_STATEFUL}" | 231 seek="${START_STATEFUL}" |
214 dd if="${TEMP_KERN}" of="${TEMP_IMG}" conv=notrunc bs=512 \ | 232 dd if="${TEMP_KERN}" of="${TEMP_IMG}" conv=notrunc bs=512 \ |
215 seek="${START_KERN_A}" | 233 seek="${START_KERN_A}" |
216 dd if="${TEMP_ESP}" of="${TEMP_IMG}" conv=notrunc bs=512 \ | 234 dd if="${TEMP_ESP}" of="${TEMP_IMG}" conv=notrunc bs=512 \ |
217 seek="${START_ESP}" | 235 seek="${START_ESP}" |
218 | 236 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 guestOS = \"otherlinux\" | 281 guestOS = \"otherlinux\" |
264 ethernet0.addressType = \"generated\" | 282 ethernet0.addressType = \"generated\" |
265 floppy0.present = \"FALSE\"" | 283 floppy0.present = \"FALSE\"" |
266 | 284 |
267 if [[ "${FLAGS_make_vmx}" = "${FLAGS_TRUE}" ]]; then | 285 if [[ "${FLAGS_make_vmx}" = "${FLAGS_TRUE}" ]]; then |
268 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" | 286 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" |
269 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" | 287 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" |
270 echo "${VMX_CONFIG}" | 288 echo "${VMX_CONFIG}" |
271 fi | 289 fi |
272 | 290 |
OLD | NEW |