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. |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 # Flags | 27 # Flags |
28 DEFINE_string from "$DEFAULT_FROM" \ | 28 DEFINE_string from "$DEFAULT_FROM" \ |
29 "Directory containing rootfs.image and mbr.image" | 29 "Directory containing rootfs.image and mbr.image" |
30 DEFINE_string to "$DEFAULT_TO" \ | 30 DEFINE_string to "$DEFAULT_TO" \ |
31 "Destination folder for VM output file(s)" | 31 "Destination folder for VM output file(s)" |
32 DEFINE_string state_image "" \ | 32 DEFINE_string state_image "" \ |
33 "Stateful partition image (defaults to creating new statful partition)" | 33 "Stateful partition image (defaults to creating new statful partition)" |
34 DEFINE_string format "vmware" \ | 34 DEFINE_string format "vmware" \ |
35 "Output format, either vmware or virtualbox" | 35 "Output format, either vmware or virtualbox" |
36 | 36 |
37 DEFINE_boolean make_vmx ${FLAGS_TRUE} \ | 37 DEFINE_boolean make_vmx ${FLAGS_TRUE} \ |
38 "Create a vmx file for use with vmplayer (vmware only)." | 38 "Create a vmx file for use with vmplayer (vmware only)." |
39 DEFINE_string vmdk "$DEFAULT_VMDK" \ | 39 DEFINE_string vmdk "$DEFAULT_VMDK" \ |
40 "Filename for the vmware disk image (vmware only)." | 40 "Filename for the vmware disk image (vmware only)." |
41 DEFINE_string vmx "$DEFAULT_VMX" \ | 41 DEFINE_string vmx "$DEFAULT_VMX" \ |
42 "Filename for the vmware config (vmware only)." | 42 "Filename for the vmware config (vmware only)." |
43 DEFINE_integer mem "$DEFAULT_MEM" \ | 43 DEFINE_integer mem "$DEFAULT_MEM" \ |
44 "Memory size for the vm config in MBs (vmware only)." | 44 "Memory size for the vm config in MBs (vmware only)." |
45 | 45 |
46 DEFINE_string vbox_disk "$DEFAULT_VBOX_DISK" \ | 46 DEFINE_string vbox_disk "$DEFAULT_VBOX_DISK" \ |
47 "Filename for the output disk (virtualbox only)." | 47 "Filename for the output disk (virtualbox only)." |
48 | 48 |
49 # Parse command line | 49 # Parse command line |
50 FLAGS "$@" || exit 1 | 50 FLAGS "$@" || exit 1 |
51 eval set -- "${FLAGS_ARGV}" | 51 eval set -- "${FLAGS_ARGV}" |
52 | 52 |
53 # Die on any errors. | 53 # Die on any errors. |
54 set -e | 54 set -e |
55 | 55 |
56 if [ "$FLAGS_format" != "vmware" ]; then | 56 if [ "$FLAGS_format" != "vmware" ]; then |
57 FLAGS_make_vmx=${FLAGS_FALSE} | 57 FLAGS_make_vmx=${FLAGS_FALSE} |
58 fi | 58 fi |
59 | 59 |
60 # Convert args to paths. Need eval to un-quote the string so that shell | 60 # Convert args to paths. Need eval to un-quote the string so that shell |
61 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. | 61 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. |
62 FLAGS_from=`eval readlink -f $FLAGS_from` | 62 FLAGS_from=`eval readlink -f $FLAGS_from` |
63 FLAGS_to=`eval readlink -f $FLAGS_to` | 63 FLAGS_to=`eval readlink -f $FLAGS_to` |
64 | 64 |
65 # Split apart the partitions and make some new ones | 65 # Split apart the partitions and make some new ones |
66 TEMP_DIR=$(mktemp -d) | 66 TEMP_DIR=$(mktemp -d) |
67 (cd "$TEMP_DIR" && | 67 (cd "$TEMP_DIR" && |
68 "${FLAGS_from}/unpack_partitions.sh" "${FLAGS_from}/chromiumos_image.bin") | 68 "${FLAGS_from}/unpack_partitions.sh" "${FLAGS_from}/chromiumos_image.bin") |
69 | 69 |
70 # Fix the kernel command line | 70 # Fix the kernel command line |
| 71 # FIXME: TEMP_ESP is only partition 4 at the moment. It may change! |
| 72 TEMP_ESP="$TEMP_DIR"/part_4 |
71 TEMP_ROOTFS="$TEMP_DIR"/part_3 | 73 TEMP_ROOTFS="$TEMP_DIR"/part_3 |
72 TEMP_STATE="$TEMP_DIR"/part_1 | 74 TEMP_STATE="$TEMP_DIR"/part_1 |
73 if [ -n "${FLAGS_state_image}" ]; then | 75 if [ -n "${FLAGS_state_image}" ]; then |
74 TEMP_STATE="${FLAGS_state_image}" | 76 TEMP_STATE="${FLAGS_state_image}" |
75 fi | 77 fi |
76 TEMP_KERN="$TEMP_DIR"/part_2 | 78 TEMP_KERN="$TEMP_DIR"/part_2 |
77 TEMP_PMBR="$TEMP_DIR"/pmbr | 79 TEMP_PMBR="$TEMP_DIR"/pmbr |
78 dd if="${FLAGS_from}/chromiumos_image.bin" of="$TEMP_PMBR" bs=512 count=1 | 80 dd if="${FLAGS_from}/chromiumos_image.bin" of="$TEMP_PMBR" bs=512 count=1 |
79 | 81 |
80 TEMP_MNT=$(mktemp -d) | 82 TEMP_MNT=$(mktemp -d) |
81 cleanup() { | 83 cleanup() { |
82 sudo umount -d "$TEMP_MNT" | 84 sudo umount -d "$TEMP_MNT" |
83 rmdir "$TEMP_MNT" | 85 rmdir "$TEMP_MNT" |
84 } | 86 } |
85 trap cleanup INT TERM EXIT | 87 trap cleanup INT TERM EXIT |
86 mkdir -p "$TEMP_MNT" | 88 mkdir -p "$TEMP_MNT" |
87 sudo mount -o loop "$TEMP_ROOTFS" "$TEMP_MNT" | 89 sudo mount -o loop "$TEMP_ROOTFS" "$TEMP_MNT" |
88 sudo "$TEMP_MNT"/postinst /dev/sda3 | 90 sudo "$TEMP_MNT"/postinst /dev/sda3 |
89 trap - INT TERM EXIT | 91 trap - INT TERM EXIT |
90 cleanup | 92 cleanup |
91 | 93 |
92 # Make 3 GiB output image | 94 # Make 3 GiB output image |
93 TEMP_IMG=$(mktemp) | 95 TEMP_IMG=$(mktemp) |
94 # TOOD(adlr): pick a size that will for sure accomodate the partitions | 96 # TOOD(adlr): pick a size that will for sure accomodate the partitions |
95 sudo dd if=/dev/zero of="${TEMP_IMG}" bs=1 count=1 \ | 97 sudo dd if=/dev/zero of="${TEMP_IMG}" bs=1 count=1 \ |
96 seek=$((3 * 1024 * 1024 * 1024 - 1)) | 98 seek=$((3 * 1024 * 1024 * 1024 - 1)) |
97 | 99 |
98 # Set up the partition table | 100 # Set up the partition table |
99 install_gpt "$TEMP_IMG" "$TEMP_ROOTFS" "$TEMP_KERN" "$TEMP_STATE" \ | 101 install_gpt "$TEMP_IMG" "$TEMP_ROOTFS" "$TEMP_KERN" "$TEMP_STATE" \ |
100 "$TEMP_PMBR" true | 102 "$TEMP_PMBR" "$TEMP_ESP" true |
101 # Copy into the partition parts of the file | 103 # Copy into the partition parts of the file |
102 dd if="$TEMP_ROOTFS" of="$TEMP_IMG" conv=notrunc bs=512 seek="$START_ROOTFS_A" | 104 dd if="$TEMP_ROOTFS" of="$TEMP_IMG" conv=notrunc bs=512 seek="$START_ROOTFS_A" |
103 dd if="$TEMP_STATE" of="$TEMP_IMG" conv=notrunc bs=512 seek="$START_STATEFUL" | 105 dd if="$TEMP_STATE" of="$TEMP_IMG" conv=notrunc bs=512 seek="$START_STATEFUL" |
104 dd if="$TEMP_KERN" of="$TEMP_IMG" conv=notrunc bs=512 seek="$START_KERN_A" | 106 dd if="$TEMP_KERN" of="$TEMP_IMG" conv=notrunc bs=512 seek="$START_KERN_A" |
| 107 dd if="$TEMP_ESP" of="$TEMP_IMG" conv=notrunc bs=512 seek="$START_ESP" |
105 | 108 |
106 echo Creating final image | 109 echo Creating final image |
107 # Convert image to output format | 110 # Convert image to output format |
108 if [ "$FLAGS_format" = "virtualbox" ]; then | 111 if [ "$FLAGS_format" = "virtualbox" ]; then |
109 qemu-img convert -f raw $TEMP_IMG \ | 112 qemu-img convert -f raw $TEMP_IMG \ |
110 -O raw "${VBOX_TEMP_IMAGE}" | 113 -O raw "${VBOX_TEMP_IMAGE}" |
111 VBoxManage convertdd "${VBOX_TEMP_IMAGE}" "${FLAGS_to}/${FLAGS_vbox_disk}" | 114 VBoxManage convertdd "${VBOX_TEMP_IMAGE}" "${FLAGS_to}/${FLAGS_vbox_disk}" |
112 elif [ "$FLAGS_format" = "vmware" ]; then | 115 elif [ "$FLAGS_format" = "vmware" ]; then |
113 qemu-img convert -f raw $TEMP_IMG \ | 116 qemu-img convert -f raw $TEMP_IMG \ |
114 -O vmdk "${FLAGS_to}/${FLAGS_vmdk}" | 117 -O vmdk "${FLAGS_to}/${FLAGS_vmdk}" |
115 else | 118 else |
116 echo invalid format: "$FLAGS_format" | 119 echo invalid format: "$FLAGS_format" |
117 exit 1 | 120 exit 1 |
118 fi | 121 fi |
119 | 122 |
120 rm -rf "$TEMP_DIR" "${VBOX_TEMP_IMAGE}" "$TEMP_IMG" | 123 rm -rf "$TEMP_DIR" "${VBOX_TEMP_IMAGE}" "$TEMP_IMG" |
121 if [ -z "$FLAGS_state_image" ]; then | 124 if [ -z "$FLAGS_state_image" ]; then |
122 rm -f "$STATE_IMAGE" | 125 rm -f "$STATE_IMAGE" |
123 fi | 126 fi |
124 | 127 |
125 echo "Created image ${FLAGS_to}" | 128 echo "Created image ${FLAGS_to}" |
126 | 129 |
127 # Generate the vmware config file | 130 # Generate the vmware config file |
128 # A good reference doc: http://www.sanbarrow.com/vmx.html | 131 # A good reference doc: http://www.sanbarrow.com/vmx.html |
129 VMX_CONFIG="#!/usr/bin/vmware | 132 VMX_CONFIG="#!/usr/bin/vmware |
130 .encoding = \"UTF-8\" | 133 .encoding = \"UTF-8\" |
(...skipping 10 matching lines...) Expand all Loading... |
141 guestOS = \"otherlinux\" | 144 guestOS = \"otherlinux\" |
142 ethernet0.addressType = \"generated\" | 145 ethernet0.addressType = \"generated\" |
143 floppy0.present = \"FALSE\"" | 146 floppy0.present = \"FALSE\"" |
144 | 147 |
145 if [[ ${FLAGS_make_vmx} = ${FLAGS_TRUE} ]]; then | 148 if [[ ${FLAGS_make_vmx} = ${FLAGS_TRUE} ]]; then |
146 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" | 149 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" |
147 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" | 150 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" |
148 echo "${VMX_CONFIG}" | 151 echo "${VMX_CONFIG}" |
149 fi | 152 fi |
150 | 153 |
OLD | NEW |