Wednesday, May 25, 2016

Repair Windows Boot Loader with bootrec

When you use the Recovery Environment (Windows RE) to troubleshoot startup issues, first try the Startup Repair option in the System Recovery Options dialog box. If this does not resolve the issue, or if you have to manually troubleshoot additional issues, use the Bootrec.exe tool. This article talks about how to use the Bootrec.exe tool in the Windows RE to troubleshoot and repair the following items in Windows Vista or Windows 7:

  • A master boot record (MBR)
  • A boot sector
  • A Boot Configuration Data (BCD) store
How to run the Bootrec.exe tool
To run the Bootrec.exe tool, first start the Windows RE:
  1. Put the Windows Vista or Windows 7 media in the DVD drive, and then start the computer.
  2. Press a key when you are prompted.
  3. Select a language, a time, a currency, a keyboard, or an input method, and then click Next.
  4. Click Repair your computer.
  5. Select the operating system that you want to repair, and then click Next.
  6. In the System Recovery Options dialog box, click Command Prompt.
  7. Type Bootrec.exe, and then press Enter.
Note To start the computer from the Windows Vista or Windows 7 DVD, the computer must be configured to start from the DVD drive. For information about how to do this, see the documentation that was included with the computer, or contact the computer manufacturer.

Bootrec.exe options
The Bootrec.exe tool supports the following options. Use the option that's appropriate for your situation.

/FixMbr

This option writes a Windows 7 or Windows Vista-compatible MBR to the system partition. It does not overwrite the existing partition table. Use this option when you must resolve MBR corruption issues, or when you have to remove nonstandard code from the MBR.

/FixBoot

This option writes a new boot sector to the system partition by using a boot sector that's compatible with Windows Vista or Windows 7. Use this option if one of the following conditions is true:
  • The boot sector was replaced with a nonstandard Windows Vista or Windows 7 boot sector.
  • The boot sector is damaged.
  • An earlier Windows operating system was installed after Windows Vista or Windows 7 was installed. In this situation, the computer starts by using Windows NT Loader (NTLDR) instead of Windows Boot Manager (Bootmgr.exe).

/ScanOs

This option scans all disks for installations that are compatible with Windows Vista or Windows 7. It also displays the entries that are currently not in the BCD store. Use this option when there are Windows Vista or Windows 7 installations that the Boot Manager menu does not list.

/RebuildBcd

This option scans all disks for installations that are compatible with Windows Vista or Windows 7. Additionally, it lets you select the installations that you want to add to the BCD store. Use this option when you must completely rebuild the BCD store.
Note Use the Bootrec.exe tool to troubleshoot a "Bootmgr Is Missing" error. If rebuilding the BCD store doesn't resolve the startup issue, you can export and delete the BCD store and then run this option again. By doing this, you make sure that the BCD store is completely rebuilt.

To do this, type the following commands at the Windows RE command prompt:
  • bcdedit /export C:\BCD_Backup
  • c:
  • cd boot
  • attrib bcd -s -h -r
  • ren c:\boot\bcd bcd.old
  • bootrec /RebuildBcd

“An operating system wasn’t found” error when booting Windows

Symptoms
When trying to boot Windows, you receive the error:

An operating system wasn’t found. Try disconnecting any drives that don’t contain an operating system.

Press Ctrl+Alt+Del to restart

Resolution
A bootable USB or DVD with Windows 7 or higher is needed to bring up the Command Prompt.

Bring up the command prompt:
  1. Boot from any DVD or USB Windows 7, 8, or 10 media.
  2. Once you have reached the Windows Setup screen (where you select the Language, Time and Keyboard settings), press the SHIFT + F10 keys to bring up the Command Prompt.

Find out whether your disk is set to GUID Partition Table (GPT) or Master Boot Record (MBR):
  1. In the Command Prompt, type diskpartand press Enter.
  2. Type list disk and press Enter.
  3. Look for your disk and see if the GPT column has an asterisk (*) – this will indicate the disk is GPT. If no asterisk is found, then the disk is set as MBR.
  4. Type exit and press Enter.
