vm ESX image copy

as ESX v3 don’t support copy of vmware machines by web interface (no VC) i have written a script for migrating a vmdk disk from existing Machine to a new one.

#!/bin/sh

SRC=$1
TRG=$2
/usr/bin/clear

if [ $# -ne 2 ]
then
echo "COPY Virtual Machine Utility"
echo "USAGE : cp_IMAGE SourceDIR DestinationDIR"
echo "-----------------------------------------"
exit
fi

echo "COPY Virtual Machine Utility"
echo "-----------------------------------------"
sleep 1

echo "Source Directory : " = $SRC
echo "Target Directory : " = $TRG
echo "-----------------------------------------"
sleep 1
if [ -e $SRC/$SRC.vmdk ]
then
echo "Source Virtual Machine exists !"
sleep 1
else
echo "Source Virtual Machine - not Exists !"
echo "fix source Virtual Machine name"
exit
fi
sleep 1
if [ -e $TRG/$TRG.vmdk ]
then
echo "Target Virtual Machine exists !"
sleep 1
else
   echo "Target Virtual Machine - not Exists !"
   echo "Create Destination Virtual Machine"
   exit
fi
if [ $SRC = $TRG ]
then
   echo "Cannot copy VM to itself !"
   echo "bye"
   exit
fi
echo "Going to remove {" $TRG "} Disks"
echo "Are you Sure ? (yes/no)"
read ANswer
case "$ANswer" in
        "yes" ) /bin/rm $TRG/*.vmdk;
                echo "Target Disk Removed";
                sleep 2;
        ;;
        "no" ) echo "bye";
               exit;
        ;;
        * ) echo "not a valid option";
            echo "bye";
            exit;
esac


/usr/sbin/vmkfstools -i $SRC/$SRC.vmdk $TRG/$TRG.vmdk
echo "-----------------------------------------"
echo "Done."

Busybox notes

Some notes from my busybox implementation:

  • for fortran support –enable-languages=f77 in gcc.
  • after compilation make the soft link : ln -s /path-to-g77 /bin/g77
  • inittab :: wait:-/bin/sh for automated login
  • no Correct Hostname value in this file, so manualy do /bin/hostname ‘the_name’
  • no Snapshot use in buildroot compilation – uclibc,busybox.
  • bash :: echo -e ‘\E[num1;num2m{text}’ – for:back :: 31 red – 32 green – 36 cyan – 37 white – 40 black
  • changes in packages settings for buildroot are done in package/…
  • busybox :: enable_renice

KERNEL :

  • Firestarter :: USB::Usb Mass storage ;
  • SCSI::Scsi Disk support,num of disks 40 ;
  • File Systems::dos fat fs,ms dos fs,vfat,romfs ;
  • Partition types::Advanced Partition, PC Bios ;
  • Block Devices::RAM Disk Support,initrd

ENV :

  • alias ls=’ls -l –color’