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 23 matching lines...) Expand all Loading... |
34 DEFINE_string from "" \ | 34 DEFINE_string from "" \ |
35 "Directory containing rootfs.image and mbr.image" | 35 "Directory containing rootfs.image and mbr.image" |
36 DEFINE_boolean make_vmx ${FLAGS_TRUE} \ | 36 DEFINE_boolean make_vmx ${FLAGS_TRUE} \ |
37 "Create a vmx file for use with vmplayer (vmware only)." | 37 "Create a vmx file for use with vmplayer (vmware only)." |
38 DEFINE_integer mem "${DEFAULT_MEM}" \ | 38 DEFINE_integer mem "${DEFAULT_MEM}" \ |
39 "Memory size for the vm config in MBs (vmware only)." | 39 "Memory size for the vm config in MBs (vmware only)." |
40 DEFINE_integer rootfs_partition_size 1024 \ | 40 DEFINE_integer rootfs_partition_size 1024 \ |
41 "rootfs parition size in MBs." | 41 "rootfs parition size in MBs." |
42 DEFINE_string state_image "" \ | 42 DEFINE_string state_image "" \ |
43 "Stateful partition image (defaults to creating new statful partition)" | 43 "Stateful partition image (defaults to creating new statful partition)" |
| 44 DEFINE_integer statefulfs_size -1 \ |
| 45 "Stateful partition size in MBs." |
44 DEFINE_boolean test_image "${FLAGS_FALSE}" \ | 46 DEFINE_boolean test_image "${FLAGS_FALSE}" \ |
45 "Copies normal image to chromiumos_test_image.bin, modifies it for test." | 47 "Copies normal image to chromiumos_test_image.bin, modifies it for test." |
46 DEFINE_string to "" \ | 48 DEFINE_string to "" \ |
47 "Destination folder for VM output file(s)" | 49 "Destination folder for VM output file(s)" |
48 DEFINE_string vbox_disk "${DEFAULT_VBOX_DISK}" \ | 50 DEFINE_string vbox_disk "${DEFAULT_VBOX_DISK}" \ |
49 "Filename for the output disk (virtualbox only)." | 51 "Filename for the output disk (virtualbox only)." |
50 DEFINE_integer vdisk_size 3072 \ | 52 DEFINE_integer vdisk_size 3072 \ |
51 "virtual disk size in MBs." | 53 "virtual disk size in MBs." |
52 DEFINE_string vmdk "${DEFAULT_VMDK}" \ | 54 DEFINE_string vmdk "${DEFAULT_VMDK}" \ |
53 "Filename for the vmware disk image (vmware only)." | 55 "Filename for the vmware disk image (vmware only)." |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 TEMP_DIR=$(mktemp -d) | 132 TEMP_DIR=$(mktemp -d) |
131 (cd "${TEMP_DIR}" && | 133 (cd "${TEMP_DIR}" && |
132 "${FLAGS_from}/unpack_partitions.sh" "${SRC_IMAGE}") | 134 "${FLAGS_from}/unpack_partitions.sh" "${SRC_IMAGE}") |
133 | 135 |
134 # Fix the kernel command line | 136 # Fix the kernel command line |
135 TEMP_ESP="${TEMP_DIR}"/part_12 | 137 TEMP_ESP="${TEMP_DIR}"/part_12 |
136 TEMP_ROOTFS="${TEMP_DIR}"/part_3 | 138 TEMP_ROOTFS="${TEMP_DIR}"/part_3 |
137 TEMP_STATE="${TEMP_DIR}"/part_1 | 139 TEMP_STATE="${TEMP_DIR}"/part_1 |
138 if [ -n "${FLAGS_state_image}" ]; then | 140 if [ -n "${FLAGS_state_image}" ]; then |
139 TEMP_STATE="${FLAGS_state_image}" | 141 TEMP_STATE="${FLAGS_state_image}" |
| 142 else |
| 143 # If we have a stateful fs size specified create a new state partition |
| 144 # of the specified size. |
| 145 if [ "${FLAGS_statefulfs_size}" -ne -1 ]; then |
| 146 STATEFUL_SIZE_BYTES=$((1024 * 1024 * ${FLAGS_statefulfs_size})) |
| 147 original_image_size=$(stat -c%s "${TEMP_STATE}") |
| 148 if [ "${original_image_size}" -gt "${STATEFUL_SIZE_BYTES}" ]; then |
| 149 die "Cannot resize stateful image to smaller than original. Exiting." |
| 150 fi |
| 151 |
| 152 echo "Resizing stateful partition to ${FLAGS_statefulfs_size}MB" |
| 153 STATEFUL_LOOP_DEV=$(sudo losetup -f) |
| 154 if [ -z "${STATEFUL_LOOP_DEV}" ]; then |
| 155 die "No free loop device. Free up a loop device or reboot. Exiting." |
| 156 fi |
| 157 |
| 158 # Extend the original file size to the new size. |
| 159 dd if=/dev/zero of="${TEMP_STATE}" bs=1 count=1 \ |
| 160 seek=$((STATEFUL_SIZE_BYTES - 1)) |
| 161 # Resize the partition. |
| 162 sudo losetup "${STATEFUL_LOOP_DEV}" "${TEMP_STATE}" |
| 163 sudo e2fsck -f "${STATEFUL_LOOP_DEV}" |
| 164 sudo resize2fs "${STATEFUL_LOOP_DEV}" |
| 165 sudo losetup -d "${STATEFUL_LOOP_DEV}" |
| 166 fi |
140 fi | 167 fi |
141 TEMP_KERN="${TEMP_DIR}"/part_2 | 168 TEMP_KERN="${TEMP_DIR}"/part_2 |
142 TEMP_PMBR="${TEMP_DIR}"/pmbr | 169 TEMP_PMBR="${TEMP_DIR}"/pmbr |
143 dd if="${SRC_IMAGE}" of="${TEMP_PMBR}" bs=512 count=1 | 170 dd if="${SRC_IMAGE}" of="${TEMP_PMBR}" bs=512 count=1 |
144 | 171 |
145 TEMP_MNT=$(mktemp -d) | 172 TEMP_MNT=$(mktemp -d) |
146 cleanup() { | 173 cleanup() { |
147 sudo umount -d "${TEMP_MNT}" | 174 sudo umount -d "${TEMP_MNT}" |
148 rmdir "${TEMP_MNT}" | 175 rmdir "${TEMP_MNT}" |
149 } | 176 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 guestOS = \"otherlinux\" | 249 guestOS = \"otherlinux\" |
223 ethernet0.addressType = \"generated\" | 250 ethernet0.addressType = \"generated\" |
224 floppy0.present = \"FALSE\"" | 251 floppy0.present = \"FALSE\"" |
225 | 252 |
226 if [[ "${FLAGS_make_vmx}" = "${FLAGS_TRUE}" ]]; then | 253 if [[ "${FLAGS_make_vmx}" = "${FLAGS_TRUE}" ]]; then |
227 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" | 254 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" |
228 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" | 255 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" |
229 echo "${VMX_CONFIG}" | 256 echo "${VMX_CONFIG}" |
230 fi | 257 fi |
231 | 258 |
OLD | NEW |