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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 130 |
131 # Split apart the partitions and make some new ones | 131 # Split apart the partitions and make some new ones |
132 TEMP_DIR=$(mktemp -d) | 132 TEMP_DIR=$(mktemp -d) |
133 (cd "${TEMP_DIR}" && | 133 (cd "${TEMP_DIR}" && |
134 "${FLAGS_from}/unpack_partitions.sh" "${SRC_IMAGE}") | 134 "${FLAGS_from}/unpack_partitions.sh" "${SRC_IMAGE}") |
135 | 135 |
136 # Fix the kernel command line | 136 # Fix the kernel command line |
137 TEMP_ESP="${TEMP_DIR}"/part_12 | 137 TEMP_ESP="${TEMP_DIR}"/part_12 |
138 TEMP_ROOTFS="${TEMP_DIR}"/part_3 | 138 TEMP_ROOTFS="${TEMP_DIR}"/part_3 |
139 TEMP_STATE="${TEMP_DIR}"/part_1 | 139 TEMP_STATE="${TEMP_DIR}"/part_1 |
| 140 TEMP_KERN="${TEMP_DIR}"/part_2 |
140 if [ -n "${FLAGS_state_image}" ]; then | 141 if [ -n "${FLAGS_state_image}" ]; then |
141 TEMP_STATE="${FLAGS_state_image}" | 142 TEMP_STATE="${FLAGS_state_image}" |
142 else | 143 else |
143 # If we have a stateful fs size specified create a new state partition | 144 # If we have a stateful fs size specified create a new state partition |
144 # of the specified size. | 145 # of the specified size. |
145 if [ "${FLAGS_statefulfs_size}" -ne -1 ]; then | 146 if [ "${FLAGS_statefulfs_size}" -ne -1 ]; then |
146 STATEFUL_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_statefulfs_size})) | 147 STATEFUL_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_statefulfs_size})) |
147 original_image_size=$(stat -c%s "${TEMP_STATE}") | 148 original_image_size=$(stat -c%s "${TEMP_STATE}") |
148 if [ "${original_image_size}" -gt "${STATEFUL_SIZE_BYTES}" ]; then | 149 if [ "${original_image_size}" -gt "${STATEFUL_SIZE_BYTES}" ]; then |
149 die "Cannot resize stateful image to smaller than original. Exiting." | 150 die "Cannot resize stateful image to smaller than original. Exiting." |
(...skipping 13 matching lines...) Expand all Loading... |
163 sudo e2fsck -f "${STATEFUL_LOOP_DEV}" | 164 sudo e2fsck -f "${STATEFUL_LOOP_DEV}" |
164 sudo resize2fs "${STATEFUL_LOOP_DEV}" | 165 sudo resize2fs "${STATEFUL_LOOP_DEV}" |
165 sudo losetup -d "${STATEFUL_LOOP_DEV}" | 166 sudo losetup -d "${STATEFUL_LOOP_DEV}" |
166 fi | 167 fi |
167 fi | 168 fi |
168 TEMP_KERN="${TEMP_DIR}"/part_2 | 169 TEMP_KERN="${TEMP_DIR}"/part_2 |
169 TEMP_PMBR="${TEMP_DIR}"/pmbr | 170 TEMP_PMBR="${TEMP_DIR}"/pmbr |
170 dd if="${SRC_IMAGE}" of="${TEMP_PMBR}" bs=512 count=1 | 171 dd if="${SRC_IMAGE}" of="${TEMP_PMBR}" bs=512 count=1 |
171 | 172 |
172 TEMP_MNT=$(mktemp -d) | 173 TEMP_MNT=$(mktemp -d) |
| 174 TEMP_ESP_MNT=$(mktemp -d) |
173 cleanup() { | 175 cleanup() { |
174 sudo umount -d "${TEMP_MNT}" | 176 sudo umount -d "${TEMP_MNT}" |
175 rmdir "${TEMP_MNT}" | 177 sudo umount -d "${TEMP_ESP_MNT}" |
| 178 rmdir "${TEMP_MNT}" "${TEMP_ESP_MNT}" |
176 } | 179 } |
177 trap cleanup INT TERM EXIT | 180 trap cleanup INT TERM EXIT |
178 mkdir -p "${TEMP_MNT}" | 181 mkdir -p "${TEMP_MNT}" |
179 sudo mount -o loop "${TEMP_ROOTFS}" "${TEMP_MNT}" | 182 sudo mount -o loop "${TEMP_ROOTFS}" "${TEMP_MNT}" |
| 183 mkdir -p "${TEMP_ESP_MNT}" |
| 184 sudo mount -o loop "${TEMP_ESP}" "${TEMP_ESP_MNT}" |
| 185 |
180 if [ "${FLAGS_format}" = "qemu" ]; then | 186 if [ "${FLAGS_format}" = "qemu" ]; then |
181 sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \ | 187 sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \ |
182 --enable_tablet=true | 188 --enable_tablet=true |
183 else | 189 else |
184 sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \ | 190 sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \ |
185 --enable_tablet=false | 191 --enable_tablet=false |
186 fi | 192 fi |
| 193 # Remount read-only so that when we call setimage, it will recreate correct |
| 194 # boot hashes for verifying the rootfs integrity. This is a bit of a cheat |
| 195 # but it will have to do. We don't assume legacy bootloaders are secure so |
| 196 # we update the hash too, but the hash in part_2 doesn't change which would |
| 197 # cause failures on a Chrome OS boot (without re-running build_kernel_image). |
| 198 sudo mount -o remount,ro "${TEMP_MNT}" |
| 199 sync |
187 | 200 |
188 # Change this value if the rootfs partition changes | 201 # Check if the current image was build with --enable_rootfs_verification |
189 ROOTFS_PARTITION=/dev/sda3 | 202 enable_rootfs_verification= |
190 sudo "${TEMP_MNT}"/postinst "${ROOTFS_PARTITION}" --esp_part_file="${TEMP_ESP}" | 203 if grep -qE '^chromeos-v' "${TEMP_ESP_MNT}"/syslinux/default.cfg; then |
| 204 enable_rootfs_verification=--enable_rootfs_verification |
| 205 fi |
| 206 |
| 207 # Update the bootloader and verified hashes for the given rootfs in the |
| 208 # vm and fixup changes. |
| 209 DST_DEV=/dev/sda |
| 210 BOOT_SLOT=A |
| 211 syslinux_cfg="${TEMP_MNT}/boot/syslinux/root.${BOOT_SLOT}.cfg" |
| 212 grub_cfg="${TEMP_MNT}/boot/efi/boot/grub.cfg" |
| 213 sudo "${TEMP_MNT}"/usr/sbin/chromeos-setimage ${BOOT_SLOT} \ |
| 214 --dst=${DST_DEV} --run_as_root \ |
| 215 --update_syslinux_cfg="${syslinux_cfg}" \ |
| 216 --update_grub_cfg="${grub_cfg}" \ |
| 217 --rootfs_image="${TEMP_ROOTFS}" \ |
| 218 --esp_mounted_at="${TEMP_ESP_MNT}" \ |
| 219 --kernel_image="${TEMP_KERN}" \ |
| 220 --update_vmlinuz=${TEMP_MNT}/boot/vmlinuz \ |
| 221 ${enable_rootfs_verification} |
| 222 |
191 trap - INT TERM EXIT | 223 trap - INT TERM EXIT |
192 cleanup | 224 cleanup |
193 | 225 |
194 # Make 3 GiB output image | 226 # Make 3 GiB output image |
195 TEMP_IMG=$(mktemp) | 227 TEMP_IMG=$(mktemp) |
196 # TOOD(adlr): pick a size that will for sure accomodate the partitions | 228 # TOOD(adlr): pick a size that will for sure accomodate the partitions |
197 sudo dd if=/dev/zero of="${TEMP_IMG}" bs=1 count=1 \ | 229 sudo dd if=/dev/zero of="${TEMP_IMG}" bs=1 count=1 \ |
198 seek=$((${FLAGS_vdisk_size} * 1024 * 1024 - 1)) | 230 seek=$((${FLAGS_vdisk_size} * 1024 * 1024 - 1)) |
199 | 231 |
200 # Set up the partition table | 232 # Set up the partition table |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 guestOS = \"otherlinux\" | 281 guestOS = \"otherlinux\" |
250 ethernet0.addressType = \"generated\" | 282 ethernet0.addressType = \"generated\" |
251 floppy0.present = \"FALSE\"" | 283 floppy0.present = \"FALSE\"" |
252 | 284 |
253 if [[ "${FLAGS_make_vmx}" = "${FLAGS_TRUE}" ]]; then | 285 if [[ "${FLAGS_make_vmx}" = "${FLAGS_TRUE}" ]]; then |
254 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" | 286 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" |
255 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" | 287 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" |
256 echo "${VMX_CONFIG}" | 288 echo "${VMX_CONFIG}" |
257 fi | 289 fi |
258 | 290 |
OLD | NEW |