Azure ローカル VM 用に Ubuntu Azure Marketplace イメージを準備する

この記事では、Azure ローカル仮想マシン (VM) で使用する Ubuntu Azure Marketplace イメージを準備する方法について説明します。 これらの手順に従って、VM に最新のセキュリティ更新プログラム、サポート、統合機能があることを確認します。

[前提条件]

  • Ubuntu 22.04 以降など、論理ボリューム管理 (LVM) を使用して Ubuntu VM を設定してライセンスを付与するアクセス許可を持つアクティブな Azure サブスクリプション。

  • Azure portal へのアクセス権限。

  • ワークロードの論理ネットワークとストレージ パスを使用して設定された Azure ローカル クラスター。 詳細については、「 論理ネットワークの作成 」および 「ストレージ パスの作成」を参照してください。

  • 前提条件を確認して完了してください。

  • クライアントを使用して Azure Local インスタンスに接続する場合は、「Azure CLI クライアント経由で Azure Local に接続する」を参照してください。

サインインしてサブスクリプションを設定する

  1. Azure ローカル インスタンス上のマシンに接続します。

  2. サインインし、次のコマンドを入力します。

    az login --use-device-code
    
  3. サブスクリプションを設定します。

    az account set --subscription <Subscription ID>
    

Azure VM のセットアップと準備

