如何增加Azure VM的硬盘大小

问题描述:

我正在使用类型为RHEL OS类型的Azure VM。目前我正在使用Standard D3 v2大小的VM。我在虚拟机中只能看到32个硬盘存储。如何增加硬盘的大小?如何增加Azure VM的硬盘大小

Filesystem  Size Used Avail Use% Mounted on 
/dev/sda2  32G 32G 185M 100%/
devtmpfs  6.9G  0 6.9G 0% /dev 
tmpfs   6.9G  0 6.9G 0% /dev/shm 
tmpfs   6.9G 8.4M 6.9G 1% /run 
tmpfs   6.9G  0 6.9G 0% /sys/fs/cgroup 
/dev/sda1  497M 117M 381M 24% /boot 
/dev/sdb1  197G 2.1G 185G 2% /mnt/resource 
tmpfs   1.4G  0 1.4G 0% /run/user/1000 

注意:我正在使用非托管磁盘。

检查你的操作系统磁盘如果您的虚拟机使用Azure的资源管理器(ARM),你可以调整操作系统的磁盘或内的数据磁盘创建新的Azure门户。

  1. 导航到您要调整磁盘大小的Azure资源管理器虚拟机。
  2. 从Azure门户关闭虚拟机。等到它完全关闭(取消分配)。
  3. 在“设置”选项卡中选择“磁盘”(如下图所示)。

Disks settings blade

  1. 选择OS或数据磁盘,你想以调整大小。
  2. 在新刀片上,输入新的磁盘大小(每个磁盘最大1023GB或1TB)(如下图所示)。
  3. Change disk size

    1. 点击“保存”在上面。
    2. 再次启动虚拟机。
    3. 就是这样!您可以登录到VM并检查是否有新的选定磁盘大小。

    开始=>
开始=>
+0

是的。我测试了它的操作系统盘。其作品。 – karan

所以基本上按照这篇文章:https://docs.microsoft.com/en-us/azure/virtual-machines/linux/expand-disks

az vm deallocate --resource-group myResourceGroup --name myVM 
az disk list \ 
    --resource-group myResourceGroup \ 
    --query '[*].{Name:name,Gb:diskSizeGb,Tier:accountType}' \ 
    --output table 
az disk update \ 
    --resource-group myResourceGroup \ 
    --name myDataDisk \ 
    --size-gb 200 
az vm start --resource-group myResourceGroup --name myVM 

非托管磁盘:
https://blogs.msdn.microsoft.com/cloud_solution_architect/2016/05/24/step-by-step-how-to-resize-a-linux-vm-os-disk-in-azure-arm/

+0

我正在使用非托管磁盘。我执行此命令时看到一个空的结果 - 磁盘列表--resource-group testresourcegroup1 --query'[*]。{Name:name,Gb:diskSizeGb,Tier:accountType}' - 输出表 – karan

+0

检查链接我已添加@karan – 4c74356b41

+0

我正在使用非托管磁盘。请参考我更新的问题。上述链接对我有用吗? – karan

根据你的描述,我在我的实验室测试,我测试的Red Hat Enterprise Linux Server release 7.3 (Maipo)

注意:当你没有它时,我强烈建议你可以备份你的OS VHD。如果 确实失败,则无法启动虚拟机。

1.在Azure Portal上停止虚拟机。

2.使用Azure CLI增加操作系统磁盘。

az vm update -g shui -n shui --set storageProfile.osDisk.diskSizeGB=100 

3.启动您的VM和ssh到您的虚拟机。您可以检查df -hfdisk -l/dev/sda2不会增加到100GB。您需要按照以下命令进行操作。

sudo -i 

[[email protected] ~]# fdisk /dev/sda 

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to 
     switch off the mode (command 'c') and change display units to 
     sectors (command 'u'). 

Command (m for help): p 

Disk /dev/sda: 53.7 GB, 53687091200 bytes 
255 heads, 63 sectors/track, 6527 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 
Sector size (logical/physical): 512 bytes/512 bytes 
I/O size (minimum/optimal): 512 bytes/512 bytes 
Disk identifier: 0x0001461e 

    Device Boot  Start   End  Blocks Id System 
/dev/sda1 *   1   64  512000 83 Linux 
Partition 1 does not end on cylinder boundary. 
/dev/sda2    64  3917 30944256 83 Linux 

Command (m for help): u 
Changing display/entry units to sectors 

Command (m for help): p 

Disk /dev/sda: 53.7 GB, 53687091200 bytes 
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors 
Units = sectors of 1 * 512 = 512 bytes 
Sector size (logical/physical): 512 bytes/512 bytes 
I/O size (minimum/optimal): 512 bytes/512 bytes 
Disk identifier: 0x0001461e 

    Device Boot  Start   End  Blocks Id System 
/dev/sda1 *  2048  1026047  512000 83 Linux 
Partition 1 does not end on cylinder boundary. 
/dev/sda2   1026048 62914559 30944256 83 Linux 

Command (m for help): d 
Partition number (1-4): 1 

Command (m for help): n 
Command action 
    e extended 
    p primary partition (1-4) 
p 
Partition number (1-4): 1 
First sector (63-104857599, default 63): 64 
Last sector, +sectors or +size{K,M,G} (64-1026047, default 1026047): 
Using default value 1026047 

Command (m for help): p 

Disk /dev/sda: 53.7 GB, 53687091200 bytes 
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors 
Units = sectors of 1 * 512 = 512 bytes 
Sector size (logical/physical): 512 bytes/512 bytes 
I/O size (minimum/optimal): 512 bytes/512 bytes 
Disk identifier: 0x0001461e 

    Device Boot  Start   End  Blocks Id System 
/dev/sda1    64  1026047  512992 83 Linux 
Partition 1 does not end on cylinder boundary. 
/dev/sda2   1026048 62914559 30944256 83 Linux 

Command (m for help): wq 
The partition table has been altered! 

Calling ioctl() to re-read partition table. 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy. 
The kernel still uses the old table. The new table will be used at 
the next reboot or after you run partprobe(8) or kpartx(8) 
Syncing disks. 
[[email protected] ~]# fdisk -l /dev/sda 

Disk /dev/sda: 53.7 GB, 53687091200 bytes 
255 heads, 63 sectors/track, 6527 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 
Sector size (logical/physical): 512 bytes/512 bytes 
I/O size (minimum/optimal): 512 bytes/512 bytes 
Disk identifier: 0x0001461e 

    Device Boot  Start   End  Blocks Id System 
/dev/sda1    1   64  512992 83 Linux 
Partition 1 does not end on cylinder boundary. 
/dev/sda2    64  3917 30944256 83 Linux 

4.重新启动你的VM

5.SSH你的VM和调整文件系统。现在

xfs_growfs -d /dev/sda2 

,你可以用df -h

[[email protected] ~]# df -h 
Filesystem  Size Used Avail Use% Mounted on 
/dev/sda2  100G 1.7G 98G 2%/