概要
カスタムイメージを作ったときに何をしたかをメモしておく
前提
あらかじめ、Azure上にAzureで提供されているイメージから、必要な状態にしたマシンを作製しておく
結論
2017年3月17日の時点では、このページをみればよかった。
PowerShell の場合
Azure CLI 1.0 の場合
Azure CLI 2.0 の場合
実際の作業
今回は Azure CLI 2.0 の方法を、Azure CLi 0.10.6 (docker)で実行し、
途中から Azure CLI 1.0 の方法に切り替えた。
作業はじめたときに見落としていたので。
azure config arm
なっている前提
1. 元となるVMのプロビジョニングを解除する
azureuser@standalonevm:~$ sudo waagent -deprovision+user -force
WARNING! The waagent service will be stopped.
WARNING! All SSH host key pairs will be deleted.
WARNING! Cached DHCP leases will be deleted.
WARNING! Nameserver configuration in /etc/resolvconf/resolv.conf.d/{tail,original} will be deleted.
WARNING! azureuser account and entire home directory will be deleted.
メッセージを読むと、SSH の鍵などが削除されるとある。
このコマンドの実行後確認してみた
azureuser@standalonevm:~$ ls -lar
total 0
2. azure vm deallocate で VM の割当を解除
sshを接続したままで、以下のコマンドを実行すると、sshの接続が解除されるので、
なにか作業があるときは、早めに行っておくこと。
azure vm deallocate --resource-group TESTRESOURCEGROUP1 --name standalonevm
数分ほど時間がかかって、終了した
azure vm deallocate --resource-group TESTRESOURCEGROUP1 --name standalonevm
info: Executing command vm deallocate
+ Looking up the VM "standalonevm"
+ Deallocating the virtual machine "standalonevm"
3. azure vm generize で一般化する
このコマンドは、すぐにおわった
root@3371f3750d51:/# azure vm generalize --resource-group TESTRESOURCEGROUP1 --name standalonevm
info: Executing command vm generalize
+ Looking up the VM "standalonevm"
+ Generalizing the virtual machine "standalonevm"
info: vm generalize command OK
4. azure vm capture で、VMをキャプチャする
これは
root@3371f3750d51:/# azure vm capture -g TESTRESOURCEGROUP1 -n standalonevm -p standalonevm -t standalonevm.json
info: Executing command vm capture
+ Looking up the VM "standalonevm"
+ Capturing the virtual machine "standalonevm"
info: Saved template to file "standalonevm.json"
info: vm capture command OK