Azure Linux Partition Expand

最近在 Azure 上的 LAB 機上的 DB Partition一開始切太小 在倒正式區的 DB Backup時又加上了 binlog 遇到空間不足的問題,之前又不是切成LVM的Partiton 所以又不想做白工在搬資料, Study了一下在雲端的環境中加空間其實很方便

先確定 Partition

root@lab-My-DB1:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           796M   81M  715M  11% /run
/dev/sda1        29G  4.6G   25G  16% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda15      105M  3.6M  101M   4% /boot/efi
/dev/sdb1        16G   44M   15G   1% /mnt
tmpfs           796M     0  796M   0% /run/user/0
/dev/sdc1       512G  512G  856K 100% /var/lib/mysql
root@lab-My-DB1:~#

確定後要將 partition unmount 掉,Azure才給加,所以unmount掉, 如果有服務在用也要記得停掉服務

原來的 Partition 大小為512GB 自 Azure Console 加好空間後掛載上

root@lab-My-DB1:~# fdisk /dev/sdc -l
Disk /dev/sdc: 1 TiB, 1099511627776 bytes, 2147483648 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xbcb9e6ad

Device     Boot Start        End    Sectors  Size Id Type
/dev/sdc1        2048 1073741823 1073739776  512G 83 Linux
root@lab-My-DB1:~#

重點來了

# 用 growpart 去將 partition 擴大,可以加上 –dry-run  去檢查一下

root@lab-My-DB1:~# growpart --dry-run /dev/sdc 1
CHANGE: partition=1 start=2048 old: size=1073739776 end=1073741824 new: size=2147481567,end=2147483615
# === old sfdisk -d ===
label: dos
label-id: 0xbcb9e6ad
device: /dev/sdc
unit: sectors

/dev/sdc1 : start=        2048, size=  1073739776, type=83
# === new sfdisk -d ===
label: dos
label-id: 0xbcb9e6ad
device: /dev/sdc
unit: sectors

/dev/sdc1 : start=        2048, size=  2147481567, type=83
root@lab-My-DB1:~# growpart /dev/sdc 1
CHANGED: partition=1 start=2048 old: size=1073739776 end=1073741824 new: size=2147481567,end=2147483615
root@lab-My-DB1:~#

# 擴好 partition 後 再用 xfs growfs去將現用的 fs 去擴增

root@lab-My-DB1:~# xfs_growfs /var/lib/mysql
meta-data=/dev/sdc1              isize=512    agcount=4, agsize=33554368 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1 spinodes=0
data     =                       bsize=4096   blocks=134217472, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=65535, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 134217472 to 268435195
root@lab-My-DB1:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           796M   81M  715M  11% /run
/dev/sda1        29G  4.6G   25G  16% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda15      105M  3.6M  101M   4% /boot/efi
/dev/sdb1        16G   44M   15G   1% /mnt
tmpfs           796M     0  796M   0% /run/user/0
/dev/sdc1       1.0T  513G  512G  51% /var/lib/mysql
root@lab-My-DB1:~#

完成 & 收工

Author: jerryw1974

learning and focus on computer science, cloud infrastructure, virtualization and information security, technical, networking,platform system and cyber-security related topic.