| 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. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 echo "Done with mod_image_for_test." | 108 echo "Done with mod_image_for_test." |
| 109 else | 109 else |
| 110 echo "Using cached test image." | 110 echo "Using cached test image." |
| 111 fi | 111 fi |
| 112 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" | 112 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" |
| 113 echo "Source test image is: ${SRC_IMAGE}" | 113 echo "Source test image is: ${SRC_IMAGE}" |
| 114 fi | 114 fi |
| 115 | 115 |
| 116 # Memory units are in MBs | 116 # Memory units are in MBs |
| 117 DEFAULT_MEM="1024" | 117 DEFAULT_MEM="1024" |
| 118 TEMP_IMAGE="${IMAGES_DIR}/temp_image.img" | 118 TEMP_IMG="$(dirname ${SRC_IMAGE})/vm_temp_image.bin" |
| 119 | |
| 120 | 119 |
| 121 # If we're not building for VMWare, don't build the vmx | 120 # If we're not building for VMWare, don't build the vmx |
| 122 if [ "${FLAGS_format}" != "vmware" ]; then | 121 if [ "${FLAGS_format}" != "vmware" ]; then |
| 123 FLAGS_make_vmx="${FLAGS_FALSE}" | 122 FLAGS_make_vmx="${FLAGS_FALSE}" |
| 124 fi | 123 fi |
| 125 | 124 |
| 126 # Convert args to paths. Need eval to un-quote the string so that shell | 125 # Convert args to paths. Need eval to un-quote the string so that shell |
| 127 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. | 126 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. |
| 128 FLAGS_from=`eval readlink -f $FLAGS_from` | 127 FLAGS_from=`eval readlink -f $FLAGS_from` |
| 129 FLAGS_to=`eval readlink -f $FLAGS_to` | 128 FLAGS_to=`eval readlink -f $FLAGS_to` |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 mkdir -p "${TEMP_ESP_MNT}" | 181 mkdir -p "${TEMP_ESP_MNT}" |
| 183 sudo mount -o loop "${TEMP_ESP}" "${TEMP_ESP_MNT}" | 182 sudo mount -o loop "${TEMP_ESP}" "${TEMP_ESP_MNT}" |
| 184 | 183 |
| 185 if [ "${FLAGS_format}" = "qemu" ]; then | 184 if [ "${FLAGS_format}" = "qemu" ]; then |
| 186 sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \ | 185 sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \ |
| 187 --enable_tablet=true | 186 --enable_tablet=true |
| 188 else | 187 else |
| 189 sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \ | 188 sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \ |
| 190 --enable_tablet=false | 189 --enable_tablet=false |
| 191 fi | 190 fi |
| 192 # Remount read-only so that when we call setimage, it will recreate correct | 191 |
| 193 # boot hashes for verifying the rootfs integrity. This is a bit of a cheat | 192 # Modify the unverified usb template which uses a default usb_disk of sdb3 |
| 194 # but it will have to do. We don't assume legacy bootloaders are secure so | 193 sudo sed -i -e 's/sdb3/sda3/g' "${TEMP_MNT}/boot/syslinux/usb.A.cfg" |
| 195 # we update the hash too, but the hash in part_2 doesn't change which would | 194 |
| 196 # cause failures on a Chrome OS boot (without re-running build_kernel_image). | 195 # Unmount everything prior to building a final image |
| 197 sudo mount -o remount,ro "${TEMP_MNT}" | |
| 198 sync | 196 sync |
| 199 | |
| 200 # Check if the current image was build with --enable_rootfs_verification | |
| 201 enable_rootfs_verification= | |
| 202 if grep -qE '^chromeos-v' "${TEMP_ESP_MNT}"/syslinux/default.cfg; then | |
| 203 enable_rootfs_verification=--enable_rootfs_verification | |
| 204 fi | |
| 205 | |
| 206 # Update the bootloader and verified hashes for the given rootfs in the | |
| 207 # vm and fixup changes. | |
| 208 DST_DEV=/dev/sda | |
| 209 BOOT_SLOT=A | |
| 210 syslinux_cfg="${TEMP_MNT}/boot/syslinux/root.${BOOT_SLOT}.cfg" | |
| 211 grub_cfg="${TEMP_MNT}/boot/efi/boot/grub.cfg" | |
| 212 sudo "${TEMP_MNT}"/usr/sbin/chromeos-setimage ${BOOT_SLOT} \ | |
| 213 --dst=${DST_DEV} --run_as_root \ | |
| 214 --update_syslinux_cfg="${syslinux_cfg}" \ | |
| 215 --update_grub_cfg="${grub_cfg}" \ | |
| 216 --rootfs_image="${TEMP_ROOTFS}" \ | |
| 217 --esp_mounted_at="${TEMP_ESP_MNT}" \ | |
| 218 --kernel_image="${TEMP_KERN}" \ | |
| 219 --update_vmlinuz=${TEMP_MNT}/boot/vmlinuz \ | |
| 220 ${enable_rootfs_verification} | |
| 221 | |
| 222 trap - INT TERM EXIT | 197 trap - INT TERM EXIT |
| 223 cleanup | 198 cleanup |
| 224 | 199 |
| 225 # Make 3 GiB output image | 200 # Make 3 GiB output image |
| 226 TEMP_IMG=$(mktemp) | |
| 227 # 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 |
| 228 sudo dd if=/dev/zero of="${TEMP_IMG}" bs=1 count=1 \ | 202 dd if=/dev/zero of="${TEMP_IMG}" bs=1 count=1 \ |
| 229 seek=$((${FLAGS_vdisk_size} * 1024 * 1024 - 1)) | 203 seek=$((${FLAGS_vdisk_size} * 1024 * 1024 - 1)) |
| 230 | 204 |
| 231 # Set up the partition table | 205 # Set up the partition table |
| 232 install_gpt "${TEMP_IMG}" "$(numsectors $TEMP_ROOTFS)" \ | 206 install_gpt "${TEMP_IMG}" "$(numsectors $TEMP_ROOTFS)" \ |
| 233 "$(numsectors $TEMP_STATE)" "${TEMP_PMBR}" "$(numsectors $TEMP_ESP)" \ | 207 "$(numsectors $TEMP_STATE)" "${TEMP_PMBR}" "$(numsectors $TEMP_ESP)" \ |
| 234 false ${FLAGS_rootfs_partition_size} | 208 false ${FLAGS_rootfs_partition_size} |
| 235 # Copy into the partition parts of the file | 209 # Copy into the partition parts of the file |
| 236 dd if="${TEMP_ROOTFS}" of="${TEMP_IMG}" conv=notrunc bs=512 \ | 210 dd if="${TEMP_ROOTFS}" of="${TEMP_IMG}" conv=notrunc bs=512 \ |
| 237 seek="${START_ROOTFS_A}" | 211 seek="${START_ROOTFS_A}" |
| 238 dd if="${TEMP_STATE}" of="${TEMP_IMG}" conv=notrunc bs=512 \ | 212 dd if="${TEMP_STATE}" of="${TEMP_IMG}" conv=notrunc bs=512 \ |
| 239 seek="${START_STATEFUL}" | 213 seek="${START_STATEFUL}" |
| 240 dd if="${TEMP_KERN}" of="${TEMP_IMG}" conv=notrunc bs=512 \ | 214 dd if="${TEMP_KERN}" of="${TEMP_IMG}" conv=notrunc bs=512 \ |
| 241 seek="${START_KERN_A}" | 215 seek="${START_KERN_A}" |
| 242 dd if="${TEMP_ESP}" of="${TEMP_IMG}" conv=notrunc bs=512 \ | 216 dd if="${TEMP_ESP}" of="${TEMP_IMG}" conv=notrunc bs=512 \ |
| 243 seek="${START_ESP}" | 217 seek="${START_ESP}" |
| 244 | 218 |
| 219 # Make the built-image bootable and ensure that the legacy default usb boot |
| 220 # uses /dev/sda instead of /dev/sdb3. |
| 221 # NOTE: The TEMP_IMG must live in the same image dir as the original image |
| 222 # to operate automatically below. |
| 223 ${SCRIPTS_DIR}/bin/cros_make_image_bootable $(dirname "${TEMP_IMG}") \ |
| 224 $(basename "${TEMP_IMG}") \ |
| 225 --usb_disk /dev/sda3 |
| 226 |
| 245 echo Creating final image | 227 echo Creating final image |
| 246 # Convert image to output format | 228 # Convert image to output format |
| 247 if [ "${FLAGS_format}" = "virtualbox" -o "${FLAGS_format}" = "qemu" ]; then | 229 if [ "${FLAGS_format}" = "virtualbox" -o "${FLAGS_format}" = "qemu" ]; then |
| 248 if [ "${FLAGS_format}" = "virtualbox" ]; then | 230 if [ "${FLAGS_format}" = "virtualbox" ]; then |
| 249 VBoxManage convertdd "${TEMP_IMG}" "${FLAGS_to}/${FLAGS_vbox_disk}" | 231 VBoxManage convertdd "${TEMP_IMG}" "${FLAGS_to}/${FLAGS_vbox_disk}" |
| 250 else | 232 else |
| 251 mv ${TEMP_IMG} ${FLAGS_to}/${DEFAULT_QEMU_IMAGE} | 233 mv ${TEMP_IMG} ${FLAGS_to}/${DEFAULT_QEMU_IMAGE} |
| 252 fi | 234 fi |
| 253 elif [ "${FLAGS_format}" = "vmware" ]; then | 235 elif [ "${FLAGS_format}" = "vmware" ]; then |
| 254 qemu-img convert -f raw "${TEMP_IMG}" \ | 236 qemu-img convert -f raw "${TEMP_IMG}" \ |
| (...skipping 26 matching lines...) Expand all Loading... |
| 281 guestOS = \"otherlinux\" | 263 guestOS = \"otherlinux\" |
| 282 ethernet0.addressType = \"generated\" | 264 ethernet0.addressType = \"generated\" |
| 283 floppy0.present = \"FALSE\"" | 265 floppy0.present = \"FALSE\"" |
| 284 | 266 |
| 285 if [[ "${FLAGS_make_vmx}" = "${FLAGS_TRUE}" ]]; then | 267 if [[ "${FLAGS_make_vmx}" = "${FLAGS_TRUE}" ]]; then |
| 286 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" | 268 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" |
| 287 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" | 269 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" |
| 288 echo "${VMX_CONFIG}" | 270 echo "${VMX_CONFIG}" |
| 289 fi | 271 fi |
| 290 | 272 |
| OLD | NEW |