xfs文件系統無損擴容

雲環境中,經常面臨數據盤需要擴容的情況。演示系統爲 CentOS 7.0,無損擴容數據盤文件系統大小(XFS)/dev/vdc1從10G擴展到30G。

以防萬一,操作前請做好重要數據備份

  1. 查看磁盤掛載、分區信息
root@BJ-CentOS7 ~ # df -hT | grep vdc
/dev/vdc1      xfs        10G   33M   10G    1% /vdc1
root@BJ-CentOS7 ~ # 
root@BJ-CentOS7 ~ # lsblk  /dev/vdc
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vdc    253:32   0  30G  0 disk 
└─vdc1 253:33   0  10G  0 part /vdc1
  1. 進行分區擴容(等同分區重建,注意扇區起始位置不要錯誤)
root@BJ-CentOS7 ~ # umount /dev/vdc1
root@BJ-CentOS7 ~ # 
root@BJ-CentOS7 ~ # fdisk /dev/vdc 
歡迎使用 fdisk (util-linux 2.23.2)。
更改將停留在內存中,直到您決定將更改寫入磁盤。
使用寫入命令前請三思。
命令(輸入 m 獲取幫助):p
磁盤 /dev/vdc:32.2 GB, 32212254720 字節,62914560 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標籤類型:dos
磁盤標識符:0x2ebd63d4
   設備 Boot      Start         End      Blocks   Id  System
/dev/vdc1            2048    20973567    10485760   83  Linux
命令(輸入 m 獲取幫助):d
已選擇分區 1
分區 1 已刪除
命令(輸入 m 獲取幫助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分區號 (1-4,默認 1):1
起始 扇區 (2048-62914559,默認爲 2048):
將使用默認值 2048
Last 扇區, +扇區 or +size{K,M,G} (2048-62914559,默認爲 62914559):
將使用默認值 62914559
分區 1 已設置爲 Linux 類型,大小設爲 30 GiB
命令(輸入 m 獲取幫助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 設備或資源忙.
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)
正在同步磁盤。
root@BJ-CentOS7 ~ # 
root@BJ-CentOS7 ~ # partprobe
  1. 文件系統擴容(注意分區擴容完成後需要執行 partprobe 命令)

partprobe 命令用於重讀分區表,告訴內核分區表有變更,不然使用 xfs_growfs 命令擴容文件系統時可能會出現擴容無效情況

xfs_growfs 命令執行需要分區是掛載狀態,不然會報錯

root@BJ-CentOS7 ~ # xfs_growfs /dev/vdc1 
xfs_growfs: /dev/vdc1 is not a mounted XFS filesystem
root@BJ-CentOS7 ~ # 
root@BJ-CentOS7 ~ # mount /dev/vdc1 /vdc1
root@BJ-CentOS7 ~ # 
root@BJ-CentOS7 ~ # xfs_growfs /dev/vdc1 
meta-data=/dev/vdc1              isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=2621440, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 2621440 to 7864064
root@BJ-CentOS7 ~ # 
root@BJ-CentOS7 ~ # df -hT | grep vdc
/dev/vdc1      xfs        30G   33M   30G    1% /vdc1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章