So far in this series of articles I’ve covered the following items.
Part 1 – initial setup and creating a VM
Part 2 – add a license key, enable VM automatic startup and shutdown and unregister a VM
Part 3 – create a virtual switch and configure a firewall VM
Part 4 – install an update for ESXi
Part 5 – Creating a datastore and migrating VMs
Part 6 – Adding a virtual disk to a VM and reseting your licence configuration
In this part I first cover deleting a virtual disk from a VM. Then below I discuss how to set various VM settings.
Deleting a virtual disk
To accomplish this I’ll use the getdevices and device.diskremove options of vim-cmd vmsvc/. The first step I took was to remove the partitions in the guest OS. After that, I used vim-cmd vmsvc/getdevices to determine the bus ID for the controller and the IDs for the disks to remove. The output of that is shown below. To remove a disk from a VM it is necessary to identify the bus number for the virtual SCSI adapter as well as the device numbers for each virtual disk to delete. The device section show 3 virtual disks (2000, 2001 and 2002) that correspond to the unit numbers in the section for each virtual disk.
(vim.vm.device.VirtualBusLogicController) {
dynamicType = <unset>,
key = 1000,
deviceInfo = (vim.Description) {
dynamicType = <unset>,
label = "SCSI controller 0",
summary = "BusLogic",
},
backing = (vim.vm.device.VirtualDevice.BackingInfo) null,
connectable = (vim.vm.device.VirtualDevice.ConnectInfo) null,
controllerKey = 100,
unitNumber = 3,
busNumber = 0,
device = (int) [
2000,
2001,
2002
],
hotAddRemove = true,
sharedBus = "noSharing",
scsiCtlrUnitNumber = 7,
}, (vim.vm.device.VirtualDisk) {
dynamicType = <unset>,
key = 2001,
deviceInfo = (vim.Description) {
dynamicType = <unset>,
label = "Hard disk 2",
summary = "9439212 KB",
},
backing = (vim.vm.device.VirtualDisk.FlatVer2BackingInfo) {
dynamicType = <unset>,
fileName = "[datastore2] CLUSTER01/CLUSTER01_1.vmdk",
datastore = 'vim.Datastore:4aea17ed-5267d790-647d-001a9253e63a',
diskMode = "persistent",
split = false,
writeThrough = false,
thinProvisioned = false,
eagerlyScrub = <unset>,
uuid = "6000C292-3bd5-1a68-c5f8-c44ce2af81bc",
contentId = "a757fc1a1c7be97b743264ebd8428c98",
changeId = <unset>,
parent = (vim.vm.device.VirtualDisk.FlatVer2BackingInfo) null,
},
connectable = (vim.vm.device.VirtualDevice.ConnectInfo) null,
controllerKey = 1000,
unitNumber = 1,
capacityInKB = 9439212,
shares = (vim.SharesInfo) {
dynamicType = <unset>,
shares = 1000,
level = "normal",
},
},
(vim.vm.device.VirtualDisk) {
dynamicType = <unset>,
key = 2002,
deviceInfo = (vim.Description) {
dynamicType = <unset>,
label = "Hard disk 3",
summary = "8394987 KB",
},
backing = (vim.vm.device.VirtualDisk.FlatVer2BackingInfo) {
dynamicType = <unset>,
fileName = "[datastore2] CLUSTER01/CLUSTER01_2.vmdk",
datastore = 'vim.Datastore:4aea17ed-5267d790-647d-001a9253e63a',
diskMode = "persistent",
split = false,
writeThrough = false,
thinProvisioned = false,
eagerlyScrub = <unset>,
uuid = "6000C29f-b4ee-1f59-7c65-679b4c8af87d",
contentId = "3941f27e9828baf128b12f0a098e3fe7",
changeId = <unset>,
parent = (vim.vm.device.VirtualDisk.FlatVer2BackingInfo) null,
},
connectable = (vim.vm.device.VirtualDevice.ConnectInfo) null,
controllerKey = 1000,
unitNumber = 2,
capacityInKB = 8394987,
shares = (vim.SharesInfo) {
dynamicType = <unset>,
shares = 1000,
level = "normal",
},
},
Once you have the bus number and unit number you can use that with the VM ID to remove the virtual disks from the VM as shown below.
~ # vim-cmd vmsvc/device.diskremove
Insufficient arguments.
Usage: device.diskremove vmid controller number unit number delete file
Remove a disk from this virtual machine.
~ # vim-cmd vmsvc/device.diskremove 352 0 1 true
~ # vim-cmd vmsvc/device.diskremove 352 0 2 true
After the commands have been completed you’ll have to manually delete the files on the datastore. The VMX file for the VM will also only be updated to set the “present” value to false.
scsi0:1.present = "FALSE"
scsi0:1.fileName = "CLUSTER01_1.vmdk"
scsi0:1.deviceType = "scsi-hardDisk"
scsi0:2.present = "FALSE"
scsi0:2.fileName = "CLUSTER01_2.vmdk"
scsi0:2.deviceType = "scsi-hardDisk"
Editing VM parameters
In some cases, you might want to edit the settings for a VM that you would normally access in the vSphere client by select the VM, right-clicking and select Edit Settings. Without the vSphere client, it is necessary to make those changes in the VMX file and a good source of information about the various settings can be found at sanbarrow.com.
To get started I used the command vim-cmd vmsvc/get.options <VMID> to get the current settings of the various options available for configuration. I then used the following method to set a BIOS delay, enable hot-add memory and CPU , and set disk shares to high.
1) Powered down the VM with vim-cmd vmsvc/power.shutdown <VMID>.
2) The below parameters were added to the VMX file and the file was saved.
bios.bootDelay = "5000"
sched.scsi0:0.shares = "high"
vcpu.hotadd = "TRUE"
mem.hotadd = "TRUE"
2) I ran the command vim-cmd vmsvc/releoad <VMID> to reload the configuration and then vim-cmd vmsvc/get.options <VMID> again to verify the changes
3) The command vim-cmd vmsvc/power.on <VMID> was run to start up the VM.
vim-cmd vmsvc/get.options Output
Configuration:
(vim.vm.ConfigInfo) {
dynamicType = <unset>,
changeVersion = "2006-01-09T07:52:34.844193Z",
modified = "1970-01-01T00:00:00Z",
name = "CLUSTER01",
guestFullName = "Microsoft Windows Server 2003, Enterprise Edition (32-bit)",
version = "vmx-04",
uuid = "564db48e-c9cc-cb66-c5c8-e3d52cc7db00",
instanceUuid = "5255c152-b560-67bd-67a4-03dcc8abe7e9",
npivWorldWideNameType = "",
npivDesiredNodeWwns = <unset>,
npivDesiredPortWwns = <unset>,
npivTemporaryDisabled = <unset>,
npivOnNonRdmDisks = <unset>,
locationId = "564df414-3055-a9e7-de8d-2716ba951425",
template = false,
guestId = "winNetEnterpriseGuest",
alternateGuestName = "",
annotation = "",
files = (vim.vm.FileInfo) {
dynamicType = <unset>,
vmPathName = "[datastore2] CLUSTER01/CLUSTER01.vmx",
snapshotDirectory = "[datastore2] CLUSTER01",
suspendDirectory = "[datastore2] CLUSTER01",
logDirectory = "[datastore2] CLUSTER01",
},
tools = (vim.vm.ToolsConfigInfo) {
dynamicType = <unset>,
toolsVersion = 8193,
afterPowerOn = false,
afterResume = false,
beforeGuestStandby = false,
beforeGuestShutdown = false,
beforeGuestReboot = <unset>,
toolsUpgradePolicy = "manual",
pendingCustomization = <unset>,
syncTimeWithHost = false,
},
flags = (vim.vm.FlagInfo) {
dynamicType = <unset>,
disableAcceleration = false,
enableLogging = true,
useToe = false,
runWithDebugInfo = false,
monitorType = "release",
htSharing = "any",
snapshotDisabled = <unset>,
snapshotLocked = <unset>,
diskUuidEnabled = false,
virtualMmuUsage = "automatic",
virtualExecUsage = "hvAuto",
snapshotPowerOffBehavior = "powerOff",
recordReplayEnabled = false,
},
consolePreferences = (vim.vm.ConsolePreferences) null,
defaultPowerOps = (vim.vm.DefaultPowerOpInfo) {
dynamicType = <unset>,
powerOffType = "preset",
suspendType = "preset",
resetType = "preset",
defaultPowerOffType = "soft",
defaultSuspendType = "hard",
defaultResetType = "soft",
standbyAction = "checkpoint",
},
hardware = (vim.vm.VirtualHardware) {
dynamicType = <unset>,
numCPU = 0,
memoryMB = -1884154149,
},
cpuAllocation = (vim.ResourceAllocationInfo) {
dynamicType = <unset>,
reservation = 0,
expandableReservation = <unset>,
limit = -1,
shares = (vim.SharesInfo) {
dynamicType = <unset>,
shares = 1000,
level = "normal",
},
overheadLimit = <unset>,
},
memoryAllocation = (vim.ResourceAllocationInfo) {
dynamicType = <unset>,
reservation = 0,
expandableReservation = <unset>,
limit = -1,
shares = (vim.SharesInfo) {
dynamicType = <unset>,
shares = 5120,
level = "normal",
},
overheadLimit = <unset>,
},
memoryHotAddEnabled = false,
cpuHotAddEnabled = false,
cpuHotRemoveEnabled = false,
hotPlugMemoryLimit = 0,
hotPlugMemoryIncrementSize = 0,
cpuAffinity = (vim.vm.AffinityInfo) null,
memoryAffinity = (vim.vm.AffinityInfo) null,
networkShaper = (vim.vm.NetworkShaperInfo) null,
extraConfig = (vim.option.OptionValue) [
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "nvram",
value = "CLUSTER01.nvram",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "deploymentPlatform",
value = "windows",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "MemAllowAutoScaleDown",
value = "FALSE",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "MemTrimRate",
value = "-1",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "buslogic.noDriver",
value = "false",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "replay.supported",
value = "false",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "sched.swap.derivedName",
value = "/vmfs/volumes/4aea17ed-5267d790-647d-001a9253e63a/CLUSTER01/CLUSTER01-719cecef.vswp",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "scsi0:0.redo",
value = "",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "scsi0:1.redo",
value = "",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "scsi0:2.redo",
value = "",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "vmotion.checkpointFBSize",
value = "16777216",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "ethernet0.generatedAddressOffset",
value = "0",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "hostCPUID.0",
value = "0000000a756e65476c65746e49656e69",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "guestCPUID.0",
value = "0000000a756e65476c65746e49656e69",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "virtualHW.productCompatibility",
value = "hosted",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "userCPUID.0",
value = "0000000a756e65476c65746e49656e69",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "hostCPUID.1",
value = "000006f7000408000000e3bdbfebfbff",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "guestCPUID.1",
value = "000006f700010800000022010febbbff",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "userCPUID.1",
value = "000006f7000408000000e3bdbfebfbff",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "hostCPUID.80000001",
value = "00000000000000000000000120100800",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "guestCPUID.80000001",
value = "00000000000000000000000120100800",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "userCPUID.80000001",
value = "00000000000000000000000120100800",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "evcCompatibilityMode",
value = "false",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "unity.customColor",
value = "#C0C0C0",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "vmware.tools.internalversion",
value = "8193",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "vmware.tools.requiredversion",
value = "8193",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "vmware.tools.installstate",
value = "none",
},
(vim.option.OptionValue) {
dynamicType = <unset>,
key = "vmware.tools.lastInstallStatus",
value = "unknown",
}
],
datastoreUrl = (vim.vm.ConfigInfo.DatastoreUrlPair) [
(vim.vm.ConfigInfo.DatastoreUrlPair) {
dynamicType = <unset>,
name = "datastore2",
url = "/vmfs/volumes/4aea17ed-5267d790-647d-001a9253e63a/",
}
],
swapPlacement = "inherit",
swapDirectory = <unset>,
preserveSwapOnPowerOff = <unset>,
bootOptions = (vim.vm.BootOptions) {
dynamicType = <unset>,
bootDelay = 0,
enterBIOSSetup = false,
},
ftInfo = (vim.vm.FaultToleranceConfigInfo) null,
vAppConfig = (vim.vApp.VmConfigInfo) null,
vAssertsEnabled = false,
changeTrackingEnabled = <unset>,
}