ユーザ用ツール

サイト用ツール


alacarte:create_esxi_vm_on_command_line

Create ESXi VM on Command Line

# vi /vmfs/volumes/ESXiVol/mkvm.sh
#!/bin/sh

cd /vmfs/volumes/ESXiVol/

VMNAME=$1
VMMEMM=$2
VMSIZE=$3
CPFROM=$4

if [ "${VMNAME}" == "" -o "${VMMEMM}" == ""  -o "${VMSIZE}" == "" ]; then
  echo "illegal parameters." 
  echo "e.g. mkvm.sh NAME MEMMORY DISKSIZE & CopyFrom" 
  exit 1
fi

mkdir /vmfs/volumes/ESXiVol/${VMNAME}

# First make the disk
SEED=/vmfs/volumes/ESXiVol/${CPFROM}/${CPFROM}.vmdk
if [ -f ${SEED} ]; then
  echo "Copy From ${SEED}..."                                                                                     
  vmkfstools -i /vmfs/volumes/ESXiVol/${CPFROM}/${CPFROM}.vmdk -d zeroedthick /vmfs/volumes/ESXiVol/${VMNAME}/${VM
else                                                                                
  echo "create new vm image..."                                                     
  vmkfstools -c ${VMSIZE} -a lsilogic /vmfs/volumes/ESXiVol/${VMNAME}/${VMNAME}.vmdk
fi 

# Now output the vmx file
cat << EOT >> ${VMNAME}/${VMNAME}.vmx
.encoding = "UTF-8" 
config.version = "8" 
virtualHW.version = "8" 
pciBridge0.present = "TRUE" 
pciBridge4.present = "TRUE" 
pciBridge4.virtualDev = "pcieRootPort" 
pciBridge4.functions = "8" 
pciBridge5.present = "TRUE" 
pciBridge5.virtualDev = "pcieRootPort" 
pciBridge5.functions = "8" 
pciBridge6.present = "TRUE" 
pciBridge6.virtualDev = "pcieRootPort" 
pciBridge6.functions = "8" 
pciBridge7.present = "TRUE" 
pciBridge7.virtualDev = "pcieRootPort" 
pciBridge7.functions = "8" 
vmci0.present = "TRUE" 
hpet0.present = "TRUE" 
nvram = "${VMNAME}.nvram" 
virtualHW.productCompatibility = "hosted" 
powerType.powerOff = "soft" 
powerType.powerOn = "hard" 
powerType.suspend = "hard" 
powerType.reset = "soft" 
displayName = "${VMNAME}" 
extendedConfigFile = "${VMNAME}.vmxf" 
memsize = "${VMMEMM}" 
ide1:0.present = "TRUE" 
ide1:0.clientDevice = "TRUE" 
ide1:0.deviceType = "cdrom-raw" 
ide1:0.startConnected = "FALSE" 
ethernet0.present = "TRUE" 
ethernet0.virtualDev = "e1000" 
ethernet0.networkName = "VM Network" 
ethernet0.addressType = "generated" 
guestOS = "centos-64" 
scsi0.present = "TRUE" 
scsi0.sharedBus = "none" 
scsi0.virtualDev = "lsilogic" 
scsi0:0.present = "TRUE" 
scsi0:0.fileName = "${VMNAME}.vmdk" 
scsi0:0.deviceType = "scsi-hardDisk" 
floppy0.present = "FALSE" 
EOT

# Now register our new VM
vnum=`vim-cmd solo/registervm /vmfs/volumes/ESXiVol/${VMNAME}/${VMNAME}.vmx`
vim-cmd vmsvc/power.on $vnum

# MAC
cat /vmfs/volumes/ESXiVol/${VMNAME}/${VMNAME}.vmx | grep generatedAddress

新規作成(vm名称 メモリ HDD)

# /vmfs/volumes/ESXiVol/mkvm.sh taro 1024 15G

コピー作成(vm名称 メモリ HDD(無視される) コピー元)

# /vmfs/volumes/ESXiVol/mkvm.sh hanako 4096 30G CentOS6_Base
alacarte/create_esxi_vm_on_command_line.txt · 最終更新: 2014/02/21 03:02 by clownclown

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki