mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-31 14:37:59 +00:00
update create_virtualimage script
copied changes from commit 34854f9 and commit 467914e.
This commit is contained in:
parent
335872485a
commit
d59ef0beaa
@ -1,8 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Copyright (C) 2009-2010 OpenELEC.tv
|
# This file is part of OpenELEC - http://www.openelec.tv
|
||||||
# http://www.openelec.tv
|
# Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
|
||||||
#
|
#
|
||||||
# This Program is free software; you can redistribute it and/or modify
|
# This Program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -20,49 +20,94 @@
|
|||||||
# http://www.gnu.org/copyleft/gpl.html
|
# http://www.gnu.org/copyleft/gpl.html
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# usage: sudo ./create_virtualmachine <path>
|
# usage: sudo ./create_virtualmachine <path> <size(MB)> [<type>] [system partition size(MB)]
|
||||||
# example: sudo ./create_virtualmachine /home/test/VM
|
# example: sudo ./create_virtualmachine /home/test/VM 512 [vdi] [128]
|
||||||
|
|
||||||
if [ "$(id -u)" != "0" ]; then
|
if [ "$(id -u)" != "0" ]; then
|
||||||
clear
|
echo "##############################################################"
|
||||||
echo "#########################################################"
|
echo "# please execute with 'sudo' or -DANGEROUS!!!- as root #"
|
||||||
echo "# please execute with 'sudo' or -DANGEROUS!!!- as root #"
|
echo "# example: #"
|
||||||
echo "# example: sudo ./create_virtualmachine <path> #"
|
echo "# sudo ./create_virtualmachine <path> <size(MB)> [<type>] #"
|
||||||
echo "#########################################################"
|
echo "##############################################################"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" -o -z "$2" ]; then
|
||||||
clear
|
echo "##############################################################"
|
||||||
echo "#########################################################"
|
echo "# please execute as follows #"
|
||||||
echo "# please execute with target folder drive as option #"
|
echo "# example: #"
|
||||||
echo "# example: sudo ./create_virtualmachine /home/test/VM/ #"
|
echo "# sudo ./create_virtualmachine <path> <size(MB)> [<type>] #"
|
||||||
echo "#########################################################"
|
echo "##############################################################"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "$1" ]; then
|
||||||
|
echo "##############################################################"
|
||||||
|
echo "# please create target directory #"
|
||||||
|
echo "# example: #"
|
||||||
|
echo "# mkdir <path> #"
|
||||||
|
echo "##############################################################"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$2" -lt "200" -o "$2" -gt "2048" ]; then
|
||||||
|
echo "##############################################################"
|
||||||
|
echo "# use a value between 200MB and 2048MB (2GB) #"
|
||||||
|
echo "# example: #"
|
||||||
|
echo "# sudo ./create_virtualmachine /home/test/VM 512 #"
|
||||||
|
echo "##############################################################"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -z "$3" -a "$3" != "vdi" -a "$3" != "vmdk" ]; then
|
||||||
|
echo "##############################################################"
|
||||||
|
echo "# only vdi or vmdk types are supported #"
|
||||||
|
echo "# example: #"
|
||||||
|
echo "# sudo ./create_virtualmachine /home/test/VM 512 [vdi] #"
|
||||||
|
echo "##############################################################"
|
||||||
|
exit 1
|
||||||
|
elif [ "$3" = "vdi" ]; then
|
||||||
|
TYPE="vdi"
|
||||||
|
elif [ -z "$3" -o "$3" = "vmdk" ]; then
|
||||||
|
TYPE="vmdk"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$4" ]; then
|
||||||
|
SYSTEM_SIZE=192
|
||||||
|
else
|
||||||
|
if [ "$4" -lt "128" -o "$4" -gt "1024" -o "$4" -gt "$2" ]; then
|
||||||
|
echo "##############################################################"
|
||||||
|
echo "# use a value between 128MB and 1024MB #"
|
||||||
|
echo "# example: #"
|
||||||
|
echo "# sudo ./create_virtualmachine /home/test/VM 512 [vdi] [256] #"
|
||||||
|
echo "##############################################################"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
SYSTEM_SIZE=$4
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
DISK="$1/OpenELEC.img"
|
DISK="$1/OpenELEC.img"
|
||||||
VMDK="$1/OpenELEC.vmdk"
|
IMAGE="$1/OpenELEC.$TYPE"
|
||||||
LOOP=$(losetup -f)
|
LOOP=$(losetup -f)
|
||||||
|
DISK_SIZE=$2
|
||||||
|
STORAGE_SIZE=$(( $DISK_SIZE - $SYSTEM_SIZE ))
|
||||||
|
|
||||||
clear
|
echo ""
|
||||||
echo "#########################################################"
|
echo " folder: $1"
|
||||||
echo "# #"
|
echo " loop: $LOOP"
|
||||||
echo "# OpenELEC.tv USB Installer #"
|
echo " disk: $DISK"
|
||||||
echo "# #"
|
echo " image: $IMAGE"
|
||||||
echo "#########################################################"
|
echo " type: $TYPE"
|
||||||
echo "# #"
|
echo " disk size: $DISK_SIZE MB"
|
||||||
echo "# This will wipe any data off your chosen drive #"
|
echo " system size: $SYSTEM_SIZE MB"
|
||||||
echo "# Please read the instructions and use very carefully.. #"
|
echo "storage size: $STORAGE_SIZE MB"
|
||||||
echo "# #"
|
|
||||||
echo "#########################################################"
|
|
||||||
|
|
||||||
# check for some required tools
|
# check for some required tools
|
||||||
|
|
||||||
# this is needed to create a bootloader
|
# this is needed to create a bootloader
|
||||||
which syslinux > /dev/null
|
which syslinux > /dev/null
|
||||||
if [ "$?" = "1" ]; then
|
if [ "$?" = "1" ]; then
|
||||||
clear
|
|
||||||
echo "#########################################################"
|
echo "#########################################################"
|
||||||
echo "# #"
|
echo "# #"
|
||||||
echo "# OpenELEC.tv missing tool - Installation will quit #"
|
echo "# OpenELEC.tv missing tool - Installation will quit #"
|
||||||
@ -75,10 +120,24 @@ echo "#########################################################"
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# this is needed to create a bootloader
|
||||||
|
which extlinux > /dev/null
|
||||||
|
if [ "$?" = "1" ]; then
|
||||||
|
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
|
# this is needed by syslinux
|
||||||
which mcopy > /dev/null
|
which mcopy > /dev/null
|
||||||
if [ "$?" = "1" ]; then
|
if [ "$?" = "1" ]; then
|
||||||
clear
|
|
||||||
echo "#########################################################"
|
echo "#########################################################"
|
||||||
echo "# #"
|
echo "# #"
|
||||||
echo "# OpenELEC.tv missing tool - Installation will quit #"
|
echo "# OpenELEC.tv missing tool - Installation will quit #"
|
||||||
@ -96,7 +155,6 @@ echo "#########################################################"
|
|||||||
# this is needed to partion the drive
|
# this is needed to partion the drive
|
||||||
which parted > /dev/null
|
which parted > /dev/null
|
||||||
if [ "$?" = "1" ]; then
|
if [ "$?" = "1" ]; then
|
||||||
clear
|
|
||||||
echo "#########################################################"
|
echo "#########################################################"
|
||||||
echo "# #"
|
echo "# #"
|
||||||
echo "# OpenELEC.tv missing tool - Installation will quit #"
|
echo "# OpenELEC.tv missing tool - Installation will quit #"
|
||||||
@ -109,10 +167,9 @@ echo "#########################################################"
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# this is needed fo convert harddisk image to vmdk format
|
# this is needed fo convert harddisk image to vmdk or vdi format
|
||||||
which qemu-img > /dev/null
|
which qemu-img > /dev/null
|
||||||
if [ "$?" = "1" ]; then
|
if [ "$?" = "1" ]; then
|
||||||
clear
|
|
||||||
echo "#########################################################"
|
echo "#########################################################"
|
||||||
echo "# #"
|
echo "# #"
|
||||||
echo "# OpenELEC.tv missing tool - Installation will quit #"
|
echo "# OpenELEC.tv missing tool - Installation will quit #"
|
||||||
@ -125,13 +182,12 @@ echo "#########################################################"
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# check MD5 sums
|
# check MD5 sums
|
||||||
|
echo ""
|
||||||
echo "checking MD5 sum..."
|
echo "checking MD5 sum..."
|
||||||
|
|
||||||
md5sumFailed()
|
md5sumFailed()
|
||||||
{
|
{
|
||||||
clear
|
|
||||||
echo "#########################################################"
|
echo "#########################################################"
|
||||||
echo "# #"
|
echo "# #"
|
||||||
echo "# OpenELEC.tv failed md5 check - Installation will quit #"
|
echo "# OpenELEC.tv failed md5 check - Installation will quit #"
|
||||||
@ -153,32 +209,42 @@ echo "#########################################################"
|
|||||||
md5sumFailed
|
md5sumFailed
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ensure loop0 not in use
|
# ensure loopX not in use
|
||||||
|
echo ""
|
||||||
|
echo "next two errors can be ignored..."
|
||||||
umount "$LOOP"
|
umount "$LOOP"
|
||||||
losetup -d "$LOOP"
|
losetup -d "$LOOP"
|
||||||
|
|
||||||
# create an image
|
# create an image
|
||||||
|
echo ""
|
||||||
echo "creating new empty harddisk image: $DISK..."
|
echo "creating new empty harddisk image: $DISK..."
|
||||||
dd if=/dev/zero of="$DISK" bs=1M count=512
|
dd if=/dev/zero of="$DISK" bs=1M count="$DISK_SIZE"
|
||||||
|
|
||||||
# write a disklabel
|
# write a disklabel
|
||||||
|
echo ""
|
||||||
echo "creating new partition table: $DISK..."
|
echo "creating new partition table: $DISK..."
|
||||||
losetup "$LOOP" "$DISK"
|
losetup "$LOOP" "$DISK"
|
||||||
parted -s "$LOOP" mklabel msdos
|
parted -s "$LOOP" mklabel msdos
|
||||||
|
|
||||||
# create partition1
|
# create partition1
|
||||||
|
echo ""
|
||||||
echo "creating partition1 on $DISK..."
|
echo "creating partition1 on $DISK..."
|
||||||
parted -s "$LOOP" -a min unit s mkpart primary ext4 64 262208
|
SYSTEM_PART_END=$(( $SYSTEM_SIZE * 1024 * 1024 / 512 + 64 ))
|
||||||
|
parted -s "$LOOP" -a min unit s mkpart primary ext4 64 $SYSTEM_PART_END
|
||||||
|
|
||||||
# create partition2
|
# create partition2
|
||||||
|
echo ""
|
||||||
echo "creating partition2 on $DISK..."
|
echo "creating partition2 on $DISK..."
|
||||||
parted -s "$LOOP" -a min unit s mkpart primary ext4 262209 100%
|
STORAGE_PART_START=$(( $SYSTEM_PART_END + 1 ))
|
||||||
|
parted -s "$LOOP" -a min unit s mkpart primary ext4 $STORAGE_PART_START 100%
|
||||||
|
|
||||||
# make partition1 active (bootable)
|
# make partition1 active (bootable)
|
||||||
|
echo ""
|
||||||
echo "marking partition1 active..."
|
echo "marking partition1 active..."
|
||||||
parted -s "$LOOP" set 1 boot on
|
parted -s "$LOOP" set 1 boot on
|
||||||
|
|
||||||
# write mbr
|
# write mbr
|
||||||
|
echo ""
|
||||||
echo "writing mbr..."
|
echo "writing mbr..."
|
||||||
if [ -f /usr/lib/syslinux/mbr.bin ]; then
|
if [ -f /usr/lib/syslinux/mbr.bin ]; then
|
||||||
MBR="/usr/lib/syslinux/mbr.bin" # example: debian, ubuntu
|
MBR="/usr/lib/syslinux/mbr.bin" # example: debian, ubuntu
|
||||||
@ -186,71 +252,101 @@ echo "#########################################################"
|
|||||||
MBR="/usr/share/syslinux/mbr.bin" # example: fedora
|
MBR="/usr/share/syslinux/mbr.bin" # example: fedora
|
||||||
else
|
else
|
||||||
echo "Can't find syslinux's mbr.bin on Host OS"
|
echo "Can't find syslinux's mbr.bin on Host OS"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$MBR" ]; then
|
if [ -n "$MBR" ]; then
|
||||||
cat "$MBR" > "$LOOP"
|
cat "$MBR" > "$LOOP"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# sync disk
|
||||||
|
echo ""
|
||||||
|
echo "syncing disk..."
|
||||||
|
sync
|
||||||
|
|
||||||
# create filesystem on partition1
|
# create filesystem on partition1
|
||||||
echo "creating filesystem on partition1..."
|
echo ""
|
||||||
losetup -d "$LOOP"
|
losetup -d "$LOOP"
|
||||||
losetup -o 32768 --sizelimit 134218240 "$LOOP" "$DISK"
|
echo "creating filesystem on partition1..."
|
||||||
mke2fs -t ext4 -m 0 "$LOOP"
|
OFFSET=$(( 64 * 512 ))
|
||||||
|
SIZELIMIT=$(( $SYSTEM_SIZE * 1024 * 1024 ))
|
||||||
|
losetup -o $OFFSET --sizelimit $SIZELIMIT "$LOOP" "$DISK"
|
||||||
|
mke2fs -q -t ext4 -m 0 "$LOOP"
|
||||||
tune2fs -U random -L "System" "$LOOP"
|
tune2fs -U random -L "System" "$LOOP"
|
||||||
sync
|
sync
|
||||||
|
|
||||||
# mount partition
|
# mount partition
|
||||||
|
echo ""
|
||||||
echo "mounting partition1 on /tmp/vmware_install..."
|
echo "mounting partition1 on /tmp/vmware_install..."
|
||||||
mkdir -p /tmp/vmware_install
|
mkdir -p /tmp/vmware_install
|
||||||
mount "$LOOP" /tmp/vmware_install
|
mount "$LOOP" /tmp/vmware_install
|
||||||
|
|
||||||
# create bootloader configuration
|
# create bootloader configuration
|
||||||
|
echo ""
|
||||||
echo "creating bootloader configuration..."
|
echo "creating bootloader configuration..."
|
||||||
|
|
||||||
echo "DEFAULT linux" > /tmp/vmware_install/syslinux.cfg
|
cat >/tmp/vmware_install/syslinux.cfg << EOF
|
||||||
echo "PROMPT 0" >> /tmp/vmware_install/syslinux.cfg
|
DEFAULT linux
|
||||||
echo " " >> /tmp/vmware_install/syslinux.cfg
|
PROMPT 0
|
||||||
echo "LABEL linux" >> /tmp/vmware_install/syslinux.cfg
|
|
||||||
echo " KERNEL /KERNEL" >> /tmp/vmware_install/syslinux.cfg
|
LABEL linux
|
||||||
echo " APPEND boot=LABEL=System disk=LABEL=Storage quiet ssh" >> /tmp/vmware_install/syslinux.cfg
|
KERNEL /KERNEL
|
||||||
|
APPEND boot=LABEL=System disk=LABEL=Storage quiet ssh
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
# install extlinux
|
# install extlinux
|
||||||
|
echo ""
|
||||||
echo "installing extlinux to partition1..."
|
echo "installing extlinux to partition1..."
|
||||||
extlinux --heads=4 --sector=32 -i /tmp/vmware_install
|
extlinux --heads=4 --sector=32 -i /tmp/vmware_install
|
||||||
|
|
||||||
# copy files
|
# copy files
|
||||||
|
echo ""
|
||||||
echo "copying files to partition1..."
|
echo "copying files to partition1..."
|
||||||
cp target/KERNEL /tmp/vmware_install
|
cp target/KERNEL /tmp/vmware_install
|
||||||
cp target/SYSTEM /tmp/vmware_install
|
cp target/SYSTEM /tmp/vmware_install
|
||||||
|
|
||||||
# sync disk
|
# sync disk
|
||||||
|
echo ""
|
||||||
echo "syncing disk..."
|
echo "syncing disk..."
|
||||||
sync
|
sync
|
||||||
|
|
||||||
# unmount partition1
|
# unmount partition1
|
||||||
|
echo ""
|
||||||
echo "unmounting partition1..."
|
echo "unmounting partition1..."
|
||||||
umount "$LOOP"
|
umount "$LOOP"
|
||||||
sync
|
sync
|
||||||
|
|
||||||
# create filesystem on partition2
|
# create filesystem on partition2
|
||||||
echo "creating filesystem on partition2..."
|
echo ""
|
||||||
losetup -d "$LOOP"
|
losetup -d "$LOOP"
|
||||||
losetup -o 134251008 "$LOOP" "$DISK"
|
echo "creating filesystem on partition2..."
|
||||||
mke2fs -t ext4 -m 0 "$LOOP"
|
OFFSET=$(( $STORAGE_PART_START * 512 ))
|
||||||
|
losetup -o $OFFSET "$LOOP" "$DISK"
|
||||||
|
mke2fs -q -t ext4 -m 0 "$LOOP"
|
||||||
tune2fs -U random -L "Storage" "$LOOP"
|
tune2fs -U random -L "Storage" "$LOOP"
|
||||||
sync
|
sync
|
||||||
|
|
||||||
# detach loop0
|
# detach loopX
|
||||||
losetup -d "$LOOP"
|
losetup -d "$LOOP"
|
||||||
|
|
||||||
# cleaning
|
# cleaning
|
||||||
|
echo ""
|
||||||
echo "cleaning tempdir..."
|
echo "cleaning tempdir..."
|
||||||
|
[ -f /tmp/vmware_install/ldlinux.sys ] && chattr -i /tmp/vmware_install/ldlinux.sys
|
||||||
rm -rf /tmp/vmware_install
|
rm -rf /tmp/vmware_install
|
||||||
|
|
||||||
# convert image to vmdk
|
# convert image to vmdk or vdi
|
||||||
echo "converting $DISK to vmdk format..."
|
echo ""
|
||||||
qemu-img convert -O vmdk "$DISK" "$VMDK"
|
echo "converting $DISK to $TYPE format..."
|
||||||
|
qemu-img convert -O $TYPE "$DISK" "$IMAGE"
|
||||||
rm -f "$DISK"
|
rm -f "$DISK"
|
||||||
|
|
||||||
echo "...installation finished"
|
# sync disk
|
||||||
|
echo ""
|
||||||
|
echo "syncing disk..."
|
||||||
|
sync
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "installation finished..."
|
||||||
|
echo ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user