Managed Diskでのディスクサイズ変更


Managed Diskの容量を増やす際、Azure Portal画面上でサイズ変更自体は出来るものの、LinuxなVMではCLIで追加操作を行う必要がある。


AzureポータルとCloud Shellでやること

Azure Portal画面でディスクサイズを変更した後にAzure CLIでログイン(az login)した上で、VMを割当て解除(stopではなく、deallocate)にする。

$ az vm deallocate --resource-group kochi-moodle-RG --name Moodle-AP

次に、リソースグループ内のManaged Disk一覧を表示させる。

$ az disk list \
    --resource-group kochi-moodle-RG \
    --query '[*].{Name:name,Gb:diskSizeGb,Tier:accountType}' \
    --output table


$ az disk update \
    --resource-group kochi-moodle-RG \
    --name Moodle-AP_OsDisk_1_76bc9dcb7b764824ae799773ff955467 \
    --size-gb 500



[shinonome@test ~]$ lsblk
fd0      2:0    1    4K  0 disk 
sda      8:0    0  500G  0 disk 
├─sda1   8:1    0  500M  0 part /boot
└─sda2   8:2    0 29.5G  0 part /
sdb      8:16   0    8G  0 disk 
└─sdb1   8:17   0    8G  0 part /mnt/resource
[shinonome@test ~]$ sudo fdisk /dev/sda

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
Welcome 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): d
Partition number (1,2, default 2): 2
Partition 2 is deleted

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (1026048-1048575999, default 1026048): 
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-1048575999, default 1048575999): 
Using default value 1048575999
Partition 2 of type Linux and of size 499.5 GiB is set

Command (m for help): w
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.

ここで一度、VMを再起動させ、 次にルートパーティションを拡張させる。

[shinonome@test ~]$ sudo xfs_growfs /dev/sda2
meta-data=/dev/sda2              isize=512    agcount=4, agsize=1934016 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=7736064, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=3777, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 7736064 to 130943744


[shinonome@test ~]$ df -h
Filesystem                                         Size  Used Avail Use% Mounted on
/dev/sda2                                          500G  4.4G  496G   1% /
devtmpfs                                           2.0G     0  2.0G   0% /dev
tmpfs                                              2.0G     0  2.0G   0% /dev/shm
tmpfs                                              2.0G  9.0M  2.0G   1% /run
tmpfs                                              2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda1                                          497M  106M  392M  22% /boot
//  5.0T   73M  5.0T   1% /mnt/disk
/dev/sdb1                                          7.8G   36M  7.3G   1% /mnt/resource
tmpfs                                              394M     0  394M   0% /run/user/1000