If the type is MBR:

  1. From the Command Prompt, type dir a: and press Enter.
    1. If drive A: is found and a directory is displayed, check for the \Windows folder in the directory. If it is there, that is the System Drive. Skip to step 2.
    2. If the drive is not found or it doesn’t contain the \Windows folder, type dir b: and press Enter. Continue through the alphabet until the drive with the \Windows folder is found, but skip the X: drive. That will be the install files from the USB or DVD you are using. The most common location is the C: drive, so that example will be used in the rest of the article.
  2. Once it is found, type:bcdboot C:\Windows /S C:
    1. In this case, C is the drive where Windows folder was found. If the Windows folder is on a different drive, use that drive letter instead of “C” in the bcdboot command above.
  3. The message Boot files successfully created must be shown before you can continue.
  4. Type: diskpart and press Enter.
  5. Type: list disk and press Enter.
  6. Type: sel disk C and press Enter.
    1. In this case, C is the drive where Windows folder was found. If the Windows folder is on a different drive, use that drive letter instead of “C” in the sel disk command above.
  7. Type: list vol and press Enter.
  8. Type: sel vol C and press Enter.
    1. In this case, C is the drive where Windows folder was found. If the Windows folder is on a different drive, use that drive letter instead of “C” in the sel disk command above.
  9. Type: active and press Enter.
    1. You should get a confirmation that the volume has been successfully set as active. If you don’t get the confirmation, it means that either the disk is set to GPT (not MBR), or there is a problem with the disk. Make sure you are working with the right disk.
  10. Type: exit and press Enter.
  11. Reboot the device - you can do this quickly from the command prompt by typing: shutdown -f -r -t 00 and press Enter.
If the type is GPT:
  1. From the Command Prompt, type dir a: and press Enter.
    1. If drive A: is found and a directory is displayed, check for the \Windows folder in the directory. If it is there, that is the System Drive. Skip to step 2.
    2. If the drive is not found or it doesn’t contain the \Windows folder, type dir b: and press Enter. Continue through the alphabet until the drive with the \Windows folder is found, but skip the X: drive. That will be the install files from the USB or DVD you are using. The most common location is the C: drive, so that example will be used in the rest of the article.
  2. Type: diskpart and press Enter.
  3. Type: list disk and press Enter
  4. Type: sel disk C and press Enter.
    1. In this case, C is the drive where Windows folder was found. If the Windows folder is on a different drive, use that drive letter instead of “C” in the sel disk command above.
  5. Type: list part and press Enter.
  6. Look for the partition labeled as System.
  7. Once it is found, assign the letter R to the partition. If the letter R is already taken, you can choose any unassigned letter. To assign the letter type: assign letter=r: and press Enter.
  8. Type: exit and press Enter.
  9. Return to the command prompt, type the following one line at a time, pressing Enter after each line:
    1. cd /d r:\EFI\Microsoft\Boot\
    2. ren BCD BCD.bak
    3. bcdboot c:\Windows /l en-us /s m: /f UEFI
      • Note The /l en-us part of the command sets the Windows language to English. To set a different language, replace en-us with a different language code (such as de-de for German).
  10. Reboot the device - you can do this quickly from the command prompt by typing: shutdown -f -r -t 00 and pressing Enter.

Windows server startup repair

Cases

Most of the no boot cases are caused by either of the following reasons:   
  • Disk metadata corruption in the master boot record (MBR), partition table, or boot sector of Windows RE partition.
  • Missing or corrupt boot manager.
  • Missing or corrupt boot configuration data.

Startup Repair Process

Startup Repair will try to repair computers that are unbootable because of the following reasons:
  • Registry corruption
  • Missing or damaged system and driver files
  • Disk metadata corruption (MBR, partition table, and boot sector)
  • File system metadata corruption
  • Installation of problematic or incompatible drivers
  • Installation of incompatible Windows service packs and patches
  • Corrupt boot configuration data
  • Bad memory and hard disk hardware (detection only)

How Windows RE Works
 Log file location: Startup Repair Log:
After Startup Repair has run, a text log with diagnostic information and repair result is generated within the recovery console. This log file is located at %WINDIR%\System32\LogFiles\Srt\SrtTrail.txt


  •  We can execute startrep.exe tool in recovery console to address corrupt registry issues if any in Windows Server 2008 R2
 If the Windows registry is slightly or moderately corrupted, you may be able to restart the computer in Safe mode and use System Restore to restore the registry of the computer to the last known good configuration. However, if the Windows registry is severely corrupted, all types of logon will be prevented. Attempting to log on to Windows causes the system to fail and then to restart. In this situation, you will need to boot the system into the Recovery Console instead of into Windows. Once in the Recovery Console, you can use the Startup Repair tool. Startup Repair automates common diagnostic and repair tasks of unbootable Windows installations.
a)       Boot from your Windows Vista or Windows Server 2008 DVD
b)       On the first screen of Setup choose Next
c)       In the lower left of the screen choose "repair your computer"
d)       On the System Recovery Options screen choose your installation of Windows and then click next
e)       Click "Command prompt"
f)        Go to X:\sources\recovery> startrep.exe
g)       This will take a while but will address any registry related issues.
 
