查詢磁碟分割
sudo lsblk
>>>輸出
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
└─sda1 8:1 0 10G 0 part /
分配容量
將剩下的空間都分配給 sda1
(注意,這裡 sda 與 1 之間有空格)
sudo growpart /dev/sda 1
>>>輸出
CHANGED: partition=1 start=2048 old: size=20969472 end=20971520 new: size=62908492,end=62910540
檢查容量
df -h
>>>輸出
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.6G 0 3.6G 0% /dev
tmpfs 3.6G 0 3.6G 0% /dev/shm
tmpfs 3.6G 369M 3.3G 11% /run
tmpfs 3.6G 0 3.6G 0% /sys/fs/cgroup
/dev/sda1 10G 8.1G 2.0G 81% /
tmpfs 732M 0 732M 0% /run/user/0
tmpfs 732M 0 732M 0% /run/user/1011
更新容量
將分配的容量正式套用在 sda1
(下方 sda 跟 1 之間沒有空格)
sudo resize2fs /dev/sda1
在 CentOS7 環境,預設 resize2fs 不能跟 XFS 一起使用
你可能會遇到以下錯誤訊息
resize2fs: Bad magic number in super-block while trying to open /dev/sda1Couldn’t find valid filesystem superblock.
解決方式,可以用 xfs_growfs替代 resize2fs
sudo xfs_growfs /dev/sda1
>>>輸出
meta-data=/dev/sda1 isize=512 agcount=4, agsize=655296 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=2621184, 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=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 2621184 to 7863552
檢查容量
df -h
>>> 輸出
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.6G 0 3.6G 0% /dev
tmpfs 3.6G 0 3.6G 0% /dev/shm
tmpfs 3.6G 369M 3.3G 11% /run
tmpfs 3.6G 0 3.6G 0% /sys/fs/cgroup
/dev/sda1 30G 8.1G 22G 27% /
tmpfs 732M 0 732M 0% /run/user/0
tmpfs 732M 0 732M 0% /run/user/1011