Azure云扩展根文件系统容量

问题描述

通过 Azure 平台部署的 Linux 虚拟机默认的根文件系统容量有限,需要进行扩展。

 

解决办法

使用Azure新门户(Azure portal)登陆:https://portal.azure.cn/  输入用户名密码

步骤如下(注意区分centos6和centos7):

  1.  Azure portal 机。
  2. 点击虚拟机的名称,选择“磁盘”,点击操作系统磁盘

 在“大小”处输入希望扩展的容量数字,点击保存,需要注意的是此操作必须在虚拟机关机的状态下进行

注:这一步需注意虚拟机类型,若类型是“虚拟机”,则可如上通过Portal进行操作,若类型是“虚拟机(经典)”,则是无法通过Portal进行操作的,需要使用PowerShell命令,命令如下

执行以下 Powershell 命令,对系统盘进行扩展:

Get-AzureVM -ServiceName "vfldev" -Name "vfldev" | get-AzureOSDisk ## 使用正确的 ServiceName 和 VM Name 取代上述参数。Update-AzureDisk –DiskName "vfldev-vfldev-0-201503091934500547" -Label "ResiZedOS" -ResizedSizeInGB 100## 用步骤一获取的 OSdisk 的名字取代上述的 DiskName,并输入想要扩容的磁盘大小。

 

如何安装和配置 Azure PowerShell:

 https://www.azure.cn/documentation/articles/powershell-install-configure

3.  通过 Azure portal 启动虚拟机。

4.  登陆虚拟机,切换成 root 用户,查看当前的虚拟机的根文件系统容量。

[root@resizeSDA chpaadmin]# df -hFilesystem      Size  Used Avail Use% Mounted on/dev/sda1        30G  1.1G   27G   4% /devtmpfs        832M     0  832M   0% /devtmpfs           840M     0  840M   0% /dev/shmtmpfs           840M  8.3M  832M   1% /runtmpfs           840M     0  840M   0% /sys/fs/cgroup/dev/sdb1        69G   53M   66G   1% /mnt/resource

5.   打开分区表(以下命令默认系统为centos6,centos7不同命令在旁边标注)

[root@resizeSDA chpaadmin]# fdisk /dev/sdaWelcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Command (m for help): pDisk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x00093e4e## 请记录分区信息Device Boot      Start         End      Blocks   Id  System/dev/sda1   *        2048    62914559    31456256   83  Linux## 删除分区Command (m for help): dSelected partition 1  (centos7 应选择2)Partition 1 is deleted## 新建分区Command (m for help): nPartition type:p   primary (0 primary, 0 extended, 4 free)e   extendedSelect (default p): p (以下均为默认配置)Partition number (1-4, default 1):First sector (2048-209715199, default 2048):Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):Using default value 209715199Partition 1 of type Linux and of size 100 GiB is set## 此时修改分区结束,打印分区信息,确认信息无误Command (m for help): pDisk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x00093e4e## 注意,这里的start的值,必须和此前的分区表里的信息一致Device Boot      Start         End      Blocks   Id  System/dev/sda1            2048   209715199   104856576   83  Linux## 激活分区Command (m for help): a   (centos7 无需这一步)Selected partition 1## 再次打印分区,确认已激活Command (m for help): pDisk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x00093e4eDevice Boot      Start         End      Blocks   Id  System/dev/sda1   *        2048   209715199   104856576   83  Linux## 如果信息有误,或者不确定,请及时联系我们,如果信息确认无误,写入分区表Command (m for help): wrThe 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 atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.

6.   分区表修改完毕,重启虚拟机。

[root@resizeSDA chpaadmin]# init 6

7.  登陆虚拟机,切换到 root 用户,检查当前根文件系统的容量。

[root@resizeSDA chpaadmin]# df -hFilesystem      Size  Used Avail Use% Mounted on/dev/sda1        30G  1.1G   27G   4% /devtmpfs        832M     0  832M   0% /devtmpfs           840M     0  840M   0% /dev/shmtmpfs           840M  8.3M  832M   1% /runtmpfs           840M     0  840M   0% /sys/fs/cgroup/dev/sdb1        69G   53M   66G   1% /mnt/resource

8.   修改根文件系统的大小。

[root@resizeSDA chpaadmin]# resize2fs /dev/sda1  (centos7 为xfs_growfs /dev/sda2)resize2fs 1.42.9 (28-Dec-2013)Filesystem at /dev/sda1 is mounted on /; on-line resizing requiredold_desc_blocks = 4, new_desc_blocks = 13The filesystem on /dev/sda1 is now 26214144 blocks long.

9.   检查根文件系统大小。

[root@resizeSDA chpaadmin]# df -hFilesystem      Size  Used Avail Use% Mounted on/dev/sda1        99G  1.1G   93G   2% /devtmpfs        832M     0  832M   0% /devtmpfs           840M     0  840M   0% /dev/shmtmpfs           840M  8.3M  832M   1% /runtmpfs           840M     0  840M   0% /sys/fs/cgroup/dev/sdb1        69G   53M   66G   1% /mnt/resource

10.   至此,根文件系统扩容完毕。

 

参考文档:

https://docs.azure.cn/zh-cn/articles/compute/aog-virtual-machines-qa-linux-root-file-system-extension

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值