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

Side by Side Diff: src/scripts/image_to_vmware.sh

Issue 668215: VMWare [1/2]: Fix vmware image generation. (Closed)
Patch Set: fixes for review Created 10 years, 9 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 | « src/scripts/image_to_virtualbox.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
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.
11 # The path to common.sh should be relative to your script's location. 11 # The path to common.sh should be relative to your script's location.
12 . "$(dirname "$0")/common.sh" 12 . "$(dirname "$0")/common.sh"
13 13
14 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" 14 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images"
15 # Default to the most recent image 15 # Default to the most recent image
16 DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`" 16 DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`"
17 DEFAULT_TO="${DEFAULT_FROM}" 17 DEFAULT_TO="${DEFAULT_FROM}"
18 DEFAULT_VMDK="ide.vmdk" 18 DEFAULT_VMDK="ide.vmdk"
19 DEFAULT_VMX="chromeos.vmx" 19 DEFAULT_VMX="chromeos.vmx"
20 DEFAULT_VBOX_DISK="os.vdi"
20 # Memory units are in MBs 21 # Memory units are in MBs
21 DEFAULT_MEM="1024" 22 DEFAULT_MEM="1024"
23 VBOX_TEMP_IMAGE="${IMAGES_DIR}/vbox_temp.img"
24
22 25
23 # Flags 26 # Flags
24 DEFINE_string from "$DEFAULT_FROM" \ 27 DEFINE_string from "$DEFAULT_FROM" \
25 "Directory containing rootfs.image and mbr.image" 28 "Directory containing rootfs.image and mbr.image"
26 DEFINE_string to "$DEFAULT_TO" \ 29 DEFINE_string to "$DEFAULT_TO" \
27 "Destination folder for VMware files" 30 "Destination folder for VM output file(s)"
28 DEFINE_boolean make_vmx true \ 31 DEFINE_string format "vmware" \
29 "Create a vmx file for use with vmplayer." 32 "Output format, either vmware or virtualbox"
33
34 DEFINE_boolean make_vmx ${FLAGS_TRUE} \
35 "Create a vmx file for use with vmplayer (vmware only)."
30 DEFINE_string vmdk "$DEFAULT_VMDK" \ 36 DEFINE_string vmdk "$DEFAULT_VMDK" \
31 "Filename for the vmware disk image" 37 "Filename for the vmware disk image (vmware only)."
32 DEFINE_string vmx "$DEFAULT_VMX" \ 38 DEFINE_string vmx "$DEFAULT_VMX" \
33 "Filename for the vmware config" 39 "Filename for the vmware config (vmware only)."
34 DEFINE_integer mem "$DEFAULT_MEM" \ 40 DEFINE_integer mem "$DEFAULT_MEM" \
35 "Memory size for the vmware config in MBs." 41 "Memory size for the vm config in MBs (vmware only)."
42
43 DEFINE_string vbox_disk "$DEFAULT_VBOX_DISK" \
44 "Filename for the output disk (virtualbox only)."
36 45
37 # Parse command line 46 # Parse command line
38 FLAGS "$@" || exit 1 47 FLAGS "$@" || exit 1
39 eval set -- "${FLAGS_ARGV}" 48 eval set -- "${FLAGS_ARGV}"
40 49
41 # Die on any errors. 50 # Die on any errors.
42 set -e 51 set -e
43 52
53 if [ "$FLAGS_format" != "vmware" ]; then
54 FLAGS_make_vmx=${FLAGS_FALSE}
55 fi
56
44 # Convert args to paths. Need eval to un-quote the string so that shell 57 # Convert args to paths. Need eval to un-quote the string so that shell
45 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. 58 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work.
46 FLAGS_from=`eval readlink -f $FLAGS_from` 59 FLAGS_from=`eval readlink -f $FLAGS_from`
47 FLAGS_to=`eval readlink -f $FLAGS_to` 60 FLAGS_to=`eval readlink -f $FLAGS_to`
48 61
49 # Make two sparse files. One for an empty partition, another for 62 # Make two sparse files. One for an empty partition, another for
50 # stateful partition. 63 # stateful partition.
51 PART_SIZE=$(stat -c%s "${FLAGS_from}/rootfs.image") 64 PART_SIZE=$(stat -c%s "${FLAGS_from}/rootfs.image")
52 dd if=/dev/zero of="${FLAGS_from}/empty.image" bs=1 count=1 \ 65 dd if=/dev/zero of="${FLAGS_from}/empty.image" bs=1 count=1 \
53 seek=$(( $PART_SIZE - 1 )) 66 seek=$(( $PART_SIZE - 1 ))
54 dd if=/dev/zero of="${FLAGS_from}/state.image" bs=1 count=1 \ 67 dd if=/dev/zero of="${FLAGS_from}/state.image" bs=1 count=1 \
55 seek=$(( $PART_SIZE - 1 )) 68 seek=$(( $PART_SIZE - 1 ))
56 mkfs.ext3 -F -L C-STATE "${FLAGS_from}/state.image" 69 mkfs.ext3 -F -L C-STATE "${FLAGS_from}/state.image"
57 70
58 # Copy MBR and rootfs to output image 71 # Fix bootloader config.
59 qemu-img convert -f raw \ 72 TEMP_IMG=$(mktemp)
60 "${FLAGS_from}/mbr.image" "${FLAGS_from}/state.image" \ 73 TEMP_MNT=$(mktemp -d)
61 "${FLAGS_from}/empty.image" "${FLAGS_from}/rootfs.image" \ 74 cp "${FLAGS_from}/rootfs.image" "$TEMP_IMG"
62 -O vmdk "${FLAGS_to}/${FLAGS_vmdk}" 75 mkdir -p "$TEMP_MNT"
76 sudo mount -o loop "$TEMP_IMG" "$TEMP_MNT"
77 sudo "$TEMP_MNT"/postinst /dev/sda3
78 sudo umount "$TEMP_MNT"
79 rmdir "$TEMP_MNT"
63 80
64 rm -f "${FLAGS_from}/empty.image" "${FLAGS_from}/state.image" 81 if [ "$FLAGS_format" = "virtualbox" ]; then
82 # Copy MBR and rootfs to output image
83 qemu-img convert -f raw \
84 "${FLAGS_from}/mbr.image" "${FLAGS_from}/state.image" \
85 "${FLAGS_from}/empty.image" "$TEMP_IMG" \
86 -O raw "${VBOX_TEMP_IMAGE}"
87 VBoxManage convertdd "${VBOX_TEMP_IMAGE}" "${FLAGS_to}/${FLAGS_vbox_disk}"
88 elif [ "$FLAGS_format" = "vmware" ]; then
89 # Copy MBR and rootfs to output image
90 qemu-img convert -f raw \
91 "${FLAGS_from}/mbr.image" "${FLAGS_from}/state.image" \
92 "${FLAGS_from}/empty.image" "$TEMP_IMG" \
93 -O vmdk "${FLAGS_to}/${FLAGS_vmdk}"
94 else
95 echo invalid format: "$FLAGS_format"
96 exit 1
97 fi
65 98
66 echo "Created VMware image ${FLAGS_to}" 99 rm -f "${FLAGS_from}/empty.image" "${FLAGS_from}/state.image" \
100 "$TEMP_IMG" "${VBOX_TEMP_IMAGE}"
101
102 echo "Created image ${FLAGS_to}"
67 103
68 # Generate the vmware config file 104 # Generate the vmware config file
69 # A good reference doc: http://www.sanbarrow.com/vmx.html 105 # A good reference doc: http://www.sanbarrow.com/vmx.html
70 VMX_CONFIG=$(cat <<END 106 VMX_CONFIG="#!/usr/bin/vmware
71 #!/usr/bin/vmware 107 .encoding = \"UTF-8\"
72 .encoding = "UTF-8" 108 config.version = \"8\"
73 config.version = "8" 109 virtualHW.version = \"4\"
74 virtualHW.version = "4" 110 memsize = \"${FLAGS_mem}\"
75 memsize = "${FLAGS_mem}" 111 ide0:0.present = \"TRUE\"
76 ide0:0.present = "TRUE" 112 ide0:0.fileName = \"${FLAGS_vmdk}\"
77 ide0:0.fileName = "${FLAGS_vmdk}" 113 ethernet0.present = \"TRUE\"
78 ethernet0.present = "TRUE" 114 usb.present = \"TRUE\"
79 usb.present = "TRUE" 115 sound.present = \"TRUE\"
80 sound.present = "TRUE" 116 sound.virtualDev = \"es1371\"
81 sound.virtualDev = "es1371" 117 displayName = \"Chromium OS\"
82 displayName = "ChromeOS" 118 guestOS = \"otherlinux\"
83 guestOS = "otherlinux" 119 ethernet0.addressType = \"generated\"
84 ethernet0.addressType = "generated" 120 floppy0.present = \"FALSE\""
85 floppy0.present = "FALSE"
86 END)
87 121
88 if [[ ${FLAGS_make_vmx} ]]; then 122 if [[ ${FLAGS_make_vmx} = ${FLAGS_TRUE} ]]; then
89 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}" 123 echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}"
90 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}" 124 echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}"
91 echo "${VMX_CONFIG}" 125 echo "${VMX_CONFIG}"
92 fi 126 fi
93 127
OLDNEW
« no previous file with comments | « src/scripts/image_to_virtualbox.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698