#!/bin/sh # # $Id: maxVdisks.tcl,v 1.1 2008/01/19 03:15:18 robroy Exp $ # # maxVdisks.tcl edits a VM's vmx file to reference the maximum # supported number of vdisks (60), then creates the disks. # # maxVdisks.tcl should be executed from within the directory where # the VM is stored. # # Copyright Robroy Gregg, Computer Consultant 2010. All rights reserved. # # Restart with tclsh \ exec tclsh $0 $@ set scriptName [file tail [info script]] #---------------------------------------------------------------------- # Continue only if there's a single VMX file in this directory. #---------------------------------------------------------------------- set vmxFile [glob -nocomplain *vmx] if {[llength $vmxFile] == 0} { puts stderr "${scriptName}: I found no VMX file to edit. \ Run this script from" puts stderr "${scriptName}: within the directory where your\ VM is stored." exit 1 } if {[llength $vmxFile] > 1} { puts stderr "${scriptName}: There are multiple VMX files in this\ directory, which makes" puts stderr "${scriptName}: my job ambiguous. Please move/rename\ all but the one you'd" puts stderr "${scriptName}: like me to edit." exit 1 } #---------------------------------------------------------------------- # Use eval(n) to remove an extraneous level of nesting (brackets) # tacked on by glob(n). #---------------------------------------------------------------------- eval set vmxFile $vmxFile #---------------------------------------------------------------------- # Create a backup of the VMX if none exists, then open the VMX. #---------------------------------------------------------------------- set vmxFileBackup [glob -nocomplain ${vmxFile}.maxVdisks.backup] if {[llength $vmxFileBackup] == 0} { file copy $vmxFile ${vmxFile}.maxVdisks.backup } if {[catch {open $vmxFile a+} fd]} { puts stderr "${scriptName}: Failed to open VMX file\ ${vmxFile}: $fd" exit 1 } #---------------------------------------------------------------------- # The specified HBA type may be either b (buslogic), l (lsilogic), # or left blank (lsilogic). #---------------------------------------------------------------------- set response null while {![regexp "^\[bl]$|(^\[ \t]*$)" $response]} { puts -nonewline {Enter b for buslogic or l for lsilogic [l]: } flush stdout gets stdin response } if {[string match $response b]} { set hbaType buslogic } else { set hbaType lsilogic } #---------------------------------------------------------------------- # The specified vdisk size may be either a number beginning with a # non-zero digit or left blank. If it's left blank, default to # fifty megabytes. #---------------------------------------------------------------------- set size null while {![regexp "(^\[1-9]+\[0-9]*$)|(^\[ \t]*$)" $size]} { puts -nonewline {Enter the size of each vdisk in megabytes [50]: } flush stdout gets stdin size } if {[regexp "^\[ \t]*$" $size]} { set size 50 } #---------------------------------------------------------------------- # Provide a disk space usage estimate and a ten second opportunity # to bail out. #---------------------------------------------------------------------- puts {} puts "====> Using $hbaType HBAs with $size megabyte disks." puts "====> This will consume [expr $size * 59] megabytes." puts {} puts {**********} puts {**********} puts {********** Hit ^C to cancel if this isn't what you want!} puts {**********} puts {**********} puts {} puts -nonewline "VM modification will begin in ten seconds: " flush stdout exec sleep 1 puts -nonewline 1; flush stdout for {set i 2} {$i <= 10} {incr i} \ {exec sleep 1; puts -nonewline ", $i"; flush stdout} puts .\n #---------------------------------------------------------------------- # Add fourteen additional targets to the first HBA (assuming that # the VM started out with a single target). #---------------------------------------------------------------------- puts -nonewline "==> Adding fourteen targets to bus zero: " flush stdout for {set target 1} {$target != 16} {incr target} { if {$target == 7} continue ;# Reserved for HBA. puts $fd "scsi0:${target}.present = \"true\"" puts $fd "scsi0:${target}.fileName = \"bus0target${target}.vmdk\"" puts $fd "scsi0:${target}.deviceType = \"scsi-hardDisk\"" if {[catch {exec vmkfstools -c ${size}M -d thick -a $hbaType \ bus0target${target}.vmdk} vmkfstoolsError]} { puts stderr "\n${scriptName}: Fatal error while running\ vmkfstools thusly:" puts stderr "${scriptName}: vmkfstools -c ${size}M -d thick\ -a $hbaType bus0target${target}.vmdk" puts stderr $vmkfstoolsError exit 1 } puts -nonewline "$target "; flush stdout } #---------------------------------------------------------------------- # Add three more HBAs with fifteen targets each. #---------------------------------------------------------------------- for {set bus 1} {$bus != 4} {incr bus} { puts -nonewline "\n==> Adding bus $bus with fifteen targets: " flush stdout puts $fd "scsi${bus}.present = \"true\"" puts $fd "scsi${bus}.sharedBus = \"none\"" if {[string match $hbaType lsilogic]} { puts $fd "scsi${bus}.virtualDev = \"lsilogic\"" } for {set target 0} {$target != 16} {incr target} { if {$target == 7} continue ;# Reserved for HBA. puts $fd "scsi${bus}:${target}.present = \"true\"" puts $fd "scsi${bus}:${target}.fileName =\ \"bus${bus}target${target}.vmdk\"" puts $fd "scsi${bus}:${target}.deviceType = \"scsi-hardDisk\"" if {[catch {exec vmkfstools -c ${size}M -d thick -a ${hbaType} \ bus${bus}target${target}.vmdk} vmkfstoolsError]} { puts stderr "\n${scriptName}: Fatal error running while\ vmkfstools thusly:" puts stderr "${scriptName}: vmkfstools -c ${size}M -d thick\ -a $hbaType bus0target${target}.vmdk" puts stderr $vmkfstoolsError exit 1 } puts -nonewline "$target "; flush stdout } } catch {close $fd} ;# Close the VMX file. puts {} puts {} puts {Done!} puts {To restore the original VMX file and remove the extra vdisks, run:} puts " mv -f ${vmxFile}.maxVdisks.backup ${vmxFile}" puts { rm -f bus?target*.vmdk} puts {} exit