Forked from nitrocode/clone-free-esxi-vm-without-vcenter.sh
Created
April 21, 2016 12:19
-
-
Save abdul/7970dcbad46f01eb5df6b327e40153c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Usage: | |
# ./clone.sh TESTENV_TO_CLONE_DIR NEW_TEST_ENV_DIR | |
# ./clone.sh TESTENV08-HOST TESTENV03-HOST | |
# The above will clone 08 to 03 and register the vm | |
# | |
# * Do not end the argument directories with a slash! | |
# Date: Mar 10, 2015 | |
DIR_DS=$(pwd) | |
cd $1 | |
# clone vmdk and create vmdk and flat vmdk | |
vmkfstools -i "$1.vmdk" "$2.vmdk" -d thin -a buslogic | |
# create new directory | |
mkdir "../$2" | |
# moves created files to new directory | |
mv "$2-flat.vmdk" "../$2" | |
mv "$2.vmdk" "../$2" | |
# copies original vm's essential files and renames them | |
cp "$1.vmx" "../$2/$2.vmx" | |
cp "$1.vmxf" "../$2/$2.vmxf" | |
cp "$1.vmsd" "../$2/$2.vmsd" | |
cd "../$2" | |
# change all references in vmx from the cloned dir to the new dir | |
sed -i "s/$1/$2/g" "$2.vmx" | |
# Change this pesky variable to the correct one | |
sed -i 's,^\(scsi0:0.fileName = \).*,\1'\"$2.vmdk\"',' "$2.vmx" | |
# register vm | |
vim-cmd "solo/registervm $DIR_DS/$2/$2.vmx" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment