Showing posts with label vmware esx. Show all posts
Showing posts with label vmware esx. Show all posts

Tuesday, October 11, 2016

VMWare - CLI: Convert Virtual Disks - Thin to Thick

Here I’m going to show you how to convert Thin Virtual Disk (dynamic space allocation up to the provisioned size) to a Thick Virtual Disk (all space provisioned at creation).

The Thick Virtual Disk does not save space, but it is safer because the space is already allocated, there are no surprises. With a Thin Virtual Disk you migth run out of space in the Datastore and the Disk can’t grow up to the provisioned size.

thin-provisioning[6]

!-- Log in via SSH (must activate first) --
# ssh root@192.168.1.45
Password: *******


!-- List DataStore Disks (if needed) --
# ls -lh /vmfs/volumes/


!-- Access the VM Folder --
# cd /vmfs/volumes/DS-VM-DISK/UBUNTU-VM/
# ls -lh

total 16779272
-rw-------    1 root  root   16.0G Oct 10 00:41 UBUNTU-VM-flat.vmdk
-rw-------    1 root  root    8.5K Oct 10 00:41 UBUNTU-VM.nvram
-rw-------    1 root  root     473 Oct  9 22:28 UBUNTU-VM.vmdk
-rw-r--r--    1 root  root       0 Oct  9 22:25 UBUNTU-VM.vmsd
-rwxr-xr-x  1 root  root    2.6K Oct 10 00:41 UBUNTU-VM.vmx
-rw-r--r--    1 root  root  187.4K Oct 10 00:41 vmware.log


!-- Convert the Virtual Disk - Thin to Thick (Easy Way) --
# vmkfstools -j UBUNTU-VM.vmdk
Inflate: 100% done.

This option converts a thin virtual disk to Eager Zeroed Thick,
you have the same conversion done bellow the "Hard Way"

 

!-- Convert the Virtual Disk - Thick to Thin (Hard Way) --

image

# vmkfstools -i UBUNTU-VM.vmdk -d zeroedthick UBUNTU-VM_thick.vmdk
Destination disk format: VMFS zeroedthick
Cloning disk 'UBUNTU-VM.vmdk'...
Clone: 100% done.

or

# vmkfstools -i UBUNTU-VM.vmdk -d eagerzeroedthick UBUNTU-VM_thick.vmdk
Destination disk format: VMFS eagerzeroedthick
Cloning disk 'UBUNTU-VM.vmdk'...
Clone: 100% done.

!-- Replace the Thin with Thick (Virtual Disks) (Hard Way) --
# rm UBUNTU-VM-flat.vmdk
# mv UBUNTU-VM_thick-flat.vmdk UBUNTU-VM-flat.vmdk
# rm UBUNTU-VM_thick.vmdk

 

!-- All Looks as When We Started --
# ls -lh
total 3246088
-rw-------    1 root  root  16.0G Oct 10 23:59 UBUNTU-VM-flat.vmdk
-rw-------    1 root  root   8.5K Oct 10 23:59 UBUNTU-VM.nvram
-rw-------    1 root  root    471 Oct 10 23:57 UBUNTU-VM.vmdk
-rw-------    1 root  root      0 Oct 10 16:46 UBUNTU-VM.vmsd
-rw-------    1 root  root   2.5K Oct 10 23:59 UBUNTU-VM.vmx

Now you can power the VM :)


To Reverse It Check Out:

Tuesday, August 23, 2016

VMWare - Linked Clones Without vCenter (with vSphere Client)


As soon as you can create snapshots you have all the ingredients required to create linked clones.

This will walk you through the process of creating a bunch of linked clones from one master.
Only tools used are the vSphere client and a text editor on a Windows host.
First create the master VM.

It is recommended to use a thin disk ...

Give it a reasonable name - so that it stands out from the other VMs.
In the example I called the VM "dont_touch"

clip_image001
Install the new VM and when done reboot it and install VMware-tools.

Feel free to add more apps ... or sysprep the master VM ...

Once you are satisfied power down the VM.
Now create a snapshot with the vClient.

See the screenshot - the files that belong to the snapshot are hilighted.
From now on regard the directory "dont_touch" as readonly. Do not start the VM again.

clip_image002
Next use the datastore browser and download the two files hilighted in the next screen : the vmx and the snapshot-vmdk.

 clip_image003
