AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 650324
Accepted
user2363318
user2363318
Asked: 2014-12-10 09:20:35 +0800 CST2014-12-10 09:20:35 +0800 CST 2014-12-10 09:20:35 +0800 CST

没有分区表的磁盘上的 LVM。如何使用 fdisk 重新分配可用空间?

  • 772

我使用以下命令将 LVM 缩小了一半:

e2fsck -f /dev/VG/LV
resize2fs /dev/VG/LV 5G
lvreduce -L 5G /dev/VG/LV

检查物理卷会产生以下结果:

  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               VG
  PV Size               10.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              2559
  Free PE               1279
  Allocated PE          1280

如何通过 fdisk 将空闲 PE(从哪个柱面开始)分配为标准分区?

centos6
  • 1 1 个回答
  • 1240 Views

1 个回答

  • Voted
  1. Best Answer
    blubberdiblub
    2014-12-15T09:55:54+08:002014-12-15T09:55:54+08:00

    如果您已将 PV 创建为分区,则必须先使用 缩小 PV ,然后使用或pvresize --setphysicalvolumesize 5124M /dev/sdb等工具调整分区表中的分区大小。fdiskparted

    但是在您的情况下,您无法在那里创建新分区,因为 PV 包含整个驱动器,因此您无法在不破坏 PV 的情况下安全地创建新的分区表。好吧,实际上你可以通过直接操作分区表,但这很危险,并且会回来并进一步咬你。

    相反,最安全的方法是在不同的驱动器上创建另一个 PV,将其添加到卷组,将 LV 移动到另一个 PV,从 VG 中删除第一个 PV,从 /dev/sdb 中删除第一个 PV,创建分区在 /dev/sdb 上,在其中一个分区上创建一个 PV,将 PV 添加到 VG,将 LV 移动到这个现在正确的 PV,最后从 VG 中删除临时 PV。

    像这样:(请注意,您必须确保使用适用于您的特定配置的设备名称,而不仅仅是复制和粘贴。/dev/sdc这只是一个示例,对您来说可能会有所不同):

    # plug in external USB drive
    
    dmesg | tail                     # Check which device name the plugged in drive got.
    lsblk                            # another way to verify, assuming `lsblk` is installed
    cat /proc/partitions             # one more way to verify, sizes are in KiB
    
    fdisk /dev/sdc                   # Make at least one partition on the drive, minimum of 5124 MiB.
    
    pvcreate /dev/sdc1               # create the Physical Volume (PV)
    vgextend VG /dev/sdc1            # add the PV to the Volume Group (VG)
    
    pvmove -i 5 /dev/sdb /dev/sdc1   # Try to move every Logical Volume (LV) on PV /dev/sdb over to PV /dev/sdc1.
                                     # There's no need to unmount anything, the process is completely transparent
                                     # to the LV and anything using it. You may want to make a tea or two ;)
                                     # Watch out for errors regarding insufficient space on the target PV, tho.
    
    vgreduce VG /dev/sdb             # Remove the old PV from the VG.
    pvremove /dev/sdb                # Wipe the PV metadata from the drive. Don't continue in case of errors here!
    
    fdisk /dev/sdb                   # Properly partition the drive. Partition for PV should be 5124 MiB minimum.
    
    pvcreate /dev/sdb1               # Create a PV on the just created partition.
    vgextend VG /dev/sdb1            # Add PV to the VG.
    
    pvmove -i 5 /dev/sdc1 /dev/sdb1  # Move LVs back from the temporary PV to the freshly partitioned one.
    
    vgreduce VG /dev/sdc1            # Remove temporary PV from the VG.
    pvremove /dev/sdc1               # Wipe PV metadata from the drive.
    

    在尝试此操作之前进行备份。

    如果按照此处所示使用,给定的pv*和命令是安全的。vg*如果不满足先决条件,他们将拒绝工作,或者会询问您是否仍要这样做(n在这种情况下回答)。特别是,当您将 LV 缩小到恰好 5 GiB 时,您将需要一个略大于 5120 MiB 的分区(我建议添加 4 MiB,因此 5124 MiB),以便 PV 能够容纳元数据,它会抱怨如果不是这样的话。

    但是,fdisk这并不安全,即使它会覆盖您的宝贵数据,它也会很乐意继续执行您的指令,因此请格外小心。

    • 4

相关问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve