本文基於centos7進行磁盤擴容
1.查看原有磁盤大小
- 查看新的磁盤空間是否已經分配
fdisk -l //可以查看空間大小是否已經分配,分配後進行下一步
如果是虛擬機可以使用下圖方式進行擴容
- 對新空間進行分區
fdisk /dev/sda
輸入m ,可以查看幫助信息
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help):
增加新的分區
command (m for help):n
選擇基本信息分區,輸入:p
Command (m for help): n
Command action
e extended
p primary partition (1-4)
回車
First cylinder (1-15908,default 1):Enter
(這是回車是指分的默認大小)
寫入並退出
command (m for help):w
完成後,如果提示:
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)
就重啓一下系統識別該磁盤空間
- 爲新分配的空間創建一個新的物理卷
鍵入命令:pvcreate /dev/sda3
如果提示sda3找不到,鍵入:partprobe或者重啓虛擬機
- 查詢創建的物理卷
可以查到本機物理卷名稱爲“centos”
- 使用新增物理卷擴展本地物理卷
- 擴展 LVM 的邏輯卷 centos-root
鍵入命令:lvextend -L +1G 加上要擴展的分區名
lvextend -L +1G /dev/centos/root
- 調整邏輯卷的大小
此時系統還不認識剛剛添加進來的磁盤的文件系統,所以還需要對文件系統進行擴容。
鍵入:xfs_growfs 加上要擴展的分區名
或者
resize2fs – f 加 上要擴展的分區名
- 結束