Linux LVM安全删除硬盘或分区-
转载:http://blog.51yip.com/linux/1779.html
背景:
由于误操作,把三块盘LVM在一起了。挺尴尬的,都安装了系统了。然后由于某种原因,不方便重新安装。所以就想着把多余的两个磁盘踢出来。。
描述:
LVM总共700G,其中sda系统盘,sdb 536G,sdc 214G,实际数据使用空间164G,想要缩减空间做删除盘的操作。
-从根目录删除盘 (根目录被使用所以要进入安全模式)
其他路径的话,在保证数据安全时可以直接迁移数据,移除操作。
1、查看分区情况
[sql] view plain copy
- # df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/VolGroup00-LogVol00
- 7xxG 169G xxG 65% /
- /dev/sda1 99M 13M 81M 14% /boot
- tmpfs 7.9G 0 7.9G 0% /dev/shm
说明:斜体表示不确定具体数据,仅供参考
[sql] view plain copy
- # fdisk -l
- Disk /dev/sda: 32.2 GB, 32212254720 bytes
- 255 heads, 63 sectors/track, 3916 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- /dev/sda1 * 1 13 104391 83 Linux
- /dev/sda2 14 3916 31350847+ 8e Linux LVM
- Disk /dev/sdb: 536.8 GB, 536870912000 bytes
- 255 heads, 63 sectors/track, 65270 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Disk /dev/sdb doesn't contain a valid partition table
- Disk /dev/sdc: 214.7 GB, 214748364800 bytes
- 255 heads, 63 sectors/track, 26108 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Disk /dev/sdc doesn't contain a valid partition table
由于是删除挂载在/目录的盘,不能在线删盘,需要进入安全模式
重启操作系统,从安装光盘启动
输入linux rescue 进入linux 安全模式,选择不挂载 NO-NO-NO
(我用的是实体服务器,del,然后选择 rescue 进入,直接在bash里面执行命令 就好了
选择第三个)
2、取消挂载,进行磁盘检测
lvm vgscan -v
lvm vgchange -a y
lvm lvs -all
e2fsck -f /dev/mapper/VolGroup00-LogVol00 磁盘检测
3、对逻辑卷重定义大小
resize2fs -p /dev/mapper/VolGroup00-LogVol00 300G 重定义大小,缩至300G
lvreduce -L 310G /dev/mapper/VolGroup00-LogVol00 重定义大小
由700G变成300G,大约要删除400G,就算400G的盘子数据满了,也可以全部移走。
4、查看物理卷情况
[sql] view plain copy
- pvdisplay -m
- --- Physical volume ---
- PV Name /dev/sda2
- VG Name VolGroup00
- PV Size 29.90 GB / not usable 24.06 MB
- Allocatable yes (but full)
- PE Size (KByte) 32768
- Total PE 956
- Free PE 0
- Allocated PE 956
- PV UUID cjwiEg-ZlfV-e1q0-VqpF-whuF-BAq4-ECOsrx
- --- Physical Segments ---
- Physical extent 0 to 892:
- Logical volume /dev/VolGroup00/LogVol00
- Logical extents 0 to 892
- Physical extent 893 to 955:
- Logical volume /dev/VolGroup00/LogVol01
- Logical extents 0 to 62
- --- Physical volume ---
- PV Name /dev/sdb
- VG Name VolGroup00
- PV Size 500.00 GB / not usable 32.00 MB
- Allocatable yes
- PE Size (KByte) 32768
- Total PE 15999
- Free PE 6972
- Allocated PE 9027
- PV UUID ltIgU5-6uep-nusm-IvdZ-xby4-cVjT-2RQBrf
- --- Physical volume ---
- PV Name /dev/sdc
- VG Name VolGroup00
- PV Size 200.00 GB / not usable 32.00 MB
- Allocatable yes 激活状态,可写入
- PE Size (KByte) 32768
- Total PE 15999 总共15999PE
- Free PE 15999 空闲15999PE,也就是说这块硬盘是空的
- Allocated PE 9027
- PV UUID ltIgU5-6uep-nusm-IvdZ-xby4-cVjT-2RQBrf
- --- Physical Segments ---
- Physical extent 0 to 9026:
- Logical volume /dev/VolGroup00/LogVol00
- Logical extents 893 to 9919
- Physical extent 9027 to 15998:
- FREE
5、移动数据,将要删除的盘的数据移动到别的盘
pvmove -i /dev/sdc
(这里我使用 pvmove /dev/sdc /dev/sda1)根据实际情况把 源 迁移到 目标
no data to move for VolGroup00
这一步,非常重要,如果盘子里面有数据,不做这一步,会造成数据丢失
6、注销要删除的硬盘/dev/sdc
[sql] view plain copy
- pvchange -xn /dev/sdc 注销sdc
- pvdisplay -m
- --- Physical volume ---
- PV Name /dev/sdc
- VG Name VolGroup00
- PV Size 200.00 GB / not usable 32.00 MB
- Allocatable NO //不是激活状态了
- PE Size (KByte) 32768
- Total PE 15999
- Free PE 15999
- Allocated PE 0
7、将硬盘或分区从逻辑卷组中删除,并删除物理盘
vgreduce VolGroup00 /dev/sdc //从逻辑卷组中删除
pvremove /dev/sdc 删除物理卷
pvdisplay
sdc 已经看不到了。
8、查看结果
[sql] view plain copy
- # df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/VolGroup00-LogVol00
- 291G 181G 96G 66% /
- /dev/sda1 99M 13M 81M 14% /boot
- tmpfs 7.9G 0 7.9G 0% /dev/shm
启动数据库正常。主从复制线程正常(从)。
更多推荐
所有评论(0)