{"id":1083,"date":"2012-10-29T10:00:06","date_gmt":"2012-10-29T14:00:06","guid":{"rendered":"http:\/\/enterpriseadmins.org\/blog\/?p=1083"},"modified":"2012-10-27T11:29:42","modified_gmt":"2012-10-27T15:29:42","slug":"detaching-scsi-luns-from-esxi-hosts","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/detaching-scsi-luns-from-esxi-hosts\/","title":{"rendered":"Detaching SCSI LUNs from ESXi hosts"},"content":{"rendered":"<p>About a month ago I experienced a production outage that related to improper removal of storage from a cluster.  In this scenario, VMFS file systems were deleted from FC devices and then the FC devices were removed from the hosts.  I&#8217;ve seen this done hundreds of times without issue, but as a best practice the devices should be detached from the host before they are removed.  Here are some articles that discuss proper removal:<\/p>\n<ul>\n<li><a href=\"http:\/\/pubs.vmware.com\/vsphere-50\/topic\/com.vmware.ICbase\/PDF\/vsphere-esxi-vcenter-server-501-storage-guide.pdf\">http:\/\/pubs.vmware.com\/vsphere-50\/topic\/com.vmware.ICbase\/PDF\/vsphere-esxi-vcenter-server-501-storage-guide.pdf<\/a> (page 126)<\/li>\n<li><a href=\"http:\/\/kb.vmware.com\/kb\/2004605\">http:\/\/kb.vmware.com\/kb\/2004605<\/a><\/li>\n<\/ul>\n<p>Manually detaching devices from a bunch of hosts doesn&#8217;t sound like a fun to me, so I created a quick script to help:<\/p>\n<pre><code class=\"language-powershell\">\r\n#These are the temporary LUNs\r\n$removeThese = @()\r\nGet-Datastore *Temp |%{\r\n$removeThese += $_.ExtensionData.info.Vmfs.Extent[0].diskName\r\n}\r\n\r\n#Manually delete file systems, then run the following:\r\n\r\nGet-VMHost esxi0* | %{\r\n  $vmHost = $_\r\n  $vmHost.name\r\n  $removeThese | %{\r\n    $esxcli = Get-EsxCli -VMHost $vmHost\r\n    $esxcli.storage.core.device.set(\"$_\",$null,$null,\"off\")\r\n  }#end device loop\r\n}#end host loop\r\n<\/code><\/pre>\n<p>Note: This code only works with ESXi 5.0 or later.  I recently tested on an ESXi 4.1 host and this code does not work.  (In 4.1 Get-EsxCli doesn&#8217;t have a storage.core namespace)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>About a month ago I experienced a production outage that related to improper removal of storage from a cluster. In this scenario, VMFS file systems were deleted from FC devices and then the FC devices were removed from the hosts. &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/detaching-scsi-luns-from-esxi-hosts\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-1083","post","type-post","status-publish","format-standard","hentry","category-scripting","category-virtualization"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=1083"}],"version-history":[{"count":5,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1083\/revisions"}],"predecessor-version":[{"id":1099,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1083\/revisions\/1099"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=1083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=1083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=1083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}