解析linux中raid和lvm(尚观学习笔记)

发布时间:2021-01-03编辑:脚本学堂
本文介绍下,linux中的raid与lvm的相关知识,来自尚观的学习笔记,有需要的朋友参考下吧。
lvm缩容:
卸载:
 

复制代码 代码示例:
[root@station230 ~]# umount /dev/vg0/lv0

检查文件系统:
 

复制代码 代码示例:
[root@station230 ~]# e2fsck -f  /dev/vg0/lv0
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg0/lv0: 11/26624 files (9.1% non-contiguous), 9031/102400 blocks

文件系统级别缩容:
 

复制代码 代码示例:
[root@station230 ~]# resize2fs /dev/vg0/lv0 80M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vg0/lv0 to 81920 (1k) blocks.
The filesystem on /dev/vg0/lv0 is now 81920 blocks long.

lv缩容:
 

复制代码 代码示例:

[root@station230 ~]# lvreduce  -L -20M /dev/vg0/lv0
  WARNING: Reducing active logical volume to 80.00 MB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv0? [y/n]: y
  Reducing logical volume lv0 to 80.00 MB
  Logical volume lv0 successfully resized

 [root@station230 ~]# vgreduce  vg0  /dev/sda14
  Removed "/dev/sda14" from volume group "vg0"

[root@station230 ~]# pvremove /dev/sda14
  Labels on physical volume "/dev/sda14" successfully wiped

[root@station230 ~]# vgremove vg0
[root@station230 ~]# lvremove lv0

lvm快照:
 

复制代码 代码示例:

[root@station230 lv0]# lvcreate  -s /dev/vg0/lv0  -n lv0bak -L 20M
  Logical volume "lv0bak" created

[root@station230 lv0bak]# lvscan
  ACTIVE   Original '/dev/vg0/lv0' [80.00 MB] inherit
  ACTIVE   Snapshot '/dev/vg0/lv0bak' [20.00 MB] inherit

替换物理卷:
把新的pv添加到vg:
 

复制代码 代码示例:
[root@station230 lv0bak]# pvcreate /dev/sda14
  Physical volume "/dev/sda14" successfully created
[root@station230 lv0bak]# vgextend vg0 /dev/sda14
  Volume group "vg0" successfully extended

移动数据:
 

复制代码 代码示例:
[root@station230 ~]# pvmove /dev/sda11 /dev/sda14
  /dev/sda11: Moved: 100.0%

移出旧pv:
 

复制代码 代码示例:
[root@station230 ~]# vgreduce vg0 /dev/sda11
  Removed "/dev/sda11" from volume group "vg0"
[root@station230 ~]# cd /mnt/lv0
[root@station230 lv0]# ls
a  b  c  d  lost+found

迁移:

原来的主机:
 

复制代码 代码示例:
[root@station230 ~]# umount /dev/vg0/lv0
[root@station230 ~]# vgchange -a n vg0
  0 logical volume(s) in volume group "vg0" now active
[root@station230 ~]# vgexport vg0
  Volume group "vg0" successfully exported

替换的主机:
 

复制代码 代码示例:
[root@station230 ~]# vgimport vg0
  Volume group "vg0" successfully imported
[root@station230 ~]# vgchange -a y vg0
  1 logical volume(s) in volume group "vg0" now active
[root@station230 ~]# mount /dev/vg0/lv0 /mnt/lv0