將一般化 VM 從內部部署移至 Azure Stack HubMove a generalized VM from on-premises to Azure Stack Hub

您可以從內部部署環境將虛擬機器 (VM) 映射。You can add a virtual machine (VM) image from your on-premises environment. 您可以 (VHD) 將映射建立為虛擬硬碟,並將映射上傳至 Azure Stack Hub 實例中的儲存體帳戶。You can create your image as a virtual hard disk (VHD) and upload the image to a storage account in your Azure Stack Hub instance. 然後,您可以從 VHD 建立 VM。You can then create a VM from the VHD.

一般化磁片映射是利用 Sysprep 來移除任何唯一資訊 (例如使用者帳戶) ,讓它可以重複使用以建立多個 vm 的映射。A generalized disk image is one that has been prepared with Sysprep to remove any unique information (such as user accounts), enabling it to be reused to create multiple VMs. 一般化的 Vhd 適合用來建立 Azure Stack Hub cloud 操作員計畫作為 marketplace 專案使用的映射。Generalized VHDs are a good fit for when are creating images that the Azure Stack Hub cloud operator plans to use as marketplace items.

如何移動影像How to move an image

在準備 VHD 時,尋找您需要的特定區段。Find the section that that is specific to your needs when preparing your VHD.

請依照 準備 WINDOWS VHD 或 VHDX 上傳至 Azure 的步驟,在上傳之前將 VHD 正確地一般化。Follow the steps in Prepare a Windows VHD or VHDX to upload to Azure to correctly generalize your VHD prior to uploading. 您必須使用 VHD 進行 Azure Stack Hub。You must use a VHD for Azure Stack Hub.

驗證您的 VHDVerify your VHD

上傳 VHD 之前,您必須先驗證 VHD 是否符合需求。Before uploading your VHD, you must validate that the VHD meets the requirements. 不符合需求的 Vhd 將無法在 Azure Stack Hub 中載入。VHDs that don't meet the requirements will fail to load in Azure Stack Hub.

  1. 您將使用在 Hyper-v 中找到的 PowerShell 模組。You will use the PowerShell modules found with Hyper-V. 啟用 Hyper-v 會安裝支援的 PowerShell 模組。Activating Hyper-V installs supporting PowerShell modules. 您可以使用提升許可權的提示字元開啟 PowerShell,並執行下列 Cmdlet,以檢查是否有此模組:You can check that you have the module by opening PowerShell with an elevated prompt and running the following cmdlet:

    Get-Command -Module hyper-v
    

    如果您沒有 Hyper-v 命令,請參閱,請參閱 使用 hyper-v 及 Windows PowerShellIf you do not have the Hyper-V commands, see, see Working with Hyper-V and Windows PowerShell.

  2. 取得您的 VHD 在電腦上的路徑。Get the path to your VHD on your machine. 執行下列 Cmdlet:Run the following cmdlet:

    get-vhd <path-to-your-VHD>
    

    此 Cmdlet 會傳回 VHD 物件,並顯示內容,例如:The cmdlet will return the VHD object and display the attributes, such as:

    ComputerName            : YOURMACHINENAME
    Path                    : <path-to-your-VHD>
    VhdFormat               : VHD
    VhdType                 : Fixed
    FileSize                : 68719477248
    Size                    : 68719476736
    MinimumSize             : 32212254720
    LogicalSectorSize       : 512
    PhysicalSectorSize      : 512
    BlockSize               : 0
    ParentPath              :
    DiskIdentifier          : 3C084D21-652A-4C0E-B2D1-63A8E8E64C0C
    FragmentationPercentage : 0
    Alignment               : 1
    Attached                : False
    DiskNumber              :
    IsPMEMCompatible        : False
    AddressAbstractionType  : None
    Number                  :
    
  3. 使用 VHD 物件,檢查是否符合 Azure Stack Hub 的需求。With the VHD object, check that meets the requirements for Azure Stack Hub.

    此外,Azure Stack Hub 只支援第一代 (1) vm的映射。In addition, Azure Stack Hub only supports images from generation one (1) VMs.

  4. 如果您的 VHD 與 Azure Stack Hub 不相容,您將必須返回來源映射和 Hyper-v、建立符合需求的 VHD,然後上傳。If your VHD is not compatible with Azure Stack Hub, you will need to return to the source image and Hyper-V, create a VHD that meets the requirements, and upload. 若要將上傳程式中可能的損毀降至最低,請使用 AzCopy。To minimize possible corruption in the upload process, use AzCopy.

如何修正 VHDHow to fix your VHD

您必須符合下列需求,才能與 Azure Stack Hub 的 VHD 相容。The following requirements must be met for compatibility of your VHD with Azure Stack Hub.

VHD 屬於固定類型VHD is of fixed type

識別:使用 get-vhd Cmdlet 取得 VHD 物件。Identify: Use get-vhd cmdlet to get the VHD object.
修正:您可以將 VHDX 檔案轉換成 VHD、將動態擴充的磁片轉換成固定大小的磁片,但您無法變更 VM 的世代。Fix: You can convert a VHDX file to VHD, convert a dynamically expanding disk to a fixed-size disk, but you can't change a VM's generation. 使用 Hyper-v 管理員或 PowerShell 來轉換磁片。Use Hyper-V Manager or PowerShell to convert the disk.

