在以下情况下如何扩展卷?
看起来有足够的空间sda2
,但我不知道如何让卷centos-root
使用它。
#> parted /dev/sda print free
Disk /dev/sda: 537GB
Number Start End Size Type File system Flags
32,3kB 1049kB 1016kB Free Space
1 1049kB 525MB 524MB primary xfs boot
2 525MB 537GB 536GB primary lvm
537GB 537GB 16,9kB Free Space
#> lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 500G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 499,5G 0 part
├─centos-root 253:0 0 8,5G 0 lvm /
└─centos-swap 253:1 0 1G 0 lvm [SWAP]
到目前为止我已经尝试过:
resize2fs
lvextend
但是我收到以下错误:
#> resize2fs -P /dev/sda2
resize2fs: Device or resource busy while trying to open /dev/sda2
Couldn't find valid filesystem superblock.
#> lvextend -l 100%FREE /dev/mapper/centos-root
New size given (10 extents) not larger than existing size (2168 extents)
更新
经过进一步的实验,我发现我错过了运行pvresize
,然后我也可以lvextend
成功运行:
#> pvresize /dev/sda2
Physical volume "/dev/sda2" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
#> lvextend -l 100%FREE /dev/mapper/centos-root
Size of logical volume centos/root changed from <9,47 GiB (2424 extents) to <489,04 GiB (125194 extents).
Logical volume centos/root successfully resized.
现在输出lsblk
看起来好多了:
#> lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 500G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 499,5G 0 part
├─centos-root 253:0 0 489G 0 lvm /
└─centos-swap 253:1 0 1G 0 lvm [SWAP]
仍然df -h
向我展示旧尺寸和scsi 重新扫描手册没有帮助,也没有官方工具。
#> df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7,8G 0 7,8G 0% /dev
tmpfs 7,8G 0 7,8G 0% /dev/shm
tmpfs 7,8G 17M 7,8G 1% /run
tmpfs 7,8G 0 7,8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 8,5G 2,5G 6,1G 30% /
/dev/sda1 497M 151M 347M 31% /boot
tmpfs 1,6G 0 1,6G 0% /run/user/0
tmpfs 1,6G 0 1,6G 0% /run/user/1013
该怎么办?
答案1
最后,缺少的步骤是应用lvresize
:
#> lvresize --extents +100%FREE --resizefs /dev/mapper/centos-root
Size of logical volume centos/root changed from <489,04 GiB (125194 extents) to <498,51 GiB (127618 extents).
Logical volume centos/root successfully resized.
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=555008 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0 spinodes=0
data = bsize=4096 blocks=2220032, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
df -h
确认了所需的结果。耶!如果有更直接的方法执行此操作,很高兴看到其他答案。
#> df -Ph /dev/mapper/centos-root
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 499G 2,3G 497G 1% /