如何从lvm分区中删除磁盘?

Mar*_*ith 8 linux lvm hard-disk volume

有人可以帮忙吗?我有 2 个磁盘跨越我的主分区。一个是 460Gb,另一个是 1TB。我想删除 1TB - 我想在另一台机器上使用它。

\n\n

无论如何,卷组不会使用大量空间,我只有 docker 和一些使用该磁盘的容器,而且我的 docker 容器卷无论如何都位于不同的物理磁盘上。

\n\n

如果我只是删除磁盘([物理]),它会导致问题,对吧?

\n\n

这是一些信息

\n\n
\npvdisplay\n\n\n  --- Physical volume ---\n  PV Name               /dev/sda3\n  VG Name               ubuntu-vg\n  PV Size               <464.26 GiB / not usable 2.00 MiB\n  Allocatable           yes (but full)\n  PE Size               4.00 MiB\n  Total PE              118850\n  Free PE               0\n  Allocated PE          118850\n  PV UUID               DA7Q8E-zJEz-2FzO-N64t-HtU3-2Z8P-UQydU4\n\n  --- Physical volume ---\n  PV Name               /dev/sdb1\n  VG Name               ubuntu-vg\n  PV Size               931.51 GiB / not usable 4.69 MiB\n  Allocatable           yes (but full)\n  PE Size               4.00 MiB\n  Total PE              238466\n  Free PE               0\n  Allocated PE          238466\n  PV UUID               Sp6b1v-nOj2-XXdb-GZYf-1Vej-cfdr-qLB3GU\n
Run Code Online (Sandbox Code Playgroud)\n\n

LVM 让我有点困惑:-)

\n\n

难道不只是一个简单的例子,

\n\n

“将自己从 VG 中删除,并评估您正在使用剩余组成员的任何内容”?

\n\n

值得注意的是,1TB 是后来添加的,所以假设它更容易删除?

\n\n

任何帮助真的很感激

\n\n

编辑

\n\n

还有一些更多信息

\n\n
df -h\nFilesystem                         Size  Used Avail Use% Mounted on\nudev                                16G     0   16G   0% /dev\ntmpfs                              3.2G  1.4M  3.2G   1% /run\n/dev/mapper/ubuntu--vg-ubuntu--lv  1.4T  5.1G  1.3T   1% /\n
Run Code Online (Sandbox Code Playgroud)\n\n

同样只使用 1%

\n\n

还输出lvs

\n\n
lvs\n  LV        VG        Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert\n  ubuntu-lv ubuntu-vg -wi-ao---- 1.36t\n
Run Code Online (Sandbox Code Playgroud)\n\n

编辑

\n\n
pvdisplay -m\n  --- Physical volume ---\n  PV Name               /dev/sda3\n  VG Name               ubuntu-vg\n  PV Size               <464.26 GiB / not usable 2.00 MiB\n  Allocatable           yes (but full)\n  PE Size               4.00 MiB\n  Total PE              118850\n  Free PE               0\n  Allocated PE          118850\n  PV UUID               DA7Q8E-zJEz-2FzO-N64t-HtU3-2Z8P-UQydU4\n\n  --- Physical Segments ---\n  Physical extent 0 to 118849:\n    Logical volume  /dev/ubuntu-vg/ubuntu-lv\n    Logical extents 0 to 118849\n\n  --- Physical volume ---\n  PV Name               /dev/sdb1\n  VG Name               ubuntu-vg\n  PV Size               931.51 GiB / not usable 4.69 MiB\n  Allocatable           NO\n  PE Size               4.00 MiB\n  Total PE              238466\n  Free PE               0\n  Allocated PE          238466\n  PV UUID               Sp6b1v-nOj2-XXdb-GZYf-1Vej-cfdr-qLB3GU\n\n  --- Physical Segments ---\n  Physical extent 0 to 238465:\n    Logical volume  /dev/ubuntu-vg/ubuntu-lv\n    Logical extents 118850 to 357315\n
Run Code Online (Sandbox Code Playgroud)\n\n

编辑

\n\n

输出