Event ID 4005 — Windows Logon Availability



  • Sfc Scannow command address file based corruptions if any.
a)       Boot from your Windows Vista or Windows Server 2008 DVD
b)       On the first screen of Setup choose Next
c)       In the lower left of the screen choose "repair your computer"
d)       On the System Recovery Options screen choose your installation of Windows and then click next
e)       Click "Command prompt"
f)        Type in the following command: SFC.EXE /scannow /offbootdir=c:\ /offwindir=c:\windows
g)       When complete type in exit to see if Windows starts up now.

  • Chkdsk to address disk and filesystem based issues.
Boot the machine in recovery console mode and run chkdsk on C: drive [Local Fixed Disk]
chkdsk C: /f and then chkdsk c: /r 
/f - Fixes errors on the disk. The disk must be locked. If chkdsk cannot lock the drive, a message appears that asks you if you want to check the drive the next time you restart the computer.
/r - Locates bad sectors and recovers readable information. The disk must be locked. /r includes the functionality of /f, with the additional analysis of physical disk errors.

How to save $ dollar on backup software

Originally Created by tech-jockey


There are mainly two types of backup technique widely used to backup virtual machine in vmware.

1) Backup Lun

2) Snapshot based


Both the techniques are good but have some pros & cons.

1) Backup Lun - We take incremental backup of whole Lun, means we are taking backup of all the vms which reside there in the Lun.


This method is safe with less backup failure rate but it is difficult to manage and need good understanding of storage so company need at least L2 folks to maintain this.

Second in case you need backup of only one VM this method is not right for you because it take backup of whole Lun means backup of all the vms inside it which are not required and this way there would be waste of storage space.

It will analyze the daily change in the Lun and replicate the same to another place, sounds good but incremental data of a multiple VMs would be large enough to cause latency and other VMs would suffer since its Lun to Lun change copy.

Most of the time this feature is provided by the storage vendor and storage to storage replication is very fast/consistent plus we don't need to pay extra $ dollar to any backup vendor.

2) Snapshot based - In this technique we select a vm or list of vms which reside in different Luns and different virtual clusters.


This way we don't need to take backup of all the vms inside a Lun, we can choose vms of our choice according to our requirement.

Snapshot based technique is very easy to use for backup/restore and they are smooth enough that anyone can handle it with 1-2 days of training.

It require third party tool which analyze the incremental changes of the vm and take the backup after applying compression and DE-duplication, there are few tools available in the market to do this but they are not free and most of them offer CPU based license.

Problem with CPU based license is suppose your blade server is having 4 physical socket and you have to take backup of 10 machine out of 60 running there then it would be not a good idea to spend lots of money on licensing.

In production its not good idea to fully utilize the resource so not advisable to put all the vms in the same host which is licensed to take backup.

So with CPU license backup vendors are basically forcing you to buy more and more licenses.


Now is there any idea to reduce the cost and still use cpu based license with snapshot backup?

::::: Yes there are ideas and this article if few of them, its again an idea not step by step solution.
::::: I have used this idea many times but there lots of manual steps were taken which we can automate easily.
::::: Few folkes with good understanding of vmware with powershell can do it within a week as per my understanding and automate all the thing

How to do it ??


Idea is we would take some machine with 40-50% load and use them for backup because anyway when agent/appliance based backup tool is used we need to ensure there is enough resource available for them to take the backup and anyway we take backup in off-hour so we can easily get it.

a) Identify the vms which we need to take the backup
b) Create small list may be .csv file and put 10-15 vms there
c) Identify the time
d) Do a vMotion of those vms among backup licensed host and note existing hostname in temp variable
e) Start the backup and according to prior calculation put a check that backup is done or not, you can check by using your outlook emails or to check whether vm has still snapshot attached to it through vmware powercli command.
f) When it is confirmed than backup is completed and no snapshot is there , just move it to old host, do the same for all other vms as well and free the resource at backup host so that you can put another list of vms for backup.

Below is the script we can use to move the vm on specific time, although for a large environment it require more coding but once you setup things properly you will save cost.



###############################################################################
clear
Add-PSSnapin VMware.VimAutomation.Core
$Admin ="tech-jockey\jockey-admin"
$Password = Get-Content c:\vccred\securestring.txt | convertto-securestring
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $Admin, $Password
Connect-VIServer tech-jockey-vCenter -SaveCredentials -Credential $Credential
$a = Get-Date
echo $a.Hour

