删除创建失败的物理卷

删除创建失败的物理卷,第1张

如果LVM不再需要使用设备,则可以使用vgreduce命令从卷组中删除物理卷,vgreduce命令通过删除物理卷来缩小卷组的容量。参考vgreduce命令_Linux vgreduce命令使用详解:从卷组中删除物理卷。

如果仍在使用物理卷,则必须使用pvmove命令将数据传输到另一个物理卷。数据移动后,可以将其从卷组中删除。参考pvmove命令_Linux pvmove命令使用详解:搬移PV中的资料。

1、将范围移动到现有物理卷

使用pvs命令检查是否使用了所需的物理卷(我们计划在LVM中删除“/dev/sdb1”磁盘):

# pvs -o+pv_used

如果使用此选项,请检查该卷组中其他物理卷上是否有足够的自由范围。

如果是这样,可以在要删除的设备上运行pvmove命令,范围将分发到其他设备:

# pvmove /dev/sdb1

/dev/sdb1: Moved: 2.0%

/dev/sdb1: Moved: 79.2%

/dev/sdb1: Moved: 100.0%

pvmove命令完成时,重新使用pvs命令检查物理卷是否空闲:

# pvs -o+pv_used

请使用vgreduce命令从卷组中删除物理卷/dev/sdb1:

# vgreduce myvg /dev/sdb1

Removed "/dev/sdb1" from volume group "myvg"

最后,运行pvremove命令从LVM配置中删除磁盘。现在,该磁盘已从LVM中完全删除,并可用于其他目的:

# pvremove /dev/sdb1

Labels on physical volume "/dev/sdb1" successfully wiped.

2、将范围移动到新磁盘

如果您在卷组中的其他物理量上没有足够的自由范围,使用以下步骤添加新的物理卷。

向存储团队请求新的LUN,分配完这些后,运行以下命令以发现Linux中新添加的LUN或磁盘:

# ls /sys/class/scsi_host

host0

# echo "- - -" >/sys/class/scsi_host/host0/scan

# fdisk -l

在 *** 作系统中检测到磁盘后,请使用pvcreate命令创建物理卷:

# pvcreate /dev/sdd1

Physical volume "/dev/sdd1" successfully created

使用以下命令将新的物理卷/dev/sdd1添加到现有的卷组vg01:

# vgextend vg01 /dev/sdd1

Volume group "vg01" successfully extended

现在,使用pvs命令查看已添加的新磁盘“/dev/sdd1”:

# pvs -o+pv_used

使用pvmove命令将数据从/dev/sdb1移动到/dev/sdd1:

# pvmove /dev/sdb1 /dev/sdd1

/dev/sdb1: Moved: 10.0%

/dev/sdb1: Moved: 79.7%

/dev/sdb1: Moved: 100.0%

数据移至新磁盘后,重新使用pvs命令检查物理卷是否空闲:

# pvs -o+pv_used

请使用vgreduce命令从卷组中删除物理卷/dev/sdb1:

# vgreduce myvg /dev/sdb1

Removed "/dev/sdb1" from volume group "myvg"

最后,运行pvremove命令从LVM配置中删除磁盘。现在,该磁盘已从LVM中完全删除,并可用于其他目的:

# pvremove /dev/sdb1

Labels on physical volume "/dev/sdb1" successfully wip

一、由于硬盘或者分区的 *** 作方式其实都一样,所以就以分区为例。

二、/home分区2.6G,由如下pv组成:

/dev/sda5 100M

/dev/sda6 200M

/dev/sda7 300M

/dev/sda8 400M

/dev/sda9 500M

/dev/sda10 600M

/dev/sda11 500M

很碎对吧?^_^因为测试。

三、随机写了一堆文件进去,用量达到了2G,空闲500M

四、准备将sda6这个200M的PV卸掉(卸掉的容量必须小于空闲容量)

好了开始具体 *** 作了。

卸载分区(缩小 *** 作必须卸载才能进行):

umount /home

缩小分区:

e2fsck -f /dev/liuhg_disk/home

resize2fs /dev/liuhg_disk/home 2200M

首先将分区缩小到2200M这是为了给sda6腾出空间,sda6为200M,而我腾出了400M,因此应该是足够的。

缩小逻辑卷:

lvreduce -L 2200M /dev/liuhg_disk/home

分区缩小了用到的逻辑卷也要随着缩小,并查看PV使用的状态:

pvdisplay -m

显示如下:

--- Physical volume ---

PV Name /dev/sda5

VG Name liuhg_disk

PV Size 103.26 MiB / not usable 3.26 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 25

Free PE 0

Allocated PE 25

PV UUID 5lnx52-b4jc-OOfZ-f2QA-ttdQ-DZeD-Ce3rb3

--- Physical Segments ---

Physical extent 0 to 24:

Logical volume /dev/liuhg_disk/home

Logical extents 0 to 24

--- Physical volume ---

PV Name /dev/sda6