Azure VM を設定して準備するには、次の手順に従います。

  1. Azure portal にサインインします。

  2. 左側のウィンドウで[仮想マシン]、[作成]、[仮想マシン] の順に選択します。

  3. 使用可能なイメージを参照し、好みの Ubuntu バージョンを選択します。

    Azure portal イメージの選択ページのスクリーンショット。

  4. ウィザードで必要な詳細を入力し、Azure VM の設定を完了します。

    Azure ローカルで使用しないユーザー名を使用して Azure VM を作成することで、ユーザー名の競合を回避します。 Azure VM と Azure Local の両方で同じユーザー名 ("usernameA" など) を使用し、VHD を再利用すると、VM は元のログイン情報を保持します。 最適な結果を得るには、異なる資格情報 ("usernameB" など) を使用して Azure ローカル VM を設定します。

  5. VM がデプロイされたら、 VM の概要 ページに移動し、[ 接続 ] オプションを選択して、[ シリアル コンソール] を選択します。

    Azure portal の [シリアル コンソールサインイン] オプションのスクリーンショット。

  6. 資格情報を使用して VM に接続し、次のコマンドを実行します。

    1. ルート ユーザーとして VM にサインインします。

      sudo su
      
    2. cloud-initの既定の構成は Azure ローカル VM には関係ないため、クリーンアップします。

      sudo cloud-init clean
      sudo rm -rf /var/lib/cloud/ /var/log/* /tmp/*
      
    3. VM 固有の SSH ホスト キーをクリーンアップします。

      sudo rm -f /etc/ssh/ssh_host*
      

VM イメージのデータ ソースを変更する

VM イメージのデータ ソースを変更するには、次の手順に従います。

  1. ディレクトリを次のパスに変更し、ファイルを一覧表示して、 90_dpkg.cfgデータ ソース ファイルを見つけます。次のコマンドを実行します。

    cd /etc/cloud/cloud.cfg.d/
    ls
    

    出力例:

    azureuser@ubuntu-image:/etc/cloud/cloud.cfg.d$ ls
    05_logging.cfg  10-azure-kvp.cfg  90-azure.cfg  90_dpkg.cfg
    
  2. 90_dpkg.cfg ファイルを開きます。 次のコマンドを実行します。

    cat 90_dpkg.cfg
    

    出力例:

    azureuser@ubuntu-image:/etc/cloud/cloud.cfg.d$ cat 90_dpkg.cfg
    # to update this file, run dpkg-reconfigure cloud-init
    datasource_list: [ Azure ]
    
  3. Azure から NoClouddatasource_listを開いて更新します。 次のコマンドを実行します。

    sudo dpkg-reconfigure cloud-init
    

    出力例:

    Cloud-init supports searching different "Data Sources" for information that it uses to configure a cloud instance.
    
    Warning: Only select 'Ec2' if this system will be run on a system with the EC2 metadata service present. Doing so incorrectly will result in a substantial timeout on boot.
    
    Which data sources should be searched?
    
    [ ] NoCloud: Reads info from /var/lib/cloud/seed only  
    [ ] ConfigDrive: Reads data from Openstack Config Drive  
    [ ] OpenNebula: read from OpenNebula context disk  
    [ ] DigitalOcean: reads data from Droplet datasource  
    [*] Azure: read from MS Azure cdrom. Requires walinux-agent
    <Ok>
    
    1. Space キーを押して NoCloud をアクティブ化し、Azure を削除して(*) を切り替えます。

    2. Enter キーを押してファイルを保存します。

    出力例:

    Cloud-init supports searching different "Data Sources" for information that it uses to configure a cloud instance.
    
    Warning: Only select 'Ec2' if this system will be run on a system with the EC2 metadata service present. Doing so incorrectly will result in a substantial timeout on boot.
    
    Which data sources should be searched?
    
    [*] NoCloud: Reads info from /var/lib/cloud/seed only  
    [ ] ConfigDrive: Reads data from Openstack Config Drive  
    [ ] OpenNebula: read from OpenNebula context disk  
    [ ] DigitalOcean: reads data from Droplet datasource  
    [ ] Azure: read from MS Azure cdrom. Requires walinux-agent
    <Ok>
    
  4. ファイルが更新されたことを確認するには、次のコマンドを実行します。

    cat 90_dpkg.cfg
    

    出力例:

    azureuser@ubuntu-image:/etc/cloud/cloud.cfg.d$ cat 90_dpkg.cfg
    # to update this file, run dpkg-reconfigure cloud-init
    datasource_list: [ NoCloud ]
    
  5. bash 履歴を削除します。 これらのコマンドを実行します。

    sudo rm -f ~/.bash_history
    export HISTSIZE=0
    exit
    
  6. 構成の変更が完了したら、Azure VM を停止します。

Azure VM OS ディスクを Azure ローカル クラスター上の VHD にエクスポートする

Azure VM OS ディスクを Azure ローカル クラスター上の VHD にエクスポートするには、次の手順に従います。

  1. Azure ローカル リソースの Azure portal で、 VM の概要に移動します。 [ 設定] オプションで、[ ディスク] を選択し、[ ディスク名 ] リンクを選択します。

    OS ディスクの詳細ページのスクリーンショット。

  2. [ 設定] で [ ディスクのエクスポート] を選択し、[ URL の生成 ] を選択して、ディスクのセキュリティで保護された URL を生成します。

    セキュリティで保護された URL の生成を含むディスク エクスポート オプションのスクリーンショット。

  3. 次の手順のために、生成されたセキュリティで保護された URL リンクをコピーします。

ディスク エクスポート URL は、時間制限付きの SAS URL です。
URL の有効期限が切れたり、正しくコピーされたり、読み取り (r) アクセス許可がない場合、イメージの作成手順が失敗し、 401 (Unauthorized) エラーが発生する可能性があります。
401 エラーが発生した場合は、ディスク エクスポート URL を再生成し、有効期限が切れる前に使用され、追加の引用符や改行なしで貼り付けられるようにします。

Azure ローカル イメージを作成する

SAS トークンを使用して Azure ローカル イメージを作成するには、次のコマンドを実行します。

$rg = "<resource-group>"
$cl = "/subscriptions/<sub>/resourcegroups/$rg/providers/microsoft.extendedlocation/customlocations/<customlocation-name>"
$sas = '"https://EXAMPLE.blob.storage.azure.net/EXAMPLE/abcd<sas-token>"'

az stack-hci-vm image create -g $rg --custom-location $cl --name "<IMAGE-NAME>" --os-type "Linux" --image-path $sas

Azure ローカル VM を作成する

作成した Azure ローカル VM イメージを使用して Azure ローカル VM を作成するには、「Azure Arc で有効になっている Azure ローカル仮想マシンを作成する」の手順に従います。