Revert "create_virtualimage: extend script with:"

This reverts commit 467914e8fde4828f5bee79c13f2fff4fa1e8da00.

needs rework:
 - $4 (system part size?) should be optional
 - /dev/loopXpX don't work on many distros. 'losetup -o' should be used
This commit is contained in:
Stefan Saraev 2013-01-21 23:00:41 +02:00
parent 9d92ab174e
commit 00243d7dde

View File

@ -20,56 +20,46 @@
# http://www.gnu.org/copyleft/gpl.html
################################################################################
# usage: sudo ./create_virtualmachine <path> <size(MB)> [<type>] [system partition size(MB)]
# example: sudo ./create_virtualmachine /home/test/VM 512 [vdi] [128]
# usage: sudo ./create_virtualmachine <path> <size(MB)> [<type>]
# example: sudo ./create_virtualmachine /home/test/VM 512 [vdi]
if [ "$(id -u)" != "0" ]; then
clear
echo "##############################################################"
echo "###########################################################"
echo "# please execute with 'sudo' or -DANGEROUS!!!- as root #"
echo "# example: #"
echo "# sudo ./create_virtualmachine <path> <size(MB)> [<type>] #"
echo "##############################################################"
echo "###########################################################"
exit 1
fi
if [ -z "$1" -o -z "$2" ]; then
clear
echo "##############################################################"
echo "###########################################################"
echo "# please execute as follows #"
echo "# example: #"
echo "# sudo ./create_virtualmachine <path> <size(MB)> [<type>] #"
echo "##############################################################"
exit 1
fi
if [ ! -d "$1" ]; then
clear
echo "##############################################################"
echo "# please create target directory #"
echo "# example: #"
echo "# mkdir <path> #"
echo "##############################################################"
echo "###########################################################"
exit 1
fi
if [ "$2" -lt "200" -o "$2" -gt "2048" ]; then
clear
echo "##############################################################"
echo "#########################################################"
echo "# use a value between 200MB and 2048MB (2GB) #"
echo "# example: #"
echo "# sudo ./create_virtualmachine /home/test/VM 512 #"
echo "##############################################################"
echo "#########################################################"
exit 1
fi
if [ ! -z "$3" -a "$3" != "vdi" -a "$3" != "vmdk" ]; then
clear
echo "##############################################################"
echo "#########################################################"
echo "# only vdi or vmdk types are supported #"
echo "# example: #"
echo "# sudo ./create_virtualmachine /home/test/VM 512 [vdi] #"
echo "##############################################################"
echo "#########################################################"
exit 1
elif [ "$3" = "vdi" ]; then
TYPE="vdi"
@ -77,21 +67,9 @@ elif [ -z "$3" -o "$3" = "vmdk" ]; then
TYPE="vmdk"
fi
if [ "$4" -lt "128" -o "$4" -gt "1024" -o "$4" -gt "$2" ]; then
clear
echo "##############################################################"
echo "# use a value between 128MB and 1024MB #"
echo "# example: #"
echo "# sudo ./create_virtualmachine /home/test/VM 512 [vdi] [256] #"
echo "##############################################################"
exit 1
fi
DISK="$1/OpenELEC.img"
IMAGE="$1/OpenELEC.$TYPE"
LOOP=$(losetup -f)
SYSTEM_PART_SIZE=$(( $4 / 8 ))
clear
echo "#########################################################"
@ -123,22 +101,6 @@ echo "#########################################################"
exit 1
fi
# this is needed to create a bootloader
which extlinux > /dev/null
if [ "$?" = "1" ]; then
clear
echo "#########################################################"
echo "# #"
echo "# OpenELEC.tv missing tool - Installation will quit #"
echo "# #"
echo "# We can't find the required tool \"extlinux\" #"
echo "# on your system. #"
echo "# Please install it via your package manager. #"
echo "# #"
echo "#########################################################"
exit 1
fi
# this is needed by syslinux
which mcopy > /dev/null
if [ "$?" = "1" ]; then
@ -223,7 +185,7 @@ echo "#########################################################"
# create an image
echo "creating new empty harddisk image: $DISK..."
dd if=/dev/zero of="$DISK" bs=1M count="$2"
dd if=/dev/zero of="$DISK" bs=1M count=1024
# write a disklabel
echo "creating new partition table: $DISK..."
@ -232,11 +194,11 @@ echo "#########################################################"
# create partition1
echo "creating partition1 on $DISK..."
parted -s "$LOOP" unit cyl mkpart primary ext2 -- 0 "$SYSTEM_PART_SIZE"
parted -s "$LOOP" unit cyl mkpart primary ext2 -- 0 16
# create partition2
echo "creating partition2 on $DISK..."
parted -s "$LOOP" unit cyl mkpart primary ext2 -- "$(( $SYSTEM_PART_SIZE + 1 ))" -2
parted -s "$LOOP" unit cyl mkpart primary ext2 -- 16 -2
# make partition1 active (bootable)
echo "marking partition1 active..."