if($a.Hour -ge 15)
{

    $vms=get-folder -name vm-tobe-backup |Get-VM
    foreach($item in $vms)
    {
Get-VM -Name $item.name | Move-VM –Destination (Get-VMHost jockeyhost1)

    }
}
###############################################################################


More Explanation of Steps:-


a)
VMs identification should be based on your requirement and design of environment.
You have to segregate the vms and put them on vCenter folders and get the list with below command

$vms=get-folder -name folder_name|get-vm

above command will find the specified folder and provide an output for pipe to get-vm command.
get-vm command will find the list and details of all the vms in the folder and store it to a variable $vms

b)
You have to create some .csv files manually and put vm names there so that you can pass it to the script its basic idea.
Second use vCenter folder and schedule backup time for complete folder ,
this way you can create .csv file on run time and extarct vmHost and vmName value in the csv so that
after completion of the backup you will again use it to move vm back to old host and then delete temp csv file.

c)
It is the most critical part where you have to do lots of analysis on backup time like which vm is taking how much time to complete the backup and writing how much data.
A particular folder backups are completing in how much time, record the trend and make schedule accordingly

d)
You have already created the csv file with vm name and old host name so now the time is to do vmotion on backup host

e)
Start the backup and according to your calculation put a check after some intervals to see if backup has been complated of not, like you can monitor email alert sent by backup software and there are many other method to check it.

f)
Once you or script is sure that backup is complete next task is to read the temp csv file and move these VMs back to the old host
put a check after 10 minutes and check whether they are on the old host or not
Repeat the same for other vms and enjoy the saving.


Please like and share the page ,Your comments are welcome !

Thanks,

Team Tech-jockey

http://tech-jockey.blogspot.com/





Monday, May 16, 2016

Getting More Information About You Cluster LUN’s

Method 1

This method is fully supported by Microsoft and is relatively strait forward.
Step 1: Import the FailoverClusters module into your PowerShell Window  
              Import-Module FailoverClusters
Step 2: Get the CSV object your interested in using the Get-ClusterSharedVolume cmdlet
              $csv = Get-ClusterSharedVolume –Name “MyCSV”
Step 3: Get the Cluster Parameters for the CSV object using Get-ClusterParameter
              $CSVParams = Get-ClusterParameter -InputObject $csv
Step 4: Filter to get just the DiskIdGuid 
              ($CSVParams | Where-object -FilterScript {$_.Name -eq "DiskIdGuid"}).Value
Ok now you’ve got the GUID for the LUN it will be something like {32443078-9afc-4c0a-b142-466f8f564051}.
Step 5: Start diskpart.exe
Step 6: Start iterating over disks using select disk and then uniqueid disk until you match the GUID’s. It will look like this: 
C:\Users\taylorb>diskpart.exe
Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: 37-4611K2713G

DISKPART> select disk 1
Disk 1 is now the selected disk.

DISKPART> uniqueid disk
Disk ID: {F1B5319E-FF92-40BB-9BC9-D5FFAD0AD66B}

DISKPART> select disk 2
Disk 2 is now the selected disk.

DISKPART> uniqueid disk
Disk ID: {32443078-9AFC-4C0A-B142-
466f8f564051}


Step 7: Once you find the disk you want you can use the detail disk command to get more information.  It will look like this:

DISKPART> detail disk
IBM 2810XIV  Multi-Path Disk Device
Disk ID: {32443078-9AFC-4C0A-B142-
466f8f564051}
Type   : FIBRE
Status : Reserved
Path   : 0
Target : 1
LUN ID : 2
Location Path : UNAVAILABLE
Current Read-only State : No
Read-only  : No
Boot Disk  : No
Pagefile Disk  : No
Hibernation File Disk  : No
Crashdump Disk  : No
Clustered Disk  : Yes

There are no volumes.


Method 2

Again I must reiterate this is not an officially supported API it has no warrantee – it may break at any time and Microsoft Support can not and will not help you with it.  Now that the disclaimer is over – in this example I am using the VDS api’s to do the mapping for me.

Script:-
 
