CentOS 7
我在虚拟服务器上运行HyperV
。我最近将硬盘大小从 32GB 增加到 64GB,并用于GParted Live
扩展分区,这似乎已经奏效,如下所示:
然而,检查时 Disk Usage Analyser
报告为 28.4GB:
在终端中,我运行df -h
并显示以下内容:
我已尝试过xfs_growfs /dev/mapper/centos-root -d
但是这说明data size unchanged, skipping
。
我对 Linux 相当不熟悉,在尝试寻找此问题的解决方案时,大多数屏幕截图都df -h
显示/dev/sda1
和/dev/sda2
。这里显示的额外内容是什么(几个 tmpfs 和 devtmpfs)以及如何让系统识别完整的磁盘空间?
答案1
你有一个文件系统在里面逻辑卷里面卷组涵盖了你的所有物理体积在你的现在——64GiB
块设备。
您通过 GParted 所做的就是扩展物理体积填补块设备,以及卷组自动填充物理卷,但你没有不是延长逻辑卷。
因此,文件系统无法增长,因为逻辑卷没有增长。
修复方法是使用几个命令。这个命令扩展了逻辑卷填补剩余的空间卷组:
lvextend -l 100%VG /dev/mapper/centos-root
这延伸了文件系统:
xfs_growfs /
完整示例
创建一个1GiB
块设备并将/dev/loop0
其扩展为2GiB
:
root@node54 [/tmp]# truncate -s 1G demo.img
root@node54 [/tmp]# losetup loop0 demo.img
root@node54 [/tmp]# lsblk /dev/loop0
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 1G 0 loop
在块设备上设置 LVM /dev/loop0
:
root@node54 [/tmp]# pvcreate /dev/loop0
Physical volume "/dev/loop0" successfully created
root@node54 [/tmp]# pvdisplay /dev/loop0
"/dev/loop0" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/loop0
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 0GC3Hx-pwqk-CsRV-UY8W-U2s0-3YOw-1pUUus
现在,一个卷组:
root@node54 [/tmp]# vgcreate PandyDemo /dev/loop0
Volume group "PandyDemo" successfully created
root@node54 [/tmp]# vgdisplay PandyDemo
--- Volume group ---
VG Name PandyDemo
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 1020.00 MiB
PE Size 4.00 MiB
Total PE 255
Alloc PE / Size 0 / 0
Free PE / Size 255 / 1020.00 MiB
VG UUID ybaz6R-iVnK-a0kZ-Zd39-DwS8-sln1-R9zmfz
现在,一个逻辑卷:
root@node54 [/tmp]# lvcreate -l 255 -n centos-root PandyDemo
Logical volume "centos-root" created
root@node54 [/tmp]# lvdisplay /dev/PandyDemo/centos-root
--- Logical volume ---
LV Path /dev/PandyDemo/centos-root
LV Name centos-root
VG Name PandyDemo
LV UUID RrhorY-JrIH-12Yu-nkEW-MSVb-YCin-o1XKbU
LV Write Access read/write
LV Creation host, time node54.deltik.org, 2016-02-10 02:56:46 -0600
LV Status available
# open 0
LV Size 1020.00 MiB
Current LE 255
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:3
为了简洁起见,我跳过了 XFS 文件系统的创建/dev/PandyDemo/centos-root
,但如果您愿意,现在就可以在那里创建一个 XFS 文件系统。
现在,关闭卷组和块设备,以便我们可以添加更多磁盘空间:
root@node54 [/tmp]# vgchange -an PandyDemo
0 logical volume(s) in volume group "PandyDemo" now active
root@node54 [/tmp]# losetup -d /dev/loop0
root@node54 [/tmp]# truncate -s 2G demo.img
再次设置块设备:
root@node54 [/tmp]# losetup loop0 demo.img
root@node54 [/tmp]# lsblk /dev/loop0
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 2G 0 loop
root@node54 [/tmp]# pvdisplay /dev/loop0
--- Physical volume ---
PV Name /dev/loop0
VG Name PandyDemo
PV Size 1.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 255
Free PE 0
Allocated PE 255
PV UUID 0GC3Hx-pwqk-CsRV-UY8W-U2s0-3YOw-1pUUus
将物理卷扩展到整个块设备,现在它已经2GiB
很大了。请注意,卷组也变2GiB
大了,但逻辑卷的大小仍然和我们创建时一样:
root@node54 [/tmp]# pvresize /dev/loop0
Physical volume "/dev/loop0" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
root@node54 [/tmp]# pvdisplay /dev/loop0
--- Physical volume ---
PV Name /dev/loop0
VG Name PandyDemo
PV Size 2.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 511
Free PE 256
Allocated PE 255
PV UUID 0GC3Hx-pwqk-CsRV-UY8W-U2s0-3YOw-1pUUus
root@node54 [/tmp]# vgdisplay PandyDemo
--- Volume group ---
VG Name PandyDemo
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 2.00 GiB
PE Size 4.00 MiB
Total PE 511
Alloc PE / Size 255 / 1020.00 MiB
Free PE / Size 256 / 1.00 GiB
VG UUID ybaz6R-iVnK-a0kZ-Zd39-DwS8-sln1-R9zmfz
root@node54 [/tmp]# lvdisplay /dev/PandyDemo/centos-root
--- Logical volume ---
LV Path /dev/PandyDemo/centos-root
LV Name centos-root
VG Name PandyDemo
LV UUID RrhorY-JrIH-12Yu-nkEW-MSVb-YCin-o1XKbU
LV Write Access read/write
LV Creation host, time node54.deltik.org, 2016-02-10 02:56:46 -0600
LV Status NOT available
LV Size 1020.00 MiB
Current LE 255
Segments 1
Allocation inherit
Read ahead sectors auto
将逻辑卷扩展为卷组大小的 100%:
root@node54 [/tmp]# lvextend -l 100%VG /dev/PandyDemo/centos-root
Size of logical volume PandyDemo/centos-root changed from 1020.00 MiB (255 extents) to 2.00 GiB (511 extents).
Logical volume centos-root successfully resized
root@node54 [/tmp]# lvdisplay /dev/PandyDemo/centos-root
--- Logical volume ---
LV Path /dev/PandyDemo/centos-root
LV Name centos-root
VG Name PandyDemo
LV UUID RrhorY-JrIH-12Yu-nkEW-MSVb-YCin-o1XKbU
LV Write Access read/write
LV Creation host, time node54.deltik.org, 2016-02-10 02:56:46 -0600
LV Status NOT available
LV Size 2.00 GiB
Current LE 511
Segments 1
Allocation inherit
Read ahead sectors auto
此时,您可以使用vgchange -ay PandyDemo
和重新激活 LVM lvchange -ay /dev/PandyDemo/centos-root
,然后,如果您已经创建了 XFS 文件系统,则可以在挂载它之后在线扩大其容量。
其他资源
如果你不使用 LVM,而只是使用 GPT 或 MSDOS 分区和 XFS,我有另一篇关于调整 XFS 文件系统大小的详细文章。