暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

linux的lvm命令及使用详解

我的工作 2020-04-12
4111

本文包括LINUX使用LVM管理分区、调整大小、vgcfgbackup 和 vgcfgrestore、vgmerge、vgexport和vgimport、改变lv的状态、查看lvm的所有命令等lvm知识。

LINUX使用LVM管理分区并调整大小  
1.LVM原先用于IBM的AIX系统
是一种分配磁盘空间到逻辑分区的磁盘管理系统
她可以灵活的动态调整分区的大小
方便管理
从Fedoar Core 3和Redhat Enterprise Linux 4起
LVM成为了安装系统的默认值
选择自动分区,就自动使用LVM
当给服务器挂接新硬盘的时候
新硬盘以可以使用LVM挂接到服务器上
2.方法如本文所述
假设现在给服务器挂接了一块339.14GB的磁盘
并希望使用LVM对这个磁盘进行分区管理
本文中们创建两个分区,名字分别叫做data和data1
大小分别为300GB和39GB
然后使用LVM调整其大小
首先确认硬盘的设备名称
执行lvmdiskscan命令
例如得到如下结果
[root@ns /data]# lvmdiskscan
/dev/cciss/c0d0p1 [ 99.59 MB]
/dev/cciss/c2d0p1 [ 1.00 KB]
/dev/cciss/c0d0p2 [ 33.82 GB] LVM physical volume
/dev/cciss/c2d0p5 [ 339.14 GB]
0 disks
2 partitions
0 LVM physical volume whole disks
1 LVM physical volumes
[root@ns /data]#
则339.14GB对应的/dev/cciss/c2d0p5就是设备名称
在设备/dev/cciss/c0d0p2的后边已经带有LVM的标记了
表示装Linux系统的时候就使用了LVM
创建物理分区
fdisk /dev/cciss/c2d0p5
按n键,创建一个分区。
类型选择主分区,大小设置为整个磁盘339.14GB即可
创建完成后按w键写入分区表
创建pv
pv的全称是Physical Vloume,首先要在物理分区上创建pv方可。
执行pvcreate /dev/cciss/c2d0p5即可
创建vg
vg的全称是Volume Group,他是一个Volume组,每个pv上要建立一个vg
执行vgcreate VolGroup01 /dev/cciss/c2d0p5
其中VolGroup01是名称,可以自定义
创建lv
lv的全称是Logical Vloume
执行lvcreate -L 300G -n data VolGroup01
其中-L 300G表示空间是300G
-n data表示名字为data
VolGroup01表示所在的vg
随后lv创建完成
这个lv的名字将会叫做/dev/vg名字/lv名字
例如/dev/VolGroup01/data
执行lvscan可以查看名字
[root@ns ~]# lvscan
ACTIVE '/dev/VolGroup01/data' [300.00 GB] inherit
ACTIVE '/dev/VolGroup00/LogVol00' [32.78 GB] inherit
ACTIVE '/dev/VolGroup00/LogVol01' [1.00 GB] inherit
[root@ns ~]#
这个结果就表示名为data的lv已经创建完成。
同理,再创建data1分区
执行lvcreate -L 39G -n data1 VolGroup01
格式化lv
执行mkfs.ext3 /dev/VolGroup01/data
将磁盘格式化成ext3格式
执行mkfs.ext3 /dev/VolGroup01/data1
将磁盘格式化成ext3格式
挂载lv到普通目录
mkdir /www
mount /dev/VolGroup01/data /www
mkdir /www1
mount /dev/VolGroup01/data1 /www
即可将刚才的两个lv分区分别挂载到/www和/www1的位置
修改/etc/fstab可以在启动时候自动挂载到相应位置
执行df -h可以看分区列表和空间的情况
调整lv的大小
首先取消挂载
umount /www
umount /www1
执行lvresize -L-30G /dev/VolGroup01/data
即可给刚才的data分区减少30GB空间
执行lvresize -L+30G /dev/VolGroup01/data1
即可给刚才的data1分区增加30GB空间
修改之后重新挂载
mount /dev/VolGroup01/data /www
mount /dev/VolGroup01/data1 /www1
现在可以用df -h命令查看具体的磁盘空间
可以看到磁盘容量已经改变
lvm补充知识

(包括1. 关闭PV的PE的分配 2. pvmove 与 pvremove 3. vgcfgbackup 和 vgcfgrestore 4. vgchang -a n 和 y 5. vgmerge 6. vgrename 7. vgexport和vgimport 8. 改变lv的状态 9. lvrename 10. Changing Mirrored Volume Configuration 11.  system-config-lvm 12. lvmdiskscan的使用 13. 查看lvm的所有命令 14 . lvm dumpconfig)
/dev/mapper/下是真正的物理设备,但并全部是可以使用的。
/dev/vg00/下的文件全是连接文件,而且全部可以使用,它是mapper下的一个子集。
1. 关闭PV的PE的分配
pvchange -x n /dev/sda10 command disables the use of PEs from the /dev/sda10 partition.
禁止使用:pvchange -x n /dev/sdb
 [root@rhttt ~]# pvchange -x n /dev/sdb
  Physical volume "/dev/sdb" changed
  1 physical volume changed / 0 physical volumes not changed