#Load the Microsoft Storage VDS Library
#
This is an undocumented, unsupported library, there is no warrantee nor gaurantees. [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Storage.Vds") | Out-Null $VdsServiceLoader = New-Object Microsoft.Storage.Vds.ServiceLoader $VdsService = $VdsServiceLoader.LoadService($null) $VdsService.WaitForServiceReady() $VdsService.Reenumerate()
#Build up a collection of all disks presented to the os $Disks = ($VdsService.Providers |% {$_.Packs}) |% {$_.Disks}
#Import the FailoverClusters module Import-Module FailoverClusters
#Retreve all of the CSV Lun’s $AllCSVs = Get-ClusterSharedVolume foreach ($Csv in $AllCSVs)
{
   
$CSVParams = Get-ClusterParameter -InputObject $Csv
    
   
#Retreve the DiskIDGuid Object from the Cluster Parameters $DiskGUIDString = ($CSVParams | Where-object -FilterScript {$_.Name -eq "DiskIdGuid"}).Value
    
   
#Match up the DiskID’s $Disk = ($Disks | Where-Object -FilterScript {$_.DiskGuid -eq $DiskGUIDString})
       
Write-Host "CSV ClusterResourceName: " $Csv.Name
       
Write-Host "DiskID: " $DiskGUIDString
       
Write-Host "DiskFriendlyName: " $Disk.FriendlyName
       
Write-Host "DiskName: " $Disk.Name
       
Write-Host "DiskAddress: " $Disk.DiskAddress
       
Write-Host
}


Sample Output




 Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Users\taylorb>.\GetCSVDevInfo1.ps1
CSV ClusterResourceName:  Cluster_CSV1_IBMXIV
DiskID:  {32443078-9afc-4c0a-b142-
466f8f564051}
DiskFriendlyName:  IBM 2810XIV  Multi-Path Disk Device
DiskName:  \\?\PhysicalDrive2
DiskAddress:  Port1Path0Target1Lun2

CSV ClusterResourceName:  Cluster_CSV2_IBMXIV
DiskID:  {ee36e403-75cb-4e23-87b4-e82af7949f4e}
DiskFriendlyName:  IBM 2810XIV  Multi-Path Disk Device
DiskName:  \\?\PhysicalDrive3
DiskAddress:  Port1Path0Target1Lun3

CSV ClusterResourceName:  Cluster_CSV3_IBMXIV
DiskID:  {5db28bcb-6ed3-4b80-b363-861a25cc10e4}
DiskFriendlyName:  IBM 2810XIV  Multi-Path Disk Device
DiskName:  \\?\PhysicalDrive4
DiskAddress:  Port1Path0Target1Lun4

Identify LUN IDs in Windows Server 2012 R2

Each iSCSI disk has a unique LUN ID.
To View the LUN ID of  a disk, you can use the diskpart command.
Here are the steps to view the LUN ID of a disk:

To View the disks:

list disk

    Select a disk

select disk


    View the LUN ID of the disk

detail disk


You can use some wmi command also to get the details
Get-WmiObject Win32_DiskDrive | Select Name, SCSIBus,SCSILun

How to get target WWN for a LUN On Windows 2012 R2 for FC SAN

Download the fcinfo for windows Utility from the link

http://www.microsoft.com/en-us/download/details.aspx?id=17530

Install and run from the below Command Line

C:\Windows\SysWOW64>fcinfo /details

Wednesday, May 11, 2016

Collecting Esxi Logs using the vSphere PowerCLI

Connecting to vCenter Server or an ESX/ESXi host with PowerCLI

To run specific vSphere PowerCLI cmdlets and perform administration or monitoring tasks, you must connect to vCenter Server or an ESX/ESXi host.
 
  1. Launch the vSphere PowerCLI.
  2. In the vSphere PowerCLI console window, establish a connection to an ESX/ESXi host or a vCenter Server using the command:

    Connect-VIServer -Server HostnameOrIPAddress

    You see output similar to:

    Name                    Port     User
    ----                    ----     ----
    HostnameOrIPAddress     443      Username


    Note: If the certificate is not trusted, a warnings displays. Depending on your security policy, these warnings can be ignored.

Downloading a diagnostic log bundle from vCenter Server

To download a vc-support diagnostic log bundle from vCenter Server:
  1. Enter the command:

    Get-Log -Bundle -DestinationPath c:\Storage\Location\

    You see output similar to:

    Data
    ----
    C:\Storage\Location\vc-support-nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn.tgz


  2. No progress bar is provided for the command. When completed, upload the logs to the FTP site.

Download a diagnostic log bundle from an ESX/ESXi host

To download a vm-support diagnostic log bundle from an ESX/ESXi host managed by vCenter Server:
  1. Enter the command:

    Get-VMHost HostNameOrIP | Get-Log -Bundle -DestinationPath c:\Storage\Location\

    You see output similar to:

    Data
    ----
    C:\Storage\Location\vm-support-nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn.tgz


  2. No progress bar is provided for the command. When completed, upload the logs to the FTP Site

Content of this blog has been moved to GITHUB

Looking at current trends and to make my content more reachable to people, I am moving all the content of my blog https://tech-jockey.blogsp...