VMware Cloud Community
mikelleen
Contributor
Contributor

Preventing New-Datastore command from formatting SCSI LUN?

I have been trying to create a datastore from a SAN volume.

The SAN volume is a SAN snapshot copy of an existing SAN volume that I has VM's on it.

This seems simple enough and I can do this thru the vSphere client with no issues, see further details in this post:

http://communities.vmware.com/thread/329871?tstart=0

As I describe in the post noted above I am using the New-Datastore command:

New-Datastore -VMHost $TargetVMCenterHost -Name $TargetVMCenterDatastoreName -Path $scsi.CanonicalName -Vmfs

The issue I am having is that when I attempt to create the datastore from PowerCLI using the code below, the datastore comes up empty, as if formatted, or not re-signatured.

titaniumlegs posted in the thread noted above:

"As to the original poster, when you ran New-Datastore, yes you reformatted the datastore."

So my question is, how do I create or add or ??? a datastore to an existing Scsi LUN that has existing data on it including VM's, via PowerCLI without formatting it?

I'm getting somewhat frustrated pursuing this answer. I'm sure others are doing this as well.

I have been trying to search and follow the threads here, and have been getting some help from LucD and others, but I freely admit that I am a PowerCLI newbie. I've been able to script the creation of VM's once I have the datastore up and running thru the vSphere GUI, as well as other tasks, but I can't seem to resolve this probably simple task.

Any help is appreciated, thanks to one and all.

Tags (1)
0 Kudos
10 Replies
mikelleen
Contributor
Contributor

I have been looking and I can't find anything on this issue, any help anyone?

Thanks!

0 Kudos
RParker
Immortal
Immortal

Well when you create a NEW datastore its self evident that it will format it.. hence the NEW command.  However if you ADD a datastore, it should NOT try to format the disk, since it could be existing.

You rescan the HBA, let it "discover" the storage, go to add storage on the ESXi host.  That will let you add it and it should NOT format it..however are you SURE it's a VMFS datastore, and not something formatted with another OS/File system?  Because you can only add NFS storage or VMFS datastores, you can't add EXT3 for example, it will not mount under ESX

0 Kudos
mikelleen
Contributor
Contributor

But looking in the PowerCLI Cmdlets reference there is no  "Add-Datastore" or similar command. Open the PowerCLI Cmdlets reference and search for datastore. There is nothing there for adding a datastore from an attached VMFS SCSI LUN.

Yes I am using a VMFS SCSI LUN.

The only way I am seeing in PowerCLI of generating a datastore and having it use a specific SCSI device is the New-Datastore command, as far as I can see.

So what am I missing here? There must be a way in PowerCLI to do this simple thing, I am hoping I am just overlooking something simple, but I have not had anyone forwarding a suggesting on how this should be done.

0 Kudos
mikelleen
Contributor
Contributor

Will the Set-HardDisk command when using the -Datastore option, creat the datastore if it does not exist?

-------------- Example 3 --------------

Set-HardDisk -HardDisk $harddisk -Datastore $datastore

Moves the hard disk to the specified datastore.

0 Kudos
LucD
Leadership
Leadership

No, it will error out if the datastore doesn't exist.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

mikelleen
Contributor
Contributor

Thanks, so any ideas on how to add the datastore without formatting it?

Someone has to be doing this I'm sure, what am I missing?????

0 Kudos
LucD
Leadership
Leadership

Afaik that is not possible with the New-Datastore cmdlet in the current build.

The ResignatureUnresolvedVmfsVolume_Task method should be able to do that.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

mikelleen
Contributor
Contributor

Thanks Luc, you had pointed me to that in another thread, and I had looked at that method.So as a new PowerCLI user, maybe I am not fully understanding:

The ResignatureUnresolvedVmfsVolume_Task description states:

Resignature an unbound VMFS volume. To safely enable sharing of the volume across hosts, a VMFS volume is bound to its underlying block device storage. When a low level block copy is performed to copy or move the VMFS volume, the copied volume will be unbound. In order for the VMFS volume to be usable, a resolution operation is needed to determine whether the VMFS volume should be treated as a new volume or not and what extents compose that volume in the event there is more than one unbound volume.

With 'Resignature' operation, a new Vmfs Uuid is assigned to the volume but its contents are kept intact. Resignature results in a new Vmfs volume on the host. Users can specify a list of hosts on which the volume will be auto-mounted.

Am I correct in assuming then that the auto-mount creates a datastore attached to the resignatured VMFS volume?

I'm not that familiar with calling these methods from PowerCLI. Is there a link that will show me how to call this method from PowerCLI?

I'll run some searches as well.

Sorry to be a PITA, your help is appreciated.

0 Kudos
mikelleen
Contributor
Contributor

So after going thru the post by LucD, I have a solution that works:

#Add datastore to host

#Get scsi device for target LUN No.

$scsilun

= "L" + $TargetLUNNo

$scsi

= Get-ScsiLun -VmHost $TargetVMCenterHost -LunType disk | Where{ $_.RuntimeName -match "$scsilun" }

$scsiCname

= $scsi.CanonicalName

#Create a list of unbound scsi devices

$hostView

= get-vmhost -name $TargetVMCenterHost | get-view

$dsView

= get-view $hostView.ConfigManager.DatastoreSystem

$unBound

= $dsView.QueryUnresolvedVmfsVolumes()

#Loop thru unbound scsi devices and resignature applicable device.

foreach

($ub in $UnBound) {

$extPaths

= @()

$Extents

= $ub.Extent;

foreach

($ex in $Extents) {

$extPaths

= $extPaths + $ex.DevicePath

}

#Only resignature desired LUN No.

IF ($extPaths -match $scsiCname)

{

$res = New-Object VMware.Vim.HostUnresolvedVmfsResignatureSpec

$res.ExtentDevicePath = $extPaths

$dsView.ResignatureUnresolvedVmfsVolume($res)

}

}

#Find and rename new datastore.

$NewDatastore

= Get-Datastore -VmHost $TargetVMCenterHost | Where{ $_.Name -like "snap-*$ProdVol0" }

Set-Datastore

$NewDatastore -Name $TargetVMCenterDatastoreName

0 Kudos
switch1
Contributor
Contributor

I'm trying to accomplish the same thing however I just want to scan and mount the datastores but not re-signature, I just need them mounted as is.

Thanks

0 Kudos