我增加了 Ubuntu VM 中扩展分区和逻辑分区的大小,如下所述:将可用的未分区空间添加到 Ubuntu 主分区
现在我想将这些新扇区添加到我当前的文件系统。我的磁盘文件系统是(使用 可以看到df -h
):
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 396M 8.1M 388M 3% /run
/dev/mapper/vagrant--vg-root 38G 14G 23G 37% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 472M 48M 401M 11% /boot
vagrant 477G 399G 78G 84% /vagrant
shared_directory 477G 399G 78G 84% /shared_directory
tmpfs 396M 0 396M 0% /run/user/1000
为了利用这个空间,我需要增加大小的文件系统是 /dev/mapper/vagrant--vg-root
。
对应的设备是sda2和sda5
sudo fdisk /dev/sda <<< "p"
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 230195199 229193730 109.3G 5 Extended
/dev/sda5 1001472 230195199 229193728 109.3G 83 Linux
我尝试对这些使用 resize2fs,但没有效果:
vagrant@dsvm:~$ sudo resize2fs /dev/mapper/vagrant--vg-root
resize2fs 1.42.13 (17-May-2015)
The filesystem is already 10097664 (4k) blocks long. Nothing to do!
vagrant@dsvm:~$ sudo resize2fs /dev/mapper/vagrant--vg-root 26214400
resize2fs 1.42.13 (17-May-2015)
The containing partition (or device) is only 10097664 (4k) blocks.
You requested a new size of 26214400 blocks.
vagrant@dsvm:~$ sudo resize2fs /dev/sda2
resize2fs 1.42.13 (17-May-2015)
resize2fs: Attempt to read block from filesystem resulted in short read while trying to open /dev/sda2
Couldn't find valid filesystem superblock.
vagrant@dsvm:~$ sudo resize2fs /dev/sda5
resize2fs 1.42.13 (17-May-2015)
resize2fs: Device or resource busy while trying to open /dev/sda5
Couldn't find valid filesystem superblock.
我应该怎么做才能将这个空间合并到我的文件系统中?
根据评论中的要求,执行建议的操作后 pvdisplay 和 lvdisplay 的结果。
光伏显示器
--- Physical volume ---
PV Name /dev/sda5
VG Name vagrant-vg
PV Size 109.29 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 27977
Free PE 9861
Allocated PE 18116
PV UUID rsXeaK-LWoy-XJGD-ZfCK-BjFM-3zvn-nqMD14
lv显示器
--- Logical volume ---
LV Path /dev/vagrant-vg/root
LV Name root
VG Name vagrant-vg
LV UUID zkQ8lz-Ghpb-gCGi-WO5Y-m7Ga-JUeH-8hy5Ds
LV Write Access read/write
LV Creation host, time vagrant, 2017-10-27 20:31:10 +0000
LV Status available
# open 1
LV Size 69.77 GiB
Current LE 17860
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
答案1
由于分区大小已发生变化,您需要更新物理卷的大小:
pvresize /dev/sda5
这应该输出一个与分区大小大致相同的值。
然后,调整逻辑卷的大小:
lvresize -l +100%FREE /dev/mapper/vagrant--vg-root
如果文件系统未挂载,您应该进行完整的文件系统检查:(您可以跳过这一步)
e2fsck -f /dev/mapper/vagrant--vg-root
最后调整文件系统的大小:
resize2fs /dev/mapper/vagrant--vg-root