PowerShell을 사용하여 VHD 파일에서 사용자 지정 이미지 만들기

Azure DevTest Labs에서 사용자 지정 이미지를 사용하여 다음을 수행할 수 있습니다.

  • 필요한 모든 소프트웨어가 미리 설치된 VHD 파일에서 VM을 만듭니다.
  • 대상 컴퓨터에 모든 필수 소프트웨어를 설치할 필요가 없으므로 VM을 빠르게 만듭니다.
  • VM에서 사용자 지정 이미지를 만든 다음 해당 이미지를 기반으로 VM을 만들어 VM을 복제합니다.

필수 조건

이 자습서를 진행하려면 사용자 지정 이미지를 만들려는 랩의 Azure Storage 계정에 업로드된 VHD(가상 하드 디스크) 파일이 필요합니다. 스토리지 계정에 VHD 파일을 업로드하려면 다음 문서 중 하나의 지침을 따릅니다.

참고 항목

Azure Az PowerShell 모듈을 사용하여 Azure와 상호 작용하는 것이 좋습니다. 시작하려면 Azure PowerShell 설치를 참조하세요. Az PowerShell 모듈로 마이그레이션하는 방법에 대한 자세한 내용은 Azure PowerShell을 AzureRM에서 Azure로 마이그레이션을 참조하세요.

PowerShell 단계

다음 단계는 Azure PowerShell을 사용하여 VHD 파일에서 사용자 지정 이미지를 만드는 과정을 안내합니다.

  1. PowerShell 명령 프롬프트에서 Connect-AzAccount cmdlet을 사용하여 Azure 계정에 로그인합니다.

    Connect-AzAccount
    
  2. Select-AzSubscription cmdlet을 사용하여 Azure 구독을 선택합니다. <subscription ID>를 구독 ID GUID로 바꿉니다.

    $subscriptionId = '<subscription ID>'
    Select-AzSubscription -SubscriptionId $subscriptionId
    
  3. Get-AzResource cmdlet을 호출하여 랩 객체를 가져옵니다. <lab resource group name> 및 <lab name> 자리 표시자를 고유한 리소스 그룹 및 랩 이름으로 바꿉니다.

    $labRg = '<lab resource group name>'
    $labName = '<lab name>'
    $lab = Get-AzResource -ResourceId ('/subscriptions/' + $subscriptionId + '/resourceGroups/' + $labRg + '/providers/Microsoft.DevTestLab/labs/' + $labName)
    
  4. $vhdUri 변수의 자리 표시자를 업로드된 VHD 파일의 URI로 바꿉니다. Azure Portal에 있는 랩 스토리지 계정의 Blob 페이지에서 VHD 파일 URI를 가져올 수 있습니다. 예제 VHD URI는 https://acontosolab1234.blob.core.windows.net/uploads/myvhd.vhd입니다.

    $vhdUri = '<VHD URI>'
    
  5. New-AzResourceGroupDeployment cmdlet을 사용하여 사용자 지정 이미지를 만듭니다. <custom image name> 및 <custom image description> 자리 표시자를 원하는 이름 및 설명으로 바꿉니다.

    $customImageName = '<custom image name>'
    $customImageDescription = '<custom image description>'
    
    $parameters = @{existingLabName="$($lab.Name)"; existingVhdUri=$vhdUri; imageOsType='windows'; isVhdSysPrepped=$false; imageName=$customImageName; imageDescription=$customImageDescription}
    
    New-AzResourceGroupDeployment -ResourceGroupName $lab.ResourceGroupName -Name CreateCustomImage -TemplateUri 'https://raw.githubusercontent.com/Azure/azure-devtestlab/master/samples/DevTestLabs/QuickStartTemplates/201-dtl-create-customimage-from-vhd/azuredeploy.json' -TemplateParameterObject $parameters
    

전체 PowerShell 스크립트

이전 단계를 결합하면 VHD 파일에서 사용자 지정 이미지를 만드는 다음 PowerShell 스크립트가 생성됩니다. 스크립트를 사용하려면 다음 자리 표시자를 고유한 값으로 바꿉니다.

  • <구독 ID>
  • <lab resource group name>
  • <lab name>
  • <VHD URI>
  • <custom image name>
  • <custom image description>
# Log in to your Azure account.
Connect-AzAccount

# Select the desired Azure subscription.
$subscriptionId = '<subscription ID>'
Select-AzSubscription -SubscriptionId $subscriptionId

# Get the lab object.
$labRg = '<lab resource group name>'
$labName = '<lab name>'
$lab = Get-AzResource -ResourceId ('/subscriptions/' + $subscriptionId + '/resourceGroups/' + $labRg + '/providers/Microsoft.DevTestLab/labs/' + $labName)

# Set the URI of the VHD file.
$vhdUri = '<VHD URI>'

# Set the custom image name and description values.
$customImageName = '<custom image name>'
$customImageDescription = '<custom image description>'

# Set up the parameters object.
$parameters = @{existingLabName="$($lab.Name)"; existingVhdUri=$vhdUri; imageOsType='windows'; isVhdSysPrepped=$false; imageName=$customImageName; imageDescription=$customImageDescription}

# Create the custom image.
New-AzResourceGroupDeployment -ResourceGroupName $lab.ResourceGroupName -Name CreateCustomImage -TemplateUri 'https://raw.githubusercontent.com/Azure/azure-devtestlab/master/samples/DevTestLabs/QuickStartTemplates/201-dtl-create-customimage-from-vhd/azuredeploy.json' -TemplateParameterObject $parameters

다음 단계