LVM 扩展问题

LVM 扩展问题

我尝试扩展在 vmware 上运行的 Ubuntu 18.04 服务器的卷。LVM 正在使用中。我将其关闭,在 vmware 中扩展虚拟磁盘,然后启动它。然后我使用 cfdisk 将 40GB /dev/sda3 的大小调整为最大 199GB。一切顺利。

Output of cfdisk after reboot:    
/dev/sda1 = 1M
/dev/sda2 = 1G
/dev/sda3 = 199G

然后我运行 df -h

Filesystem                         Size  Used Avail Use% Mounted on
udev                               3.9G     0  3.9G   0% /dev
tmpfs                              798M  1.1M  797M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   39G  4.0G   33G  11% /
tmpfs                              3.9G     0  3.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/loop0                          90M   90M     0 100% /snap/core/8268
/dev/loop1                          92M   92M     0 100% /snap/core/8592
/dev/sda2                          976M  145M  765M  16% /boot
tmpfs                              798M     0  798M   0% /run/user/1000

我知道我需要扩展 /dev/mapper/ubuntu--vg-ubuntu--lv 所以我尝试了

resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.44.1 (24-Mar-2018)
The filesystem is already 10222592 (4k) blocks long.  Nothing to do!

vgdisplay 的输出

  --- Volume group ---
  VG Name               ubuntu-vg
  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               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <39.00 GiB
  PE Size               4.00 MiB
  Total PE              9983
  Alloc PE / Size       9983 / <39.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               TXiMWd-sKCj-2nJc-yEZY-ZudW-DMOh-G2qc6d

pvdisplay的输出

--- Physical volume ---
  PV Name               /dev/sda3
  VG Name               ubuntu-vg
  PV Size               <39.00 GiB / not usable 0   
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              9983
  Free PE               0
  Allocated PE          9983
  PV UUID               rmuSVO-uUCF-iKiA-0v8Q-IScl-zvHd-jfAzMn

我也试过

lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv                                                                                                                  
New size (9983 extents) matches existing size (9983 extents).

所以我的问题是,在 cfdisk 中,它显示 /sda3 是 199G。但是我不知道如何扩展

/dev/mapper/ubuntu--vg-ubuntu--lv   39G  4.0G   33G  11% /

填充 /sda3 上剩余的约 160GB 空间。

我将不胜感激任何指导。我在这里遵循的是“更快的方法”:增加安装 Ubuntu 的分区大小?

现在我似乎陷入困境。

我应该补充一下,我也尝试过这个,但它似乎不喜欢在已挂载的文件系统上使用它。

vgextend ubuntu-vg /dev/sda3
Can't open /dev/sda3 exclusively.  Mounted filesystem?

答案1

我得到了它! :)

我必须运行 pvresize 命令。我一运行

pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
root@xxxxx:~# pvdisplay                                                                                                                                                       
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               ubuntu-vg
  PV Size               <199.00 GiB / not usable 16.50 KiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              50943
  Free PE               40960
  Allocated PE          9983
  PV UUID               rmuSVO-uUCF-iKiA-0v8Q-IScl-zvHd-jfAzMn

root@xxxxx:~# lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv                                                                                                                  
  Size of logical volume ubuntu-vg/ubuntu-lv changed from <39.00 GiB (9983 extents) to <199.00 GiB (50943 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

一切看起来都很好,但 df -h 仍然显示:

Filesystem                         Size  Used Avail Use% Mounted on
udev                               3.9G     0  3.9G   0% /dev
tmpfs                              798M  1.1M  797M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   39G  4.0G   33G  11% /
tmpfs                              3.9G     0  3.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/loop0                          90M   90M     0 100% /snap/core/8268
/dev/loop1                          92M   92M     0 100% /snap/core/8592
/dev/sda2                          976M  145M  765M  16% /boot
tmpfs                              798M     0  798M   0% /run/user/1000

于是我就跑了

root@xxxxxx:~# resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 5, new_desc_blocks = 25
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 52165632 (4k) blocks long.

最后!

root@xxxxx:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               3.9G     0  3.9G   0% /dev
tmpfs                              798M  1.1M  797M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  196G  4.0G  184G   3% /
tmpfs                              3.9G     0  3.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/loop0                          90M   90M     0 100% /snap/core/8268
/dev/loop1                          92M   92M     0 100% /snap/core/8592
/dev/sda2                          976M  145M  765M  16% /boot
tmpfs                              798M     0  798M   0% /run/user/1000

希望这能帮助其他人。

相关内容