On your Windows-host the two downloaded files should now look like this.

Don't worry - the datastorebrowser is a funny guy - he shows you two files but downloads three.
And ... he thinks this is helpful ;-)

clip_image004
First thing to do is edit the "dont_touch-000001.vmdk"
It now looks like :

# Disk DescriptorFile
version=1
encoding="UTF-8"
CID=fa3d08b7
parentCID=fa3d08b7
createType="vmfsSparse"
parentFileNameHint="dont_touch.vmdk"
# Extent description
RW 25165824 VMFSSPARSE "dont_touch-000001-delta.vmdk"
# The Disk Data Base
#DDB
ddb.longContentID = "9b8da3d63cda1e5dbea7c0f4fa3d08b7"

As we want an absolute path for the parentFileNameHint parameter we edit the vmdk descriptor so that it looks like:

Note the yellow line ! It shows the edited path.

# Disk DescriptorFile
version=1
encoding="UTF-8"
CID=fa3d08b7
parentCID=fa3d08b7
createType="vmfsSparse"
parentFileNameHint="/vmfs/volumes/4ba3aca0-eca4fd60-312d-f4ce46af50b6/dont_touch/dont_touch.vmdk"
# Extent description
RW 25165824 VMFSSPARSE "dont_touch-000001-delta.vmdk"
# The Disk Data Base
#DDB
ddb.longContentID = "9b8da3d63cda1e5dbea7c0f4fa3d08b7"

Tip: to find out the absolut path look it up in the vmx file - the parameter sched.swap.derivedName also uses the absolut path.

sched.swap.derivedName = "/vmfs/volumes/4ba3aca0-eca4fd60-312d-f4ce46af50b6/dont_touch/dont_touch-aafe8f9c.vswp"

The part marked in yellow shows the absolute path that is required to adjust the vmdk-description.

Now is also a good time to delete that parameter from the vmx file. Don't forget that !
Now we can create several copies of the vmx-file.

Give every file a new name and adjust the display name parameter.

displayName = "2k3-clone-1"

Screenshot below shows several new copies of the vmx-file - each one has the display-name adjusted and the sched.swap.derivedName line removed.

clip_image005
Now back on the ESXi create several new directories for the clones.

clip_image006
Into each new directory copy the appropriate vmx-file plus the two vmdks.

Again - don't worry - you need to upload three files but datastorebrowser only displays two.

clip_image007
Now all is left to do is add the vmx-file to the inventory and make sure you click "I copied it" on first launch.
clip_image008
During first boot of the cloned VM it is advisable to unconnect the network-card.

On a Windows VM you may want to run newsid.exe, change the hostname and configure the network on first boot.

Then reboot and enable the nics.

Taken From: http://sanbarrow.com/linkedcloneswithesxi.html

Monday, June 1, 2009

Adding Disk - Storage To VMWare ESX

In VMWare ESX, in order to be able to use a disk, this should be first in VMWare's own file system format, which is "vmfs3", other will it will not recognize the disk and, you wont be able for example store you virtual machines there.

This is quite is one a big diference between VMWare ESX and the VMWare desktop, version.
So in the next few line I'm going to show how prepare and add a disk to VMWare ESX.

Step #1 Run fdisk -l and find the disk that you want to format with VMFS3.

$ su

# fdisk -l | grep Disk
Disk /dev/sda: 32.2 GB, 32212254720 bytes
Disk /dev/sdb: 53.6 GB, 53687091200 bytes
Disk /dev/sdc: 32.2 GB, 32212254720 bytes
Disk /dev/sdd: 53.6 GB, 53687091200 bytes
Disk /dev/sde: 32.2 GB, 32212254720 bytes
Disk /dev/sdf: 10.7 GB, 10737418240 bytes
Disk /dev/sdg: 32.2 GB, 32212254720 bytes
Disk /dev/sdh: 32.2 GB, 32212254720 bytes
Disk /dev/sdi: 32.2 GB, 32212254720 bytes
Disk /dev/sdj: 21.4 GB, 21474836480 bytes
Disk /dev/sdk: 214.7 GB, 214748364800 bytes Disk /dev/cciss/c0d0: 73.3 GB, 73372631040 bytes


Note: The /dev/sdk is the one I will be adding to VMWare ESX