VHD 的虛擬大小下限至少為 20 MBVHD has minimum virtual size of at least 20 MB

識別:使用 get-vhd Cmdlet 取得 VHD 物件。Identify: Use get-vhd cmdlet to get the VHD object.
修正:使用 Hyper-v 管理員或 PowerShell 來調整磁片大小。Fix: Use Hyper-V Manager or PowerShell to resize the disk.

VHD 已對齊VHD is aligned

識別:使用 get-vhd Cmdlet 取得 VHD 物件。Identify: Use get-vhd cmdlet to get the VHD object.
修正:虛擬大小必須是一個 (1) MB 的倍數。Fix: The virtual size must be a multiple of one (1) MB.

磁片必須有與 1 MiB 一致的虛擬大小。Disks must have a virtual size aligned to 1 MiB. 如果您的 VHD 是 1 MiB 的一部分,您必須將磁片大小調整為 1 MiB 的倍數。If your VHD is a fraction of 1 MiB, you'll need to resize the disk to a multiple of 1 MiB. 從上傳的 VHD 建立映射時,屬於 MiB 分數的磁片會導致錯誤。Disks that are fractions of a MiB cause errors when creating images from the uploaded VHD. 若要確認大小,您可以使用 PowerShell 的「取得 VHD」 Cmdlet 來顯示「大小」,這在 Azure 中必須是 1 MiB 的倍數,而「FileSize」會等於 VHD 頁尾的「大小」加上512個位元組。To verify the size you can use the PowerShell Get-VHD cmdlet to show "Size", which must be a multiple of 1 MiB in Azure, and "FileSize", which will be equal to "Size" plus 512 bytes for the VHD footer.

使用 Hyper-v 管理員或 PowerShell 來調整磁片大小。Use Hyper-V Manager or PowerShell to resize the disk.

VHD blob 長度VHD blob length

識別:使用 get-vhd Cmdlet 來顯示 Size Identify: Use the get-vhd cmdlet to show Size
修正: VHD blob 長度 = 虛擬大小 + vhd 頁尾長度 (512) 。Fix: The VHD blob length = virtual size + vhd footer length (512). Blob 最後的小型頁尾會說明 VHD 的屬性。A small footer at the end of the blob describes the properties of the VHD. Size 在 Azure 中必須是 1 MiB 的倍數,且在 VHD 頁尾中必須 FileSize 等於 Size + 512 個位元組。Size must be a multiple of 1 MiB in Azure, and FileSize, which will be equal to Size + 512 bytes for the VHD footer.

使用 Hyper-v 管理員或 PowerShell 來調整磁片大小。Use Hyper-V Manager or PowerShell to resize the disk.

第一代 VmGeneration one VMs

識別:若要確認您的虛擬機器是否為第1代,請使用 Cmdlet Get-VM | Format-Table Name, GenerationIdentify: To confirm if your virtual machine is Generation 1, use the cmdlet Get-VM | Format-Table Name, Generation.
修正:您將需要在 (hyper-v) 的虛擬程式中重新建立 VM。Fix: You will need to recreate your VM in your hypervisor (Hyper-V).

上傳至儲存體帳戶Upload to a storage account

您可以使用入口網站或您在入口網站中建立的容器上傳 VHD,請使用 AzCopy。You can upload your VHD with the portal, or with the container you created in the portal, use AzCopy.

用來產生 SAS URL 和上傳 VHD 的入口網站Portal to generate SAS URL and upload VHD

  1. 登入 Azure Stack Hub 使用者入口網站。Sign in to the Azure Stack Hub user portal.

  2. 選取 [ 儲存體帳戶 ],然後選取現有的儲存體帳戶或建立新的儲存體帳戶。Select Storage Accounts and select an existing storage account or create a new storage account.

  3. 在儲存體帳戶的儲存體帳戶分頁中選取 blobSelect Blobs in the storage account blade for your storage account. 選取 [容器] 以建立新的容器。Select Container to create a new container.

  4. 輸入容器的名稱,然後選取 [ 僅限 blob 的 blob (匿名讀取存取])Type the name of your container, and then select Blob (anonymous read access for blobs only).

  5. 如果您要使用 AzCopy 來上傳您的映射,而不是入口網站,請建立 SAS 權杖。If you are going to use AzCopy to upload your image rather than the portal, create a SAS token. 在儲存體帳戶中選取 [ 共用存取 簽章],然後選取 [ 產生 SAS 與連接字串]。Select Shared access signature in the storage account, and then select Generate SAS and connection string. 複製並記下 Blob 服務 SAS URLCopy and make a note of the Blob service SAS URL. 使用 AzCopy 來上傳 VHD 時,您將會使用此 URL。You will use this URL when using AzCopy to upload your VHD.

  6. 選取您的容器,然後選取 [上傳]。Select your container and then select Upload. 上傳您的 VHD。Upload your VHD.