VG Name liuhg_disk

PV Size 203.92 MiB / not usable 3.92 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 50

Free PE 0 <-----太悲剧了,sda6里写满了数据一点不剩

Allocated PE 50 <-----这50PE的数据要挪走才行,否则数据就丢了,并且存放的地方也必须是连续的至少50PE

PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK

--- Physical Segments ---

Physical extent 0 to 49:

Logical volume /dev/liuhg_disk/home

Logical extents 25 to 74

--- Physical volume ---

PV Name /dev/sda7

VG Name liuhg_disk

PV Size 305.89 MiB / not usable 1.89 MiB

Allocatable yes

PE Size 4.00 MiB

Total PE 76

Free PE 76 <---这个分区有76个空余,因此预计装那50个是不会有问题的

Allocated PE 0

PV UUID 9CFnlx-CAEw-CSul-Rig9-FiCN-zK0a-oGmTEP

--- Physical Segments ---

Physical extent 0 to 75:

FREE

--- Physical volume ---

PV Name /dev/sda8

VG Name liuhg_disk

PV Size 407.87 MiB / not usable 3.87 MiB

Allocatable yes

PE Size 4.00 MiB

Total PE 101

Free PE 60

Allocated PE 41

PV UUID X0I8p0-x2xr-2xLG-QQD4-jbtS-3C4i-xPn4Bl

--- Physical Segments ---

Physical extent 0 to 40:

Logical volume /dev/liuhg_disk/home

Logical extents 471 to 511

Physical extent 41 to 100:

FREE

--- Physical volume ---

PV Name /dev/sda9

VG Name liuhg_disk

PV Size 509.84 MiB / not usable 1.84 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 127

Free PE 0

Allocated PE 127

PV UUID avJQaA-oMKt-NEoJ-ojBK-2Csc-1dca-1mh6Ue

--- Physical Segments ---

Physical extent 0 to 126:

Logical volume /dev/liuhg_disk/home

Logical extents 225 to 351

--- Physical volume ---

PV Name /dev/sda10

VG Name liuhg_disk

PV Size 603.98 MiB / not usable 3.98 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 150

Free PE 0

Allocated PE 150

PV UUID JlMIAF-A49n-M6HA-ZLXf-d8nS-pfZr-YeQsKT

--- Physical Segments ---

Physical extent 0 to 149:

Logical volume /dev/liuhg_disk/home

Logical extents 75 to 224

--- Physical volume ---

PV Name /dev/sda11

VG Name liuhg_disk

PV Size 478.47 MiB / not usable 2.47 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 119

Free PE 0

Allocated PE 119

PV UUID xnHJNA-tDVx-dryX-KM1x-g96Y-sptI-9iUOcU

--- Physical Segments ---

Physical extent 0 to 118:

Logical volume /dev/liuhg_disk/home

Logical extents 352 to 470

将sda6设置为离线状态:

pvchange -xn /dev/sda6

使用pvdisplay -m

显示如下:

??

--- Physical volume ---

PV Name /dev/sda6

VG Name liuhg_disk

PV Size 203.92 MiB / not usable 3.92 MiB

Allocatable NO <-----表示已经关闭了该PV

PE Size 4.00 MiB

Total PE 50

Free PE 0

Allocated PE 50

PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK

??

将sda6的数据移走:

pvmove -i 1 /dev/sda6

-i 1是每1秒钟报告一次数据迁移的进度。

[root@liuhg /]# pvmove -i 1 /dev/sda6

/dev/sda6: Moved: 38.0%

/dev/sda6: Moved: 84.0%

/dev/sda6: Moved: 100.0%

重新用pvdisplay -m

显示如下:

??

--- Physical volume ---

PV Name /dev/sda6

VG Name liuhg_disk

PV Size 203.92 MiB / not usable 3.92 MiB

Allocatable NO

PE Size 4.00 MiB

Total PE 50

Free PE 50 <----显示完全空闲和Total PE数一致

Allocated PE 0

PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK

??

从卷组里把sda6删除:

[root@liuhg /]# vgreduce liuhg_disk /dev/sda6

Removed "/dev/sda6" from volume group "liuhg_disk"

pvdisplay -m再看看吧:

--- NEW Physical volume --- <-----还告诉你这是一个新的PV ^_^

PV Name /dev/sda6

VG Name <-----空了

PV Size 203.92 MiB

Allocatable NO

PE Size 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK

到此vgdisplay -v能看到已经没有了/dev/sda6了。重新挂载/home

[root@liuhg /]# mount /dev/liuhg_disk/home /home

[root@liuhg /]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda1 2.0G 546M 1.3G 30% /

tmpfs 504M 0 504M 0% /dev/shm

/dev/mapper/liuhg_disk-home

2.2G 1.8G 42M 98% /home

进去看看数据,一个都没丢。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8665619.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-19
下一篇 2023-04-19

发表评论

登录后才能评论

评论列表(0条)

保存