# fdisk -l /dev/sdk

Disk /dev/sdk: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System


Has you can see, sdk doesen't have any partitions,
so we must create one to later on format in the "vmf3" format.

Step #2 Creating a Partition (to format later on in "vmf3")

Note: the partition in this examples, ocupies all of the disk.

First we will create the partition (n) then change the type (t) to fb. Then (w) save the changes. Check fdisk /dev/sda again and list partitions (p) - it should list as fb.


# fdisk /dev/sdk

The number of cylinders for this disk is set to 26108.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p

Partition number (1-4): 1
First cylinder (1-26108, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-26108, default 26108):
Using default value 26108

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fb
Changed system type of partition 1 to fb (Unknown)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


Note: I tried to create an extended partition, but it didn't work, fdisk didn't let met change the type to "fb".


Step #3 Then run esxcfg-vmhbadevs -m to see which vmhba devices is mapped to the partion in step #1

# esxcfg-vmhbadevs -m

vmhba1:0:4:1 /dev/sdd1 4866618b-6a9fda41-fba6-00565aa64ffa
vmhba1:0:1:1 /dev/sda1 486660ea-fe9d98aa-8010-00565aa64ffa
vmhba1:0:3:1 /dev/sdc1 48666166-5068fbcd-dfcd-00565aa64ffa
vmhba1:0:2:1 /dev/sdb1 48666146-f15b8e96-2c49-00565aa64ffa
vmhba1:0:6:1 /dev/sdf1 486661b9-4da3f066-3017-00565aa64ffa
vmhba1:0:5:1 /dev/sde1 486661a4-9d3c1b7d-3ec6-00565aa64ffa
vmhba1:0:8:1 /dev/sdh1 486661e5-84ce84f3-acd2-00565aa64ffa
vmhba0:0:0:3 /dev/cciss/c0d0p3 48666bff-9ed64a25-636c-00215aa65f04
vmhba1:0:10:1 /dev/sdj1 4866620f-939412da-7ede-00565aa64ffa
vmhba1:0:7:1 /dev/sdg1 486661d0-debeffc1-9e08-00565aa64ffa
vmhba1:0:9:1 /dev/sdi1 486661f9-4cff8fab-57a6-00565aa64ffa


Because it has no partition, starting with "sdk" (ex: vmhba1:0:9:1 /dev/sdk1) , which is the disks name, let's try to list only the disks to see if VMWare ESX detects it,

# esxcfg-vmhbadevs
vmhba0:0:0 /dev/cciss/c0d0
vmhba1:0:1 /dev/sda
vmhba1:0:2 /dev/sdb
vmhba1:0:3 /dev/sdc
vmhba1:0:4 /dev/sdd
vmhba1:0:5 /dev/sde
vmhba1:0:6 /dev/sdf
vmhba1:0:7 /dev/sdg
vmhba1:0:8 /dev/sdh
vmhba1:0:9 /dev/sdi
vmhba1:0:10 /dev/sdj
vmhba1:0:11 /dev/sdk

The disk is the but there's no partition, we will create it later on.


Step #4 Formating the Previously Created Partition in "vmfs3"

Basicly we will run vmkfstools -C vmfs3 -S "volume name" vmhba#_from_step#3


In the step before we noted that VMWare detected sdk and that it had the id "vmhba1:0:11", but there was no partition, and that by comparing the results from "esxcfg-vmhbadevs -m" (list partitions) and "esxcfg-vmhbadevs" (list disks), in the previous step the id of the partition sdk1 should be "vmhba1:0:11:1", so this is the id we will be using in the format command below.

# vmkfstools -C vmfs3 -S "ESX03" vmhba1:0:11:1

Creating vmfs3 file system on "vmhba1:0:11:1" with blockSize 1048576 and volume label "ESX03".
Successfully created new volume: 4a23df5c-41c0dac6-a39f-00215aa64ffa


Now you have the disk ready ready to add to VMWare ESX,

Step #5 Add the storage to a Blade (fisical PC) in VMWARE ESX,

Just click on one blade "Configuration | Add Storage",
and selectct "Disk/Lun", and Next in following windows.
















Note: I think if you add the disk to one blade it, will be added to all the other blades.
I tried to add to a second blade and it didn't allowed me to do that.

Step #7 Create Virtual Machines, ande select the DataStorage previously created