AzCopy VHDAzCopy VHD

使用 Azure 儲存體總管或 AzCopy 來降低 VHD 在上傳程式中損毀的機率,而您的上傳將會更快。Use Azure Storage Explorer or AzCopy to reduce that chance that your VHD will be corrupted in the upload process, and your upload will be faster. 下列步驟會在 Windows 10 電腦上使用 AzCopy。The following steps use AzCopy on a Windows 10 machine. AzCopy 是命令列公用程式,可讓您在儲存體帳戶之間複製 Blob 或檔案。AzCopy is a command-line utility that you can use to copy blobs or files to or from a storage account.

  1. 如果您尚未安裝 AzCopy,請安裝 AzCopy。If you don't have AzCopy installed, install AzCopy. 您可以在「 開始使用 AzCopy」一文中找到下載和開始使用 AzCopy 的尋找指示。You find find instruction to download and get started with AzCopy in the article Get started with AzCopy. 記下您儲存二進位檔的位置。Make a note of where you store the binary. 您可以 將 AzCopy 新增至您的路徑 ,以便從 PowerShell 命令列使用它。You can add AzCopy to your path to use it from the PowerShell command line.

  2. 開啟 PowerShell 以從 shell 使用 AzCopy。Open PowerShell to use AzCopy from the shell.

  3. 使用 AzCopy 將您的 VHD 上傳至儲存體帳戶中的容器。Use AzCopy to upload your VHD into the your container in the storage account.

    set AZCOPY_DEFAULT_SERVICE_API_VERSION=2017-11-09
    azcopy cp "/path/to/file.vhd" "https://[account].blob.core.windows.net/[container]/[path/to/blob]?[SAS] --blob-type=PageBlob
    

注意

使用類似于將單一檔案上傳至虛擬目錄的語法上傳您的 VHD。Upload your VHD using syntax similar to uploading a single file to virtual directory. 新增, --blob-type=PageBlob 以確保 VHD 會以 分頁 Blob 的形式上傳,而不是預設為 封鎖Add --blob-type=PageBlob to make sure that the VHD is uploaded as a Page Blob, instead of Block by default.

如需有關使用 AzCopy 和其他存放裝置工具的詳細資訊,請參閱 使用 Azure Stack Hub 儲存體中的資料傳輸工具For more information about using AzCopy and other storage tools, see Use data transfer tools in Azure Stack Hub Storage.

在 Azure Stack Hub 中建立映射Create the image in Azure Stack Hub

  1. 登入 Azure Stack Hub 使用者入口網站。Sign in to the Azure Stack Hub user portal.

    如果您是建立平臺映射的雲端操作員,請依照 新增平臺映射 中的指示,透過系統管理員入口網站或系統管理員端點來新增 VHD。If you are a cloud operator creating a platform image, follow the instructions in Add a platform image to add the VHD through the administrator portal or with the administrator endpoints.

  2. 在使用者入口網站中,選取 [所有服務 > 映射 > 新增]。In the user portal, select All Services > Images > Add.

  3. 在 [ 建立映射] 中:In Create image:

    1. 輸入您的映射 名稱Type the Name of your image.

    2. 選取您的 用帳戶。Select your Subscription.

    3. 建立或新增映射至 資源群組Create or add the image to a Resource group.

    4. 選取 ASDK 的 位置(也稱為區域)。Select the Location, also referred to as the region, of your ASDK.

    5. 選取符合您映射的 作業系統類型Select an OS type that matches your image.

    6. 選取 [流覽] ,然後流覽至您的儲存體帳戶、容器和 VHD。Select Browse and then navigate to your Storage account, container, and VHD. 選擇 [選取] 。Choose Select.

    7. 選取 [帳戶類型] 。Select the Account type.

      • Premium 磁片 (SSD) 是由固態硬碟所支援,可提供一致且低延遲的效能。Premium disks (SSD) are backed by solid-state drives and offer consistent, low-latency performance. 進階磁碟可讓您在價格和效能之間取得最佳的平衡,並且適用於 I/O 密集型應用程式和生產工作負載。They provide the best balance between price and performance, and are ideal for I/O-intensive applications and production workloads.
      • 標準磁片 (HDD) 是由磁片磁碟機所支援,且適用于不常存取資料的應用程式。Standard disks (HDD) are backed by magnetic drives and are preferable for applications where data is accessed infrequently. 區域冗余磁片是由區域冗余儲存體所支援 (ZRS) ,可將您的資料複寫到多個區域,即使單一區域已關閉,也可供使用。Zone-redundant disks are backed by Zone redundant storage (ZRS) that replicates your data across multiple zones and are available even if a single zone is down.
    8. 選取主機攔截的 讀取/寫入Select Read/write for host catching.

    9. 選取 [建立] 。Select Create.

  4. 建立映射之後,請使用映射來建立新的 VM。Once the image is created, use the image to create a new VM.

後續步驟Next steps

將 VM 移至 Azure Stack Hub 總覽Move a VM to Azure Stack Hub Overview