Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: image_to_vmware.sh

Issue 2803015: Final set of VM scripts - integrated with changes from Zelidrag to create a test image if specified. (Closed) Base URL: ssh://gitrw.chromium.org/crosutils.git
Patch Set: Review changes. Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « image_to_vm.sh ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/bin/bash
2
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
5 # found in the LICENSE file.
6
7 # Script to convert the output of build_image.sh to a VMware image and write a
8 # corresponding VMware config file.
9
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.
12 . "$(dirname "$0")/common.sh"
13 . "$(dirname "$0")/chromeos-common.sh"
14
15 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images"
16 # Default to the most recent image
17 DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`"
18 DEFAULT_TO="${DEFAULT_FROM}"
19 DEFAULT_VMDK="ide.vmdk"
20 DEFAULT_VMX="chromeos.vmx"
21 DEFAULT_VBOX_DISK="os.vdi"
22 # Memory units are in MBs
23 DEFAULT_MEM="1024"
24 VBOX_TEMP_IMAGE="${IMAGES_DIR}/vbox_temp.img"
25
26
27 # Flags
28 DEFINE_string from "$DEFAULT_FROM" \
29 "Directory containing rootfs.image and mbr.image"
30 DEFINE_string to "$DEFAULT_TO" \
31 "Destination folder for VM output file(s)"
32 DEFINE_string state_image "" \
33 "Stateful partition image (defaults to creating new statful partition)"
34 DEFINE_string format "vmware" \
35 "Output format, either vmware or virtualbox"
36
37 DEFINE_boolean make_vmx ${FLAGS_TRUE} \
38 "Create a vmx file for use with vmplayer (vmware only)."
39 DEFINE_string vmdk "$DEFAULT_VMDK" \
40 "Filename for the vmware disk image (vmware only)."
41 DEFINE_string vmx "$DEFAULT_VMX" \
42 "Filename for the vmware config (vmware only)."
43 DEFINE_integer mem "$DEFAULT_MEM" \
44 "Memory size for the vm config in MBs (vmware only)."
45
46 DEFINE_string vbox_disk "$DEFAULT_VBOX_DISK" \
47 "Filename for the output disk (virtualbox only)."
48
49 # Parse command line
50 FLAGS "$@" || exit 1
51 eval set -- "${FLAGS_ARGV}"
52
53 # Die on any errors.
54 set -e
55
56 if [ "$FLAGS_format" != "vmware" ]; then
57 FLAGS_make_vmx=${FLAGS_FALSE}
58 fi
59
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.
62 FLAGS_from=`eval readlink -f $FLAGS_from`
63 FLAGS_to=`eval readlink -f $FLAGS_to`
64
65 # Split apart the partitions and make some new ones
66 TEMP_DIR=$(mktemp -d)
67 (cd "$TEMP_DIR" &&
68 "${FLAGS_from}/unpack_partitions.sh" "${FLAGS_from}/chromiumos_image.bin")
69
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
73 TEMP_ROOTFS="$TEMP_DIR"/part_3
74 TEMP_STATE="$TEMP_DIR"/part_1
75 if [ -n "${FLAGS_state_image}" ]; then
76 TEMP_STATE="${FLAGS_state_image}"
77 fi
78 TEMP_KERN="$TEMP_DIR"/part_2
79 TEMP_PMBR="$TEMP_DIR"/pmbr
80 dd if="${FLAGS_from}/chromiumos_image.bin" of="$TEMP_PMBR" bs=512 count=1
81
82 TEMP_MNT=$(mktemp -d)
83 cleanup() {
84 sudo umount -d "$TEMP_MNT"
85 rmdir "$TEMP_MNT"
86 }
87 trap cleanup INT TERM EXIT
88 mkdir -p "$TEMP_MNT"
89 sudo mount -o loop "$TEMP_ROOTFS" "$TEMP_MNT"
90 sudo "$TEMP_MNT"/postinst /dev/sda3
91 trap - INT TERM EXIT
92 cleanup
93
94 # Make 3 GiB output image
95 TEMP_IMG=$(mktemp)
96 # TOOD(adlr): pick a size that will for sure accomodate the partitions
97 sudo dd if=/dev/zero of="${TEMP_IMG}" bs=1 count=1 \
98 seek=$((3 * 1024 * 1024 * 1024 - 1))
99
100 # Set up the partition table
101 install_gpt "$TEMP_IMG" "$TEMP_ROOTFS" "$TEMP_KERN" "$TEMP_STATE" \
102 "$TEMP_PMBR" "$TEMP_ESP" true
103 # Copy into the partition parts of the file
104 dd if="$TEMP_ROOTFS" of="$TEMP_IMG" conv=notrunc bs=512 seek="$START_ROOTFS_A"
105 dd if="$TEMP_STATE" of="$TEMP_IMG" conv=notrunc bs=512 seek="$START_STATEFUL"
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"
108
109 echo Creating final image
110 # Convert image to output format
111 if [ "$FLAGS_format" = "virtualbox" ]; then
112 qemu-img convert -f raw $TEMP_IMG \
113 -O raw "${VBOX_TEMP_IMAGE}"
114 VBoxManage convertdd "${VBOX_TEMP_IMAGE}" "${FLAGS_to}/${FLAGS_vbox_disk}"
115 elif [ "$FLAGS_format" = "vmware" ]; then
116 qemu-img convert -f raw $TEMP_IMG \
117 -O vmdk "${FLAGS_to}/${FLAGS_vmdk}"
118 else
119 echo invalid format: "$FLAGS_format"
120 exit 1
121 fi
122
123 rm -rf "$TEMP_DIR" "${VBOX_TEMP_IMAGE}" "$TEMP_IMG"
124 if [ -z "$FLAGS_state_image" ]; then
125 rm -f "$STATE_IMAGE"
126 fi
127
128 echo "Created image ${FLAGS_to}"
129
130 # Generate the vmware config file
131 # A good reference doc: http://www.sanbarrow.com/vmx.html
132 VMX_CONFIG="#!/usr/bin/vmware
133 .encoding = \"UTF-8\"
134 config.version = \"8\"
135 virtualHW.version = \"4\"
136 memsize = \"${FLAGS_mem}\"
137 ide0:0.present = \"TRUE\"
138 ide0:0.fileName = \"${FLAGS_vmdk}\"
139 ethernet0.present = \"TRUE\"
140 usb.present = \"TRUE\"
141 sound.present = \"TRUE\"
142 sound.virtualDev = \"es1371\"
143 displayName = \"Chromium OS\"
144 guestOS = \"otherlinux\"
145 ethernet0.addressType = \"generated\"
146 floppy0.present = \"FALSE\""
147
148 if [[ ${FLAGS_make_vmx} = ${FLAGS_TRUE} ]]; then
149 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}"
150 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}"
151 echo "${VMX_CONFIG}"
152 fi
153
OLDNEW
« no previous file with comments | « image_to_vm.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698