如何删除sd分区(磁盘管理-8-LVM裁剪和删除)

4.3 离线裁剪逻辑卷

[root@localhost /]# umount /lv1
[root@localhost /]# e2fsck -f /dev/vg1/lv1      检验文件系统
[root@localhost /]# resize2fs /dev/vg1/lv1  2G  裁剪文件系统到2G
[root@localhost /]# lvreduce /dev/vg1/lv1 -L 2G 裁剪逻辑卷
[root@localhost /]# mount /dev/vg1/lv1 /lv1/        挂载使用
[root@localhost /]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/mapper/vg1-lv1  2.0G  9.0M  1.8G    1% /lv1


xfs裁剪
将lv2的文件系统格式化为xfs
将/dev/vg1/lv2挂载到/lv2
在/lv2中建立一个文件,写入内容
备份数据
卸载分区并裁剪逻辑卷
格式化裁剪后的逻辑卷
导入数据


1)备份数据命令
xfsdump
2)备份数据
[root@localhost /]# xfsdump -f /root/lv2.img /lv2
#挂载点目录后面不要加"/"
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.8 (dump format 3.0) - type ^C for status and control

 ============================= dump label dialog ==============================

please enter label for this dump session (timeout in 300 sec)
 -> lv2
session label entered: "lv2"

 --------------------------------- end dialog ---------------------------------

xfsdump: level 0 dump of localhost.localdomain:/lv2
xfsdump: dump date: Tue Dec 10 06:33:44 2019
xfsdump: session id: 15936371-b967-4c2c-8995-49eb702792fe
xfsdump: session label: "lv2"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 20800 bytes

 ============================= media label dialog =============================

please enter label for media in drive 0 (timeout in 300 sec)
 -> lv2
media label entered: "lv2"

 --------------------------------- end dialog ---------------------------------

xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 21016 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 14 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /root/lv2.img OK (success)
xfsdump: Dump Status: SUCCESS


3)裁剪
[root@localhost ~]# umount /lv2
[root@localhost ~]# lvreduce /dev/vg1/lv2 -L 100M
  WARNING: Reducing active logical volume to 2.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg01/lv01? [y/n]: y
  Size of logical volume vg01/lv01 changed from 7.00 GiB (1792 extents) to 2.00 GiB (512 extents).
  Logical volume vg01/lv01 successfully resized.

4)格式化
[root@localhost ~]# mkfs.xfs -f /dev/vg1/lv2
[root@localhost ~]# mount /dev/vg1/lv2 /lv2

5)恢复数据 -f source
[root@localhost ~]# xfsrestore -f /root/lv2.img /lv2
.
.
.
xfsrestore: Restore Status: SUCCESS


root@localhost ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/mapper/vg1-lv2   95M  6.0M   89M    7% /lv2



[root@localhost ~]# cat /lv2/filea 
hahaha

4.4 删除LVM

建立: 分区--PV--VG--LV--挂载--fstab(autofs)--写入数据

删除: 备份重要数据--fstab(autofs)--卸载--LV--VG--PV--分区

1   备份数据(如果有需要) 
2   编辑fstab文件或者autofs服务相关文件,删除相关设置
3   卸载
[root@localhost ~]#umount /lv1
4   删除逻辑卷
[root@localhost ~]#lvremove /dev/vg1/lv1
5   删除卷组
[root@localhost ~]#vgchange -an vg1 
[root@localhost ~]#vgremove vg1
6   删除物理卷
[root@localhost ~]#pvremove /dev/sdxx
7   删除分区
[root@localhost ~]#fdisk /dev/sdxx
[root@localhost ~]#partprobe

小结

ext*离线裁剪的流程

umount--e2fsck--resize2fs--lvreduce--mount

xfs如何操作

xfsdump--umount--lvreduce--mkfs--mount--xfsrestore

删除LVM

备份--卸载
--lvremove--vgchange--vgremove--pvremove

==重点:lvm的删除,数据的备份==

==难点:针对于不同类型文件系统的裁剪流程有所差异,lvm删除之前记得备份数据==