[root@rhttt ~]# lvcreate -L 100m vg00 -n lvceshi
  Not enough PVs with free space available for parallel allocation.
  Consider --alloc anywhere if desperate.
[root@rhttt lv00]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               vg00
  PV Size               4.00 GB / not usable 4.00 MB
  Allocatable           NO
  PE Size (KByte)       4096
  Total PE              1023
  Free PE               880
  Allocated PE          143
  PV UUID               nuS2Ph-kPni-MW6o-BysP-xjf0-Ludi-VlXVqa
   
[root@rhttt lv00]#
  Allocatable           NO
注意上面这一行,可以看到禁止分配了,但是已经分配出去的还是可以正常使用的。
恢复使用: pvchange -x y /dev/sdb
 [root@rhttt ~]# pvchange -x y /dev/sdb
  Physical volume "/dev/sdb" changed
  1 physical volume changed / 0 physical volumes not changed
[root@rhttt ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               vg00
  PV Size               4.00 GB / not usable 4.00 MB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              1023
  Free PE               880
  Allocated PE          143
  PV UUID               nuS2Ph-kPni-MW6o-BysP-xjf0-Ludi-VlXVqa
[root@rhttt ~]#
[root@rhttt ~]# lvcreate -L 100m vg00 -n lvceshi
  Logical volume "lvceshi" created
[root@rhttt ~]#
2. pvmove 与 pvremove
 [root@rhttt ~]# pvcreate /dev/sdc3
  Physical volume "/dev/sdc3" successfully created
[root@rhttt ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree  
  /dev/sdb   vg00 lvm2 a-     4.00G   3.34G
  /dev/sdc3       lvm2 --   290.24M 290.24M
[root@rhttt ~]# vgextend vg00 /dev/sdc3
  Volume group "vg00" successfully extended
[root@rhttt ~]# vgdisplay -v
    Finding all volume groups
    Finding volume group "vg00"
  --- Volume group ---
  VG Name               vg00
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  13
******* 有省略 *******
   
  --- Physical volumes ---
  PV Name               /dev/sdb     
  PV UUID               nuS2Ph-kPni-MW6o-BysP-xjf0-Ludi-VlXVqa
  PV Status             allocatable
  Total PE / Free PE    1023 / 855
   
  PV Name               /dev/sdc3     
  PV UUID               2knZUY-5Ipl-sYDf-Gs05-9Suu-GquV-e7cGsB
  PV Status             allocatable
  Total PE / Free PE    72 / 72
[root@rhttt ~]# pvmove /dev/sdc3
  No data to move for vg00
[root@rhttt ~]# vgreduce vg00 /dev/sdc3
  Removed "/dev/sdc3" from volume group "vg00"
[root@rhttt ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree  
  /dev/sdb   vg00 lvm2 a-     4.00G   3.34G
  /dev/sdc3       lvm2 --   290.24M 290.24M
[root@rhttt ~]# pvremove /dev/sdc3
  /dev/cdrom: open failed: Read-only file system
  Attempt to close device '/dev/cdrom' which is not open.
  Labels on physical volume "/dev/sdc3" successfully wiped
[root@rhttt ~]# pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb   vg00 lvm2 a-   4.00G 3.34G
[root@rhttt ~]#
3. vgcfgbackup 和 vgcfgrestore
vgcfgbackup
[root@rhttt ~]# ls -l --full-time /etc/lvm/backup/
total 4
-rw------- 1 root root 2142 2009-01-28 02:55:57.000000000 +0800 vg00
[root@rhttt ~]# vgcfgbackup
  Volume group "vg00" successfully backed up.
[root@rhttt ~]# ls -l --full-time /etc/lvm/backup/
total 4
-rw------- 1 root root 2142 2009-02-23 18:00:02.000000000 +0800 vg00
[root@rhttt ~]#
vgcfgrestore
[root@rhttt ~]# vgcfgrestore
  Please specify a *single* volume group to restore.
[root@rhttt ~]# vgcfgrestore vg00
  Restored volume group vg00
[root@rhttt ~]#
4. vgchang -a n 和 y
 [root@rhttt ~]# vgchange -a n vg00
  Can't deactivate volume group "vg00" with 1 open logical volume(s)
[root@rhttt ~]# umount /lv00
[root@rhttt ~]# vgchange -a n vg00
  0 logical volume(s) in volume group "vg00" now active
[root@rhttt ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  vg00   1   3   0 wz--n- 4.00G 3.44G
[root@rhttt ~]# vgdisplay
  --- Volume group ---
  VG Name               vg00
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  17
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               4.00 GB
  PE Size               4.00 MB
  Total PE              1023
  Alloc PE / Size       143 / 572.00 MB
  Free  PE / Size       880 / 3.44 GB
  VG UUID               64901Y-EfcH-GbO5-G4Kj-mKCL-VIx9-2MD2un
   
[root@rhttt ~]#
[root@rhttt ~]# vgchange -a y
  3 logical volume(s) in volume group "vg00" now active
[root@rhttt ~]# mount /dev/vg00/lv00  /lv00
[root@rhttt ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             3.6G  2.8G  585M  83% /
/dev/sda1              99M   11M   83M  12% /boot
tmpfs                 125M     0  125M   0% /dev/shm
/dev/sdc1             471M   25M  423M   6% /home
/dev/mapper/vg00-lv00
                      454M  212M  219M  50% /lv00
[root@rhttt ~]# vgdisplay
  --- Volume group ---
  VG Name               vg00
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  17
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               4.00 GB
  PE Size               4.00 MB
  Total PE              1023
  Alloc PE / Size       143 / 572.00 MB
  Free  PE / Size       880 / 3.44 GB
  VG UUID               64901Y-EfcH-GbO5-G4Kj-mKCL-VIx9-2MD2un
 [root@rhttt ~]#
5. vgmerge
# vgmerge vg00 vg01
将后一个逻辑卷vg01 合并到vg00中去,合并前要先将vg01置为inactive状态。
合并后还要重新激活vg00,已使所有已有的逻辑卷置为可用的状态。
If you have an unused VG vgroup01, you can merge it into vgroup00 with
the following command: vgmerge vgroup00 vgroup01.
前提:v01下原有一个lv(lv_other)应经创建文件系统。
[root@rhttt ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  vg00   1   3   0 wz--n-  4.00G  3.44G
  vg01   1   1   0 wz--n- 52.00M 20.00M
[root@rhttt ~]# pvs
  PV         VG   Fmt  Attr PSize  PFree
  /dev/sdb   vg00 lvm2 a-    4.00G  3.44G
  /dev/sdc5  vg01 lvm2 a-   52.00M 20.00M
[root@rhttt ~]# vgmerge vg00 vg01
  /dev/cdrom: open failed: Read-only file system
  Logical volumes in "vg01" must be inactive
[root@rhttt ~]# vgchange -a n vg01
  0 logical volume(s) in volume group "vg01" now active
[root@rhttt ~]# vgmerge vg00 vg01
  Volume group "vg01" successfully merged into "vg00"
[root@rhttt ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  vg00   2   4   0 wz--n- 4.05G 3.46G
[root@rhttt ~]# pvs
  PV         VG   Fmt  Attr PSize  PFree
  /dev/sdb   vg00 lvm2 a-    4.00G  3.44G
  /dev/sdc5  vg00 lvm2 a-   52.00M 20.00M
[root@rhttt ~]#
[root@rhttt ~]# vgdisplay -v
    Finding all volume groups
    Finding volume group "vg00"
   ***** 有省略 *****
  --- Logical volume ---
  LV Name                /dev/vg00/lv_other
  VG Name                vg00
  LV UUID                kWQgeQ-diTs-TtUX-abXr-hAbO-1vnf-Id2KgX
  LV Write Access        read/write
  LV Status              NOT available
  LV Size                32.00 MB
  Current LE             8
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
   --- Physical volumes ---
  PV Name               /dev/sdb
  PV UUID               nuS2Ph-kPni-MW6o-BysP-xjf0-Ludi-VlXVqa
  PV Status             allocatable
  Total PE / Free PE    1023 / 880
   
  PV Name               /dev/sdc5
  PV UUID               vrhxxa-BizP-hjof-kJAc-4E3Z-yEKR-1bTmst
  PV Status             allocatable
  Total PE / Free PE    13 / 5
 [root@rhttt ~]#
注意:下面的这个,lv的状态不可用
  LV Status              NOT available
[root@rhttt ~]# vgchange -a y vg00
  4 logical volume(s) in volume group "vg00" now active
再次vgdisplay -v 查看:
  --- Logical volume ---
  LV Name                /dev/vg00/lv_other
  VG Name                vg00
  LV UUID                kWQgeQ-diTs-TtUX-abXr-hAbO-1vnf-Id2KgX
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                32.00 MB
  Current LE             8
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3
挂载:
[root@rhttt ~]# mount /dev/vg00/lv_other /lv_other/
6. vgrename
改变vg的名字
[root@rhttt ~]# vgrename vg00  my_vg
  Volume group "vg00" still has active LVs
[root@rhttt ~]# vgchange -a n vg00
  0 logical volume(s) in volume group "vg00" now active
[root@rhttt ~]# vgrename vg00 my_vg
  /dev/cdrom: open failed: Read-only file system
  Attempt to close device '/dev/cdrom' which is not open.
  Volume group "vg00" successfully renamed to "my_vg"
[root@rhttt ~]# vgs
  VG    #PV #LV #SN Attr   VSize VFree
  my_vg   2   4   0 wz--n- 4.05G 3.46G
这时所有的VG的lv的状态都是NOT available,需要重新激活以下
  --- Logical volume ---
  LV Name                /dev/my_vg/lv_other
  VG Name                my_vg
  LV UUID                kWQgeQ-diTs-TtUX-abXr-hAbO-1vnf-Id2KgX
  LV Write Access        read/write
  LV Status              NOT available
  LV Size                32.00 MB
  Current LE             8
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
[root@rhttt ~]# vgchange -a y my_vg
  4 logical volume(s) in volume group "my_vg" now active
7. vgexport和vgimport
       vgexport  allows  you to make the inactive VolumeGroupName(s) unknown to the system.  You can then move all the
       Physical Volumes in that Volume Group to a different system for later  vgimport(8).   Most  LVM2  tools  ignore
       exported Volume Groups.
       vgimport  allows  you to make a Volume Group that was previously exported using vgexport(8) known to the system
       again, perhaps after moving its Physical Volumes from a different machine.
[root@rhttt ~]# vgchange -a n my_vg
  0 logical volume(s) in volume group "my_vg" now active
[root@rhttt ~]# vgdisplay -v my_vg
    Using volume group(s) on command line
    Finding volume group "my_vg"
  --- Volume group ---
  VG Name               my_vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  25
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                4
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               4.00 GB
  PE Size               4.00 MB
  Total PE              1023
  Alloc PE / Size       151 / 604.00 MB
  Free  PE / Size       872 / 3.41 GB
  VG UUID               64901Y-EfcH-GbO5-G4Kj-mKCL-VIx9-2MD2un
    --- Logical volume ---
  LV Name                /dev/my_vg/lv00
  VG Name                my_vg
  LV UUID                cx0Ipu-lZjk-21pY-uTDz-toxm-sWzF-6AL4Mh
  LV Write Access        read/write
  LV Status              NOT available
  LV Size                468.00 MB
  Current LE             117
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
     ******** 有省略 ********
  --- Physical volumes ---
  PV Name               /dev/sdb
  PV UUID               nuS2Ph-kPni-MW6o-BysP-xjf0-Ludi-VlXVqa
  PV Status             allocatable
  Total PE / Free PE    1023 / 872
   
[root@rhttt ~]#
当关闭my_vg的活动状态时,就可以将该卷vgexport。
[root@rhttt ~]# vgexport  my_vg
  Volume group "my_vg" successfully exported
[root@rhttt ~]#
注意:-a 参数是所有的vg,但激活的lv的vg不受影响。
[root@rhttt ~]# vgexport -a
  Volume group "vg01" has active logical volumes
  Volume group my_vg is exported
[root@rhttt ~]#
[root@rhttt ~]# vgdisplay -v my_vg
    Using volume group(s) on command line
    Finding volume group "my_vg"
  Volume group my_vg is exported
  --- Volume group ---
  VG Name               my_vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  26
  VG Access             read/write
  VG Status             exported/resizable
  MAX LV                0
  Cur LV                4
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               4.00 GB
  PE Size               4.00 MB
  Total PE              1023
  Alloc PE / Size       151 / 604.00 MB
  Free  PE / Size       872 / 3.41 GB
  VG UUID               64901Y-EfcH-GbO5-G4Kj-mKCL-VIx9-2MD2un
  Volume group my_vg is exported
  --- Physical volumes ---
  PV Name               /dev/sdb
  PV UUID               nuS2Ph-kPni-MW6o-BysP-xjf0-Ludi-VlXVqa
  PV Status             allocatable
  Total PE / Free PE    1023 / 872
 [root@rhttt ~]#
注意这句,此前有很多的lv,现在全部没有了。
  Volume group my_vg is exported
在本机恢复:
[root@rhttt ~]# vgimport my_vg
  Volume group "my_vg" successfully imported
[root@rhttt ~]# vgimport my_vg
  Volume group "my_vg" is not exported
[root@rhttt ~]#
注意:当第2次执行时,就报其它的错误了。
[root@rhttt ~]# vgchange -a y my_vg
  4 logical volume(s) in volume group "my_vg" now active
[root@rhttt ~]#
在其它服务器上恢复:
[root@rhdb2 ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found exported volume group "my_vg" using metadata type lvm2
  Found volume group "vg00" using metadata type lvm2
[root@rhdb2 ~]# vgimport my_vg
  Volume group "my_vg" successfully imported
[root@rhdb2 ~]#
[root@rhdb2 ~]# vgchange -a y my_vg
  4 logical volume(s) in volume group "my_vg" now active
[root@rhdb2 ~]# mkdir /lv00
[root@rhdb2 ~]# mount /dev/my_vg/lv00 /lv00
8. 改变lv的状态
lvchange
 Similar to pvchange, changes the attributes of an LV: for example,
 the lvchange -a n vgroup00/lvol00 command disables the use of the LV labeled lvol00.
[root@rhttt /]# lvdisplay my_vg/lv00
  --- Logical volume ---
  LV Name                /dev/my_vg/lv00
  VG Name                my_vg
  LV UUID                cx0Ipu-lZjk-21pY-uTDz-toxm-sWzF-6AL4Mh
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                468.00 MB
  Current LE             117
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
 (1) 使lv00失活
[root@rhttt /]# lvchange -a n my_vg/lv00
[root@rhttt /]# lvdisplay my_vg/lv00
  --- Logical volume ---
  LV Name                /dev/my_vg/lv00
  VG Name                my_vg
  LV UUID                cx0Ipu-lZjk-21pY-uTDz-toxm-sWzF-6AL4Mh
  LV Write Access        read/write
  LV Status              NOT available
  LV Size                468.00 MB
  Current LE             117
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
(2) 将lv00激活
[root@rhttt /]# lvchange -a y my_vg/lv00
[root@rhttt /]# lvdisplay my_vg/lv00
  --- Logical volume ---
  LV Name                /dev/my_vg/lv00
  VG Name                my_vg
  LV UUID                cx0Ipu-lZjk-21pY-uTDz-toxm-sWzF-6AL4Mh
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                468.00 MB
  Current LE             117
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
 [root@rhttt /]#
失活逻辑卷my_vg下的所有lv
[root@rhttt /]# lvchange -a n my_vg
激活逻辑卷my_vg下的所有lv
[root@rhttt /]# lvchange -a y my_vg
注意:正在使用的lv是不会被失活的,如下所示。
[root@rhttt /]# lvchange -a n my_vg/lv00
  LV my_vg/lv00 in use: not deactivating
[root@rhttt /]# lvchange -a n my_vg
  LV my_vg/lv00 in use: not deactivating
9. lvrename
  lvrename - rename a logical volume
       To rename lvold in volume group vg02 to lvnew:
            lvrename /dev/vg02/lvold /dev/vg02/lvnew
       An alternate syntax to rename this logical volume is
            lvrename vg02 lvold lvnew
将lv00变名为lv00_new
[root@rhttt ~]# lvrename /dev/my_vg/lv00   /dev/my_vg/lv00_new
  Renamed "lv00" to "lv00_new" in volume group "my_vg"
[root@rhttt ~]#
恢复:重新将lv00_new变回lv00
[root@rhttt ~]# lvrename my_vg lv00_new  lv00
  Renamed "lv00_new" to "lv00" in volume group "my_vg"
[root@rhttt ~]#
10. Changing Mirrored Volume Configuration
相反的操作例子:
The following command converts the linear logical volume vg00/lvol1 to a mirrored logical volume.
lvconvert -m1 vg00/lvol1
The following command converts the mirrored logical volume vg00/lvol1 to a linear logical volume, removing the mirror leg.
lvconvert -m0 vg00/lvol1
lvconvert
 If there are sufficient available PVs, the lvconvert -m1 vgroup00/lvol00 command mirrors the LV.
       -m, --mirrors Mirrors
              Specifies the degree of the mirror you wish to create.  For example, "-m 1" would convert  the  original
              logical volume to a mirror volume with 2-sides; that is, a linear volume plus one copy.
Examples
       "lvconvert -m1 vg00/lvol1"
       converts the linear logical volume "vg00/lvol1" to a two-way mirror logical volume.
       "lvconvert --mirrorlog core vg00/lvol1"
       converts a mirror with a disk log to a mirror with an in-memory log.
       "lvconvert --mirrorlog disk vg00/lvol1"
       converts a mirror with an in-memory log to a mirror with a disk log.
       "lvconvert -m0 vg00/lvol1"
       converts a mirror logical volume to a linear logical volume.
       "lvconvert -s vg00/lvol1 vg00/lvol2"
       converts logical volume "vg00/lvol2" to snapshot of original volume "vg00/lvol1"
开始操作:
没有足够的PV, 转换后报错:
[root@rhttt ~]# lvconvert -m1 vg01/lv911
  Not enough PVs with free space available for parallel allocation.
  Consider --alloc anywhere if desperate.
  Unable to allocate extents for mirror(s).
[root@rhttt ~]#
加pv,然后再运行:
[root@rhttt ~]# lvconvert -m1  vg01/lv911
  vg01/lv911: Converted: 100.0%
  Logical volume lv911 converted.
[root@rhttt ~]# pvs
  PV         VG    Fmt  Attr PSize   PFree
  /dev/sdb   my_vg lvm2 a-     4.00G   3.41G
  /dev/sdc2  vg01  lvm2 a-   980.00M 980.00M
  /dev/sdc3  vg01  lvm2 a-   288.00M 288.00M
  /dev/sdc5  vg01  lvm2 a-    52.00M  32.00M
[root@rhttt ~]#
[root@rhttt ~]# lvs
  LV       VG    Attr   LSize   Origin Snap%  Move Log        Copy%  Convert
  lv00     my_vg -wi-a- 468.00M
  lv01     my_vg -wi-a-  52.00M
  lv02     my_vg -wi-a-  52.00M
  lv_other my_vg -wi-a-  32.00M
  lv911    vg01  mwi-a-  20.00M                    lv911_mlog 100.00
[root@rhttt ~]#
注意:下面的输出,除了lv911以外,全是命令运行后的结果。
[root@rhttt ~]# vgdisplay -v vg01
    Using volume group(s) on command line
    Finding volume group "vg01"
  --- Volume group ---
  VG Name               vg01
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  9
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                4
  Open LV               0
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               1.29 GB
  PE Size               4.00 MB
  Total PE              330
  Alloc PE / Size       11 / 44.00 MB
  Free  PE / Size       319 / 1.25 GB
  VG UUID               G48WnK-XEDn-8azf-heXP-QcLg-SBhB-KPs40V
   --- Logical volume ---
  LV Name                /dev/vg01/lv911
  VG Name                vg01
  LV UUID                bi0O8B-pN3K-wxui-lNP6-lqHJ-pOM7-ZXRBmP
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                20.00 MB
  Current LE             5
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
    --- Logical volume ---
  LV Name                /dev/vg01/lv911_mlog
  VG Name                vg01
  LV UUID                fTZbFe-qxes-bolq-cvet-uI1L-C1nw-NMploJ
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                4.00 MB
  Current LE             1
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:5
   --- Logical volume ---
  LV Name                /dev/vg01/lv911_mimage_0
  VG Name                vg01
  LV UUID                nbecog-9sM1-NXgF-I4Ga-HB22-poFQ-etkG75
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                20.00 MB
  Current LE             5
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:6
   --- Logical volume ---
  LV Name                /dev/vg01/lv911_mimage_1
  VG Name                vg01
  LV UUID                i3lAmS-Gp0Y-76An-JL5f-i0Gm-1nCE-KyW50J
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                20.00 MB
  Current LE             5
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:7
  --- Physical volumes ---
  PV Name               /dev/sdc5
  PV UUID               vrhxxa-BizP-hjof-kJAc-4E3Z-yEKR-1bTmst
  PV Status             allocatable
  Total PE / Free PE    13 / 8
   PV Name               /dev/sdc3
  PV UUID               ZAqwc1-VnyF-yQ4Q-iqAW-DKMr-DkGx-54QPCv
  PV Status             allocatable
  Total PE / Free PE    72 / 71
   
  PV Name               /dev/sdc2
  PV UUID               TFShuz-ZUEr-3JDZ-Zk6T-CnFJ-u1Cz-Vd0gtK
  PV Status             allocatable
  Total PE / Free PE    245 / 240
 [root@rhttt ~]#
一些lv的解释:
/dev/vg01/lv911  逻辑卷的接口,并不占用实际存储
/dev/vg01/lv911_mimage_0  实际存储的位置0
/dev/vg01/lv911_mimage_1  实际存储的位置1
/dev/vg01/lv911_mlog  两个实际存储的mimage的同步日志的存放的位置
撤销lv911的镜像,恢复线性存储,如下所示:
[root@rhttt ~]# lvconvert -m0 vg01/lv911
  Logical volume lv911 converted.
[root@rhttt ~]#
[root@rhttt ~]# vgdisplay vg01 -v
    Using volume group(s) on command line
    Finding volume group "vg01"
  --- Volume group ---
  VG Name               vg01
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  14
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               1.29 GB
  PE Size               4.00 MB
  Total PE              330
  Alloc PE / Size       5 / 20.00 MB
  Free  PE / Size       325 / 1.27 GB
  VG UUID               G48WnK-XEDn-8azf-heXP-QcLg-SBhB-KPs40V
  --- Logical volume ---
  LV Name                /dev/vg01/lv911
  VG Name                vg01
  LV UUID                bi0O8B-pN3K-wxui-lNP6-lqHJ-pOM7-ZXRBmP
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                20.00 MB
  Current LE             5
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  --- Physical volumes ---
  PV Name               /dev/sdc5
  PV UUID               vrhxxa-BizP-hjof-kJAc-4E3Z-yEKR-1bTmst
  PV Status             allocatable
  Total PE / Free PE    13 / 8
  PV Name               /dev/sdc3
  PV UUID               ZAqwc1-VnyF-yQ4Q-iqAW-DKMr-DkGx-54QPCv
  PV Status             allocatable
  Total PE / Free PE    72 / 72
  PV Name               /dev/sdc2
  PV UUID               TFShuz-ZUEr-3JDZ-Zk6T-CnFJ-u1Cz-Vd0gtK
  PV Status             allocatable
  Total PE / Free PE    245 / 245
[root@rhttt ~]#
11.  system-config-lvm
扩缩文件系统时,自动操作,不需手动扩展和回缩文件系统。
在快照分区的删除过程中,出现问题,无法删除。
lv在创建过程中,只能指定区的个数,每个PE 4M。
12. lvmdiskscan的使用
 [root@oradb2 ~]# lvmdiskscan -l
  WARNING: only considering LVM devices
  /dev/sda2      [       33.99 GB] LVM physical volume
  /dev/sdb       [       34.18 GB] LVM physical volume
  /dev/sdc       [       34.18 GB] LVM physical volume
  2 LVM physical volume whole disks
  1 LVM physical volume
[root@oradb2 ~]#
[root@oradb2 ~]# lvmdiskscan
  /dev/ramdisk   [       16.00 MB]
  /dev/root      [        3.00 GB]
  /dev/ram       [       16.00 MB]
  /dev/sda1      [      196.08 MB]
  /dev/vg00/lv03 [        2.00 GB]
  /dev/ram2      [       16.00 MB]
  /dev/sda2      [       33.99 GB] LVM physical volume
  /dev/vg00/lv02 [        2.00 GB]
  /dev/ram3      [       16.00 MB]
  /dev/vg00/lv07 [        9.09 GB]
  /dev/ram4      [       16.00 MB]
  /dev/vg00/lv04 [        5.88 GB]
  /dev/ram5      [       16.00 MB]
  /dev/vg00/lv06 [       10.00 GB]
  /dev/ram6      [       16.00 MB]
  /dev/vg00/lv05 [        2.00 GB]
  /dev/ram7      [       16.00 MB]
  /dev/ram8      [       16.00 MB]
  /dev/ram9      [       16.00 MB]
  /dev/ram10     [       16.00 MB]
  /dev/ram11     [       16.00 MB]
  /dev/ram12     [       16.00 MB]
  /dev/ram13     [       16.00 MB]
  /dev/ram14     [       16.00 MB]
  /dev/ram15     [       16.00 MB]
  /dev/sdb       [       34.18 GB] LVM physical volume
  /dev/sdc       [       34.18 GB] LVM physical volume
  3 disks
  21 partitions
  2 LVM physical volume whole disks
  1 LVM physical volume
[root@oradb2 ~]#
13. 查看lvm的所有命令
[root@oradb2 ~]# man lvm
同时,还以看到lvm后边可以直接跟lvm的相关命令,如下所示:
SYNOPSIS
       lvm [command | file]
[root@oradb2 ~]# lvm vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  vg00   3   7   0 wz--n- 102.28G 68.31G
[root@oradb2 ~]# lvm pvs
  PV         VG   Fmt  Attr PSize  PFree
  /dev/sda2  vg00 lvm2 a-   33.97G     0
  /dev/sdb   vg00 lvm2 a-   34.16G 34.16G
  /dev/sdc   vg00 lvm2 a-   34.16G 34.16G
[root@oradb2 ~]# lvm lvs
  LV   VG   Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  lv01 vg00 -wi-ao  3.00G
  lv02 vg00 -wi-ao  2.00G
  lv03 vg00 -wi-ao  2.00G
  lv04 vg00 -wi-ao  5.88G
  lv05 vg00 -wi-ao  2.00G
  lv06 vg00 -wi-ao 10.00G
  lv07 vg00 -wi-ao  9.09G
[root@oradb2 ~]#
14 . lvm dumpconfig
To display the settings in use after loading all the configuration files,
execute the lvm dumpconfig command.
[root@oradb1 u02]# lvm dumpconfig
  devices {
        dir="/dev"
        scan="/dev"
        preferred_names=[]
        filter="a/.*/"
        cache_dir="/etc/lvm/cache"
        cache_file_prefix=""
        write_cache_state=1
        sysfs_scan=1
        md_component_detection=1
        ignore_suspended_devices=0
  }
  activation {
        missing_stripe_filler="/dev/ioerror"
        reserved_stack=256
        reserved_memory=8192
        process_priority=-18
        mirror_region_size=512
        readahead="auto"
        mirror_log_fault_policy="allocate"
        mirror_device_fault_policy="remove"
  }
  global {
        library_dir="/usr/lib"
        umask=63
        test=0
        units="h"
        activation=1
        proc="/proc"
        locking_type=3
        fallback_to_clustered_locking=1
        fallback_to_local_locking=1
        locking_dir="/var/lock/lvm"
  }
  shell {
        history_size=100
  }
  backup {
        backup=1
        backup_dir="/etc/lvm/backup"
        archive=1
        archive_dir="/etc/lvm/archive"
        retain_min=10
        retain_days=30
  }
  log {
        verbose=0
        syslog=1
        overwrite=0
        level=0
        indent=1
        command_names=0
        prefix="  "
  }
[root@oradb1 u02]#
lvm信息查看
Initializing Physical Volumes
[root@rhdb1 ~]# vgscan
  Reading all physical volumes.  This may take a while...
  /dev/cdrom: open failed: Read-only file system
  Attempt to close device '/dev/cdrom' which is not open.
  No volume groups found
[root@rhdb1 ~]# pvcreate /dev/sdf  /dev/sdg  /dev/sdh
  Physical volume "/dev/sdf" successfully created
  Physical volume "/dev/sdg" successfully created
  Physical volume "/dev/sdh" successfully created
Displaying Physical Volumes
[root@rhdb1 ~]# pvscan
  /dev/cdrom: open failed: Read-only file system
  Attempt to close device '/dev/cdrom' which is not open.
  PV /dev/sdf         lvm2 [10.00 GB]
  PV /dev/sdg         lvm2 [10.00 GB]
  PV /dev/sdh         lvm2 [10.00 GB]
  Total: 3 [30.00 GB] / in use: 0 [0   ] / in no VG: 3 [30.00 GB]
Creating Volume Groups
[root@rhdb1 ~]# vgcreate vg01  /dev/sdf  /dev/sdg  /dev/sdh
  Volume group "vg01" successfully created
 [root@rhdb1 ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  vg01   3   0   0 wz--n- 29.99G 29.99G
[root@rhdb1 ~]# lvcreate -L 1500M -i3 -I64 -n lv_system   vg01
删除:
[root@rhdb1 ~]# lvscan
  ACTIVE            '/dev/vg01/lv_system' [1.46 GB] inherit
  ACTIVE            '/dev/vg01/lv_sysaux' [1.96 GB] inherit
  ACTIVE            '/dev/vg01/lv_undotbs1' [1.96 GB] inherit
  ACTIVE            '/dev/vg01/lv_undotbs2' [1.96 GB] inherit
[root@rhdb1 ~]# lvremove /dev/vg01/lv_system
  /dev/cdrom: open failed: Read-only file system
Do you really want to remove active logical volume "lv_system"? [y/n]: y
  Logical volume "lv_system" successfully removed
[root@rhdb1 ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  vg01   3   0   0 wz--n- 29.99G 29.99G
[root@rhdb1 ~]# vgchange -a n vg01
  0 logical volume(s) in volume group "vg01" now active
[root@rhdb1 ~]# vgremove vg01
  Volume group "vg01" successfully removed
Displaying Volumes
pvs, pvdisplay, pvscan
vgs, vgdisplay, vgscan
lvs, lvdisplay, lvscan
[root@rhdb1 ~]# pvs
  PV         VG   Fmt  Attr PSize  PFree
  /dev/sdf        lvm2 --   10.00G 10.00G
  /dev/sdg        lvm2 --   10.00G 10.00G
  /dev/sdh        lvm2 --   10.00G 10.00G
 [root@rhdb1 ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  vg01   3   0   0 wz--n- 29.99G 29.99G
[root@rhdb1 ~]# lvs
  LV          VG   Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lv_control1 vg01 -wi-a- 504.00M
  lv_control2 vg01 -wi-a- 504.00M
  lv_example  vg01 -wi-a- 504.00M
  lv_ocr      vg01 -wi-a- 204.00M
  lv_orapw    vg01 -wi-a- 108.00M
  lv_redo1_1  vg01 -wi-a- 204.00M
  lv_redo1_2  vg01 -wi-a- 204.00M
  lv_redo2_1  vg01 -wi-a- 204.00M
  lv_redo2_2  vg01 -wi-a- 204.00M
  lv_spfile   vg01 -wi-a- 108.00M
  lv_sysaux   vg01 -wi-a-   1.96G
  lv_system   vg01 -wi-a-   1.46G
  lv_temp     vg01 -wi-a-   1.96G
  lv_undotbs1 vg01 -wi-a-   1.96G
  lv_undotbs2 vg01 -wi-a-   1.96G
  lv_users    vg01 -wi-a- 504.00M
  lv_vote     vg01 -wi-a-  60.00M
[root@rhdb1 ~]#
Scanning for Block Devices
 [root@rhdb1 backup]# lvmdiskscan
  /dev/ramdisk [       16.00 MB]
  /dev/cdrom   [        2.87 GB]
  /dev/ram     [       16.00 MB]
  /dev/sda1    [      196.08 MB]
  /dev/ram2    [       16.00 MB]
  /dev/sda2    [        5.86 GB]
  /dev/ram3    [       16.00 MB]
  /dev/sda3    [        1.95 GB]
  /dev/ram4    [       16.00 MB]
  /dev/ram5    [       16.00 MB]
  /dev/sda5    [      996.19 MB]
  /dev/ram6    [       16.00 MB]
  /dev/sda6    [      996.19 MB]
  /dev/ram7    [       16.00 MB]
  /dev/root    [      996.19 MB]
  /dev/ram8    [       16.00 MB]
  /dev/sda8    [        9.07 GB]
  /dev/ram9    [       16.00 MB]
  /dev/ram10   [       16.00 MB]
  /dev/ram11   [       16.00 MB]
  /dev/ram12   [       16.00 MB]
  /dev/ram13   [       16.00 MB]
  /dev/ram14   [       16.00 MB]
  /dev/ram15   [       16.00 MB]
  /dev/sdb1    [       10.00 GB]
  /dev/sdc1    [        4.00 GB]
  /dev/sdd1    [        4.00 GB]
  /dev/sde1    [        2.00 GB]
  /dev/sdf     [       10.00 GB]
  /dev/sdg     [       10.00 GB]
  /dev/sdh     [       10.00 GB]
  7 disks
  24 partitions
  0 LVM physical volume whole disks
  0 LVM physical volumes
[root@rhdb1 backup]#
/etc/rc.d/rc.local 中的设置
============================
[root@rhdb1 ~]# vi /etc/rc.d/rc.local
/bin/raw  /dev/raw/raw1         /dev/sdi1
/bin/raw  /dev/raw/raw2         /dev/sdi2
/bin/raw  /dev/raw/raw3         /dev/vg01/lv_system
/bin/raw  /dev/raw/raw4         /dev/vg01/lv_sysaux
/bin/raw  /dev/raw/raw5         /dev/vg01/lv_undotbs1
/bin/raw  /dev/raw/raw6         /dev/vg01/lv_undotbs2
/bin/raw  /dev/raw/raw7         /dev/vg01/lv_example
/bin/raw  /dev/raw/raw8         /dev/vg01/lv_users
/bin/raw  /dev/raw/raw9         /dev/vg01/lv_temp
/bin/raw  /dev/raw/raw10        /dev/vg01/lv_spfile
/bin/raw  /dev/raw/raw11        /dev/vg01/lv_orapw
/bin/raw  /dev/raw/raw12        /dev/vg01/lv_control1
/bin/raw  /dev/raw/raw13        /dev/vg01/lv_control2
/bin/raw  /dev/raw/raw14        /dev/vg01/lv_redo1_1
/bin/raw  /dev/raw/raw15        /dev/vg01/lv_redo1_2
/bin/raw  /dev/raw/raw16        /dev/vg01/lv_redo2_1
/bin/raw  /dev/raw/raw17        /dev/vg01/lv_redo2_2
/bin/raw  /dev/raw/raw18        /dev/vg01/lv_fra
chown oracle:oinstall /dev/raw/raw[1-9]
chown oracle:oinstall /dev/raw/raw[1-9][0-8]
chmod 660 /dev/raw/raw[1-9]
chmod 660 /dev/raw/raw[1-9][0-8]



欢迎关注我的公众号    扫描二维码或公众号搜索  “我的工作




文章转载自我的工作,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论