Skip to content

Commit cdef816

Browse files
Reverting to old VHD mount solution.
1 parent 5e23286 commit cdef816

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

ComputeAdmin/AzureStack.ComputeAdmin.psm1

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -440,15 +440,12 @@ function New-Server2016VMImage {
440440
}
441441
Write-Verbose -Message "Preparing VHD"
442442

443-
Mount-DiskImage -ImagePath $VHDPath -Passthru
444-
$disknum = (Get-DiskImage -ImagePath $VHDPath).Number
445-
$VHDDriveLetter = (get-disk -number $disknum| `
446-
Initialize-Disk -PartitionStyle MBR -PassThru | `
447-
New-Partition -UseMaximumSize -AssignDriveLetter:$False -IsActive:$true | `
448-
Format-Volume -Confirm:$false -FileSystem NTFS -force | `
449-
get-partition | `
450-
Add-PartitionAccessPath -AssignDriveLetter -PassThru | `
451-
get-volume).DriveLetter
443+
$VHDMount = Mount-DiskImage -ImagePath $VHDPath -PassThru -ErrorAction Stop
444+
$disk = $VHDMount | Get-DiskImage | Get-Disk -ErrorAction Stop
445+
$disk | Initialize-Disk -PartitionStyle MBR -ErrorAction Stop
446+
$partition = New-Partition -UseMaximumSize -Disknumber $disk.DiskNumber -IsActive:$True -AssignDriveLetter -ErrorAction Stop
447+
$volume = Format-Volume -Partition $partition -FileSystem NTFS -confirm:$false -ErrorAction Stop
448+
$VHDDriveLetter = $volume.DriveLetter
452449

453450
Write-Verbose -Message "VHD is mounted at drive letter: $VHDDriveLetter"
454451

@@ -481,12 +478,8 @@ function New-Server2016VMImage {
481478
} catch {
482479
Write-Error -ErrorRecord $_ -ErrorAction Stop
483480
} finally {
484-
$retryAttempts = 0;
485-
while ((Test-Path -Path "$VHDDriveLetter`:\") -and ($retryAttempts -lt 5)) {
486-
Write-Verbose -Message "Attempting to dismount the VHD..."
487-
Get-DiskImage -ImagePath $VHDPath | Dismount-DiskImage
488-
$retryAttempts = $retryAttempts+1;
489-
sleep 1
481+
if ($VHDMount) {
482+
$VHDMount | Dismount-DiskImage
490483
}
491484
if ($IsoMount) {
492485
$IsoMount | Dismount-DiskImage

ComputeAdmin/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Adding a VM Image requires that you obtain the GUID value of your Directory Tena
2020
$aadTenant = Get-AADTenantGUID -AADTenantName "<myaadtenant>.onmicrosoft.com"
2121
```
2222

23-
Otherwise, it can be retrieved directly from your Azure Stack deployment. First, add your host to the list of TrustedHosts:
23+
Otherwise, it can be retrieved directly from your Azure Stack deployment. This method can also be used for AD FS. First, add your host to the list of TrustedHosts:
2424
```powershell
2525
Set-Item wsman:\localhost\Client\TrustedHosts -Value "<Azure Stack host address>" -Concatenate
2626
```
@@ -42,6 +42,8 @@ $ISOPath = "<Path to ISO>"
4242
New-Server2016VMImage -ISOPath $ISOPath -TenantId $aadTenant
4343
```
4444

45+
This command may show a popup prompt that can be ignored without issue.
46+
4547
To ensure that the Windows Server 2016 VM Image has the latest cumulative update, provide the -IncludeLatestCU parameter.
4648

4749
Please note that to use this image for **installing additional Azure Stack services**, you will need to make use of the -Net35 parameter to install .NET Framework 3.5 into the image.

0 commit comments

Comments
 (0)