惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
A
About on SuperTechFans
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
U
Unit 42
WordPress大学
WordPress大学
Y
Y Combinator Blog
罗磊的独立博客
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
博客园 - 叶小钗
Stack Overflow Blog
Stack Overflow Blog
Engineering at Meta
Engineering at Meta
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
V
V2EX
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
SegmentFault 最新的问题
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 衡子

Ubuntu24.04更改SSH端口 记录安装过程 Azure CLI创建管理员用户 创建VMSS中的instance 创建不带公网IP的VM Azure LSv3系列VM 自动挂载NVMe本地磁盘 Azure AD访问Azure Storage Azure Linux VM使用Managed Identity获取Key-vault的Secret Azure AD SSO with Google Cloud Identity 通过API获取Azure KeyVault Securet Azure Front Door添加自定义域名 VM间网络PPS和带宽测试 Azure获取access token的方法 VM间记录时延 Windows Terminal的一些配置 安装hping Azure解除不再使用Directory的关联 使用VSCode Remote Containers功能实现开发环境统一 Azure AKS容器网络详解
通过VM SWAP OS DISK升级VM
衡子 · 2022-03-01 · via 博客园 - 衡子

Azure的VM提供交换OS Disk的方式,对VM进行升级、测试等。这里介绍如何通过Azure CLI实现此功能。

一 环境准备

1  创建两台VM

两台VM如下,分别安装Apache2和Nginx

VM01: Ubuntu21.01 + Apache2

VM02: Ubuntu21.01 + Nginx

2 获取VM的相关参数

获取VM Disk的名称:

vm01diskname=$( az vm list -g switchdisk --query "[?name=='vm01']" \
   | jq -r .[].storageProfile.osDisk.name)

vm02diskname=$( az vm list -g switchdisk --query "[?name=='vm02']" \
   | jq -r .[].storageProfile.osDisk.name)

3 创建VM02 Disk Snapshot 

通过下面的命令创建VM02 Disk的Snapshot:

az snapshot create -g switchdisk -n vm02-s2 --source $vm02diskname \
   --hyper-v-generation V2

4 通过Snapshot创建新的Disk

从snapshot创建disk:

az disk create -g switchdisk -n vm02disk04 --location westus2 --zone 1 \
   --source vm02-s2 --hyper-v-generation V2

获取diskid: 

diskid=$(az disk list --query "[?name=='vm02disk04']" | jq -r .[].id)

二 交换OS Disk 

通过下面的命令交换OS Disk:

az vm update -g switchdisk -n vm01 --os-disk $diskid

可以观察到,大约1分钟左右,VM的OS更换成新的disk:

 同样,在VM的console中可以看到VM重新启动,挂载新系统:

 

三 总结

通过更换VM OS Disk的方式,可以非常方便的升级VM的系统。