Author: Philippe Corbes <[email protected]>
Date:   Wed Sep 7 23:38:56 2011 +0200

    Add VirtualBox disk image build script

    Signed-off-by: Philippe Corbes <[email protected]>

diff --git a/platforms/image_hd_vdi.in b/platforms/image_hd_vdi.in
new file mode 100644
index 0000000..7280e13
--- /dev/null
+++ b/platforms/image_hd_vdi.in
@@ -0,0 +1,13 @@
+## SECTION=image
+
+config IMAGE_VDI
+    bool
+    select IMAGE_HD
+    select IMAGE_EXT2
+    select HOST_GENPART
+    prompt "Generate images/hd.vdi"
+    help
+      Build a VirtualBox's disk image file.
+      Check "Generate images/hd.img" to define the hd geometry.
+      This option is available only if VirtualBox is installed on this
machine.
+
diff --git a/rules/post/image_hd_vdi.make b/rules/post/image_hd_vdi.make
new file mode 100644
index 0000000..66227bb
--- /dev/null
+++ b/rules/post/image_hd_vdi.make
@@ -0,0 +1,22 @@
+# -*-makefile-*-
+#
+# Copyright (C) 2011 by the Philippe Corbes <[email protected]>
+#
+# See CREDITS for details about who has contributed to this project.
+#
+# For further information about the PTXdist project and license conditions
+# see the README file.
+#
+
+SEL_ROOTFS-$(PTXCONF_IMAGE_VDI)        += $(IMAGEDIR)/hd.vdi
+
+$(IMAGEDIR)/hd.vdi: $(IMAGEDIR)/hd.img
+    @$(call targetinfo)
+    @echo "Creating hd.vdi from hd.vdi";                        \
+    PATH=$(PTXCONF_SYSROOT_HOST)/bin:$$PATH
$(PTXDIST_TOPDIR)/scripts/genhdvdi    \
+    -i $(IMAGEDIR)/hd.img    \
+    -o $(IMAGEDIR)/hd.vdi
+    @echo "done."
+    @$(call touch, $@)
+
+# vim: syntax=make
diff --git a/scripts/genhdvdi b/scripts/genhdvdi
new file mode 100755
index 0000000..3677f10
--- /dev/null
+++ b/scripts/genhdvdi
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+# Tool to create/update a VirtualBox disk image from an .img file
+#
+# Copyright (C) 2011 by Philippe Corbes <[email protected]>
+#
+
+
+Usage() {
+cat <<-EOF
+
+Usage: `basename "$0"` OPTIONS
+
+    -h               this help
+    -i <input file>  the .img hd image file name
+    -o <output file> the .vdi hd image file name
+EOF
+}
+
+
+while getopts "hi:o:" OPT
+do
+    case "$OPT" in
+        h)  Usage
+        exit 1
+            ;;
+    i)  IMGFILE="$OPTARG"
+        ;;
+    o)  VDIFILE="$OPTARG"
+        ;;
+    esac
+done
+
+if [ -z "$IMGFILE" ]; then
+    echo "no input image file given"
+    exit 1
+fi
+
+if [ -z "$VDIFILE" ]; then
+    echo "no output image file given"
+    exit 1
+fi
+
+VBOXMANAGE=`whereis VBoxManage|sed -e "s/.* //"`
+if [ ! -x `expr ${VBOXMANAGE}` ]; then
+    echo "Virtualbox not installed!"
+    exit 1
+fi
+
+if [ -f "${VDIFILE}" ]; then
+    # Update the existing vdi file
+    UUID=$(${VBOXMANAGE} showhdinfo ${VDIFILE}|grep -e "UUID:"|grep -v
"(UUID"|sed -e "s/.* //")
+    rm -f ${VDIFILE}
+    ${VBOXMANAGE} convertdd ${IMGFILE} ${VDIFILE} 2>&1
+    ${VBOXMANAGE} internalcommands sethduuid ${VDIFILE} ${UUID}
+else
+    # First time then create the vdi file
+    ${VBOXMANAGE} convertdd ${IMGFILE} ${VDIFILE} 2>&1
+fi
+
-- 
ptxdist mailing list
[email protected]

Reply via email to