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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/scripts/image_to_virtualbox.sh ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scripts/image_to_vmware.sh
diff --git a/src/scripts/image_to_vmware.sh b/src/scripts/image_to_vmware.sh
index dd184ec28a9cf2d3a841fa91afa89e1e746c1464..cc754029a15443cc2242514a2049bee7c6909233 100755
--- a/src/scripts/image_to_vmware.sh
+++ b/src/scripts/image_to_vmware.sh
@@ -17,22 +17,31 @@ DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`"
DEFAULT_TO="${DEFAULT_FROM}"
DEFAULT_VMDK="ide.vmdk"
DEFAULT_VMX="chromeos.vmx"
+DEFAULT_VBOX_DISK="os.vdi"
# Memory units are in MBs
DEFAULT_MEM="1024"
+VBOX_TEMP_IMAGE="${IMAGES_DIR}/vbox_temp.img"
+
# Flags
DEFINE_string from "$DEFAULT_FROM" \
"Directory containing rootfs.image and mbr.image"
DEFINE_string to "$DEFAULT_TO" \
- "Destination folder for VMware files"
-DEFINE_boolean make_vmx true \
- "Create a vmx file for use with vmplayer."
+ "Destination folder for VM output file(s)"
+DEFINE_string format "vmware" \
+ "Output format, either vmware or virtualbox"
+
+DEFINE_boolean make_vmx ${FLAGS_TRUE} \
+ "Create a vmx file for use with vmplayer (vmware only)."
DEFINE_string vmdk "$DEFAULT_VMDK" \
- "Filename for the vmware disk image"
+ "Filename for the vmware disk image (vmware only)."
DEFINE_string vmx "$DEFAULT_VMX" \
- "Filename for the vmware config"
+ "Filename for the vmware config (vmware only)."
DEFINE_integer mem "$DEFAULT_MEM" \
- "Memory size for the vmware config in MBs."
+ "Memory size for the vm config in MBs (vmware only)."
+
+DEFINE_string vbox_disk "$DEFAULT_VBOX_DISK" \
+ "Filename for the output disk (virtualbox only)."
# Parse command line
FLAGS "$@" || exit 1
@@ -41,6 +50,10 @@ eval set -- "${FLAGS_ARGV}"
# Die on any errors.
set -e
+if [ "$FLAGS_format" != "vmware" ]; then
+ FLAGS_make_vmx=${FLAGS_FALSE}
+fi
+
# Convert args to paths. Need eval to un-quote the string so that shell
# chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work.
FLAGS_from=`eval readlink -f $FLAGS_from`
@@ -55,37 +68,58 @@ dd if=/dev/zero of="${FLAGS_from}/state.image" bs=1 count=1 \
seek=$(( $PART_SIZE - 1 ))
mkfs.ext3 -F -L C-STATE "${FLAGS_from}/state.image"
-# Copy MBR and rootfs to output image
-qemu-img convert -f raw \
- "${FLAGS_from}/mbr.image" "${FLAGS_from}/state.image" \
- "${FLAGS_from}/empty.image" "${FLAGS_from}/rootfs.image" \
- -O vmdk "${FLAGS_to}/${FLAGS_vmdk}"
+# Fix bootloader config.
+TEMP_IMG=$(mktemp)
+TEMP_MNT=$(mktemp -d)
+cp "${FLAGS_from}/rootfs.image" "$TEMP_IMG"
+mkdir -p "$TEMP_MNT"
+sudo mount -o loop "$TEMP_IMG" "$TEMP_MNT"
+sudo "$TEMP_MNT"/postinst /dev/sda3
+sudo umount "$TEMP_MNT"
+rmdir "$TEMP_MNT"
-rm -f "${FLAGS_from}/empty.image" "${FLAGS_from}/state.image"
+if [ "$FLAGS_format" = "virtualbox" ]; then
+ # Copy MBR and rootfs to output image
+ qemu-img convert -f raw \
+ "${FLAGS_from}/mbr.image" "${FLAGS_from}/state.image" \
+ "${FLAGS_from}/empty.image" "$TEMP_IMG" \
+ -O raw "${VBOX_TEMP_IMAGE}"
+ VBoxManage convertdd "${VBOX_TEMP_IMAGE}" "${FLAGS_to}/${FLAGS_vbox_disk}"
+elif [ "$FLAGS_format" = "vmware" ]; then
+ # Copy MBR and rootfs to output image
+ qemu-img convert -f raw \
+ "${FLAGS_from}/mbr.image" "${FLAGS_from}/state.image" \
+ "${FLAGS_from}/empty.image" "$TEMP_IMG" \
+ -O vmdk "${FLAGS_to}/${FLAGS_vmdk}"
+else
+ echo invalid format: "$FLAGS_format"
+ exit 1
+fi
+
+rm -f "${FLAGS_from}/empty.image" "${FLAGS_from}/state.image" \
+ "$TEMP_IMG" "${VBOX_TEMP_IMAGE}"
-echo "Created VMware image ${FLAGS_to}"
+echo "Created image ${FLAGS_to}"
# Generate the vmware config file
# A good reference doc: http://www.sanbarrow.com/vmx.html
-VMX_CONFIG=$(cat <<END
-#!/usr/bin/vmware
-.encoding = "UTF-8"
-config.version = "8"
-virtualHW.version = "4"
-memsize = "${FLAGS_mem}"
-ide0:0.present = "TRUE"
-ide0:0.fileName = "${FLAGS_vmdk}"
-ethernet0.present = "TRUE"
-usb.present = "TRUE"
-sound.present = "TRUE"
-sound.virtualDev = "es1371"
-displayName = "ChromeOS"
-guestOS = "otherlinux"
-ethernet0.addressType = "generated"
-floppy0.present = "FALSE"
-END)
-
-if [[ ${FLAGS_make_vmx} ]]; then
+VMX_CONFIG="#!/usr/bin/vmware
+.encoding = \"UTF-8\"
+config.version = \"8\"
+virtualHW.version = \"4\"
+memsize = \"${FLAGS_mem}\"
+ide0:0.present = \"TRUE\"
+ide0:0.fileName = \"${FLAGS_vmdk}\"
+ethernet0.present = \"TRUE\"
+usb.present = \"TRUE\"
+sound.present = \"TRUE\"
+sound.virtualDev = \"es1371\"
+displayName = \"Chromium OS\"
+guestOS = \"otherlinux\"
+ethernet0.addressType = \"generated\"
+floppy0.present = \"FALSE\""
+
+if [[ ${FLAGS_make_vmx} = ${FLAGS_TRUE} ]]; then
echo "${VMX_CONFIG}" > "${FLAGS_to}/${FLAGS_vmx}"
echo "Wrote the following config to: ${FLAGS_to}/${FLAGS_vmx}"
echo "${VMX_CONFIG}"
« 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