\n\n
lsblk -f\nNAME   FSTYPE     LABEL UUID                                   MOUNTPOINT\nloop0  squashfs                                                /snap/core/9066\nloop2  squashfs                                                /snap/core/9289\nsda\n\xe2\x94\x9c\xe2\x94\x80sda1 vfat             E6CC-2695                              /boot/efi\n\xe2\x94\x9c\xe2\x94\x80sda2 ext4             0909ad53-d6a7-48c7-b998-ac36c8f629b7   /boot\n\xe2\x94\x94\xe2\x94\x80sda3 LVM2_membe       DA7Q8E-zJEz-2FzO-N64t-HtU3-2Z8P-UQydU4\n  \xe2\x94\x94\xe2\x94\x80ubuntu--vg-ubuntu--lv\n       ext4             b64f2bf4-cd6c-4c21-9009-76faa2627a6b   /\nsdb\n\xe2\x94\x94\xe2\x94\x80sdb1 LVM2_membe       Sp6b1v-nOj2-XXdb-GZYf-1Vej-cfdr-qLB3GU\n  \xe2\x94\x94\xe2\x94\x80ubuntu--vg-ubuntu--lv\n       ext4             b64f2bf4-cd6c-4c21-9009-76faa2627a6b   /\nsdc    xfs              1a9d0e4e-5cec-49f3-9634-37021f65da38   /gluster/bricks/2\n\n
Run Code Online (Sandbox Code Playgroud)\n\n

上面的 sdc 是不同的驱动器 - 并且不相关。

\n

tel*_*coM 10

Since the filesystem you'll need the disk removed from is your root filesystem, and the filesystem type is ext4, you'll have to boot the system from some live Linux boot media first. Ubuntu Live would probably work just fine for this.

Once booted from the external media, run sudo vgchange -ay ubuntu-vg to activate the volume group so that you'll be able to access the LVs, but don't mount the filesystem: ext2/3/4 filesystems need to be unmounted for shrinking. Then shrink the filesystem to 10G (or whatever size you wish - it can easily be extended again later, even on-line):

sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv 10G
Run Code Online (Sandbox Code Playgroud)

Pay attention to the messages output by resize2fs - if it says the filesystem cannot be shrunk that far, specify a bigger size and try again.

This is the only step that needs to be done while booted on the external media; for everything after this point, you can boot the system normally.

At this point, the filesystem should have been shrunk to 10G (or whatever size you specified). The next step is to shrink the LV. It is vitally important that the new size of the LV should be exactly the same or greater than the new size of the filesystem! You don't want to cut off the tail end of the filesystem when shrinking the LV. It's safest to specify a slightly bigger size here:

sudo lvreduce -L 15G /dev/mapper/ubuntu--vg-ubuntu--lv
Run Code Online (Sandbox Code Playgroud)

Now, use pvdisplay or pvs to see if LVM now considers /dev/sdb1 totally free or not. In pvdisplay, the Total PE and Free PE values for sdb1 should be equal - in pvs output, the PFree value should equal PSize respectively. If this is not the case, then it will be time to use pvmove:

sudo pvmove /dev/sdb1
Run Code Online (Sandbox Code Playgroud)

After this, the sdb1 PV should definitely be totally free according to LVM and it can be reduced out of the VG.

sudo vgreduce vg-ubuntu /dev/sdb1
Run Code Online (Sandbox Code Playgroud)

If you wish, you can then remove the LVM signature from the ex-PV:

sudo pvremove /dev/sdb1
Run Code Online (Sandbox Code Playgroud)

But if you are going to overwrite it anyway, you can omit this step.

After these steps, the shrunken filesystem will still be sized at 10G (or whatever you specified) even though the LV might be somewhat bigger than that. To fix that:

sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
Run Code Online (Sandbox Code Playgroud)

扩展文件系统时,您不必指定大小:该工具将自动扩展文件系统以匹配包含它的最内部设备的确切大小。在这种情况下,文件系统的大小将根据 LV 的大小进行调整。

稍后,如果您想扩展 LV+文件系统,只需两个命令即可完成:

sudo lvextend -L <new size> /dev/mapper/ubuntu--vg-ubuntu--lv
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
Run Code Online (Sandbox Code Playgroud)

即使文件系统正在使用和挂载,您也可以执行此操作。由于缩小文件系统比扩展文件系统更困难,因此在 LVM 级别保留一定量的未分配空间可能会很有用 - 您将能够立即使用它来创建新的 LV 和/或扩展现有的 LV根据需要在同一 VG 中。