[Linux] PV,VG,LV相关

2016.5.21

pv,vg,lv
[root@iphone dev]# rpm -qa | grep lvm
lvm2-2.02.98-9.el6.x86_64
lvm2-libs-2.02.98-9.el6.x86_64

1.pvcreate  --physical volume create
[root@iphone dev]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created
[root@iphone dev]# pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created
[root@iphone dev]# pvcreate /dev/sdd
  Physical volume "/dev/sdd" successfully created

2.vgcreate  --vg create
[root@iphone dev]# vgcreate vg00 /dev/sdb /dev/sdc
  Volume group "vg00" successfully created

[root@iphone dev]# vgdisplay -v vg00
    Using volume group(s) on command line
    Finding volume group "vg00"
  --- Volume group ---
  VG Name               vg00
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               15.99 GiB
  PE Size               4.00 MiB
  Total PE              4094
  Alloc PE / Size       0 / 0   
  Free  PE / Size       4094 / 15.99 GiB
  VG UUID               Ui6Kbe-yuAV-KxTB-rIwc-BqQo-0nag-AvNfRF
   
  --- Physical volumes ---
  PV Name               /dev/sdb     
  PV UUID               B2K17I-fed9-sOCq-rbbK-r9EJ-4bdQ-V392a8
  PV Status             allocatable
  Total PE / Free PE    2047 / 2047
   
  PV Name               /dev/sdc     
  PV UUID               rPIiBP-8NRC-JzCH-4ghf-2Ef1-SZtV-P1mOo5
  PV Status             allocatable
  Total PE / Free PE    2047 / 2047
 
[root@iphone dev]# pv
pvchange   pvck       pvcreate   pvdisplay  pvmove     pvremove   pvresize   pvs        pvscan     pv.sh      
[root@iphone dev]# pvscan
  PV /dev/sdb    VG vg00            lvm2 [8.00 GiB / 8.00 GiB free]
  PV /dev/sdc    VG vg00            lvm2 [8.00 GiB / 8.00 GiB free]
  PV /dev/sda2   VG vg_iphone       lvm2 [199.51 GiB / 0    free]
  PV /dev/sdd                       lvm2 [8.00 GiB]
  Total: 4 [223.50 GiB] / in use: 3 [215.50 GiB] / in no VG: 1 [8.00 GiB]
 
 
3.vgextend vg扩展
[root@iphone dev]# pvcreate /dev/sdd
  Physical volume "/dev/sdd" successfully created
 
[root@iphone dev]# vgextend vg00 /dev/sdd
  Volume group "vg00" successfully extended
[root@iphone dev]#
[root@iphone dev]# vgdisplay -v vg00
    Using volume group(s) on command line
    Finding volume group "vg00"
  --- Volume group ---
  VG Name               vg00
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               23.99 GiB
  PE Size               4.00 MiB
  Total PE              6141
  Alloc PE / Size       0 / 0   
  Free  PE / Size       6141 / 23.99 GiB
  VG UUID               Ui6Kbe-yuAV-KxTB-rIwc-BqQo-0nag-AvNfRF
   
  --- Physical volumes ---
  PV Name               /dev/sdb     
  PV UUID               B2K17I-fed9-sOCq-rbbK-r9EJ-4bdQ-V392a8
  PV Status             allocatable
  Total PE / Free PE    2047 / 2047
   
  PV Name               /dev/sdc     
  PV UUID               rPIiBP-8NRC-JzCH-4ghf-2Ef1-SZtV-P1mOo5
  PV Status             allocatable
  Total PE / Free PE    2047 / 2047
   
  PV Name               /dev/sdd     
  PV UUID               g92aTC-MK7x-29g8-GsEC-P3ax-GK3z-AA2FRX
  PV Status             allocatable
  Total PE / Free PE    2047 / 2047
   
[root@iphone dev]#
[root@iphone dev]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "vg00" using metadata type lvm2
  Found volume group "vg_iphone" using metadata type lvm2
[root@iphone dev]#
[root@iphone dev]#
[root@iphone dev]# pvscan
  PV /dev/sdb    VG vg00        lvm2 [8.00 GiB / 8.00 GiB free]
  PV /dev/sdc    VG vg00        lvm2 [8.00 GiB / 8.00 GiB free]
  PV /dev/sdd    VG vg00        lvm2 [8.00 GiB / 8.00 GiB free]
  PV /dev/sda2   VG vg_iphone   lvm2 [199.51 GiB / 0    free]
  Total: 4 [223.50 GiB] / in use: 4 [223.50 GiB] / in no VG: 0 [0   ]
 

4.lvcreate  --logical volume create & 挂载文件系统
[root@iphone dev]# lvcreate -L 2G -n lv00 vg00
  Logical volume "lv00" created
 
[root@iphone vg00]# mkfs.ext3 /dev/vg00/lv00
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912

Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@iphone ~]# cd /mnt
[root@iphone mnt]# mkdir fs1
[root@iphone mnt]# mount /dev/vg00/lv00 /mnt/fs1/
[root@iphone mnt]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_iphone-lv_root
                      51606140  43510436   5474264  89% /
tmpfs                  1962952   1028528    934424  53% /dev/shm
/dev/sda1               495844     37919    432325   9% /boot
/dev/mapper/vg_iphone-lv_home
                     150309116    192344 142481420   1% /home
/dev/mapper/vg00-lv00
                       2064208     68676   1890676   4% /mnt/fs1

[root@iphone temp_dir]# cp bu2_20160331.dmp /mnt/fs1/


5.lvextend  --logical volumne extend
[root@iphone fs1]# lvextend -L +1G /dev/vg00/lv00
  Extending logical volume lv00 to 3.00 GiB
  Logical volume lv00 successfully resized
 
[root@iphone fs1]# lvdisplay /dev/vg00/lv00
  --- Logical volume ---
  LV Path                /dev/vg00/lv00
  LV Name                lv00
  VG Name                vg00
  LV UUID                TZ60jS-wT93-G5ym-n6yf-4g77-ng2S-3owaC3
  LV Write Access        read/write
  LV Creation host, time iphone, 2016-05-21 05:11:25 +0800
  LV Status              available
  # open                 1
  LV Size                3.00 GiB
  Current LE             768
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3
   
[root@iphone fs1]# df                     --lv extend,but filesystem is not change
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_iphone-lv_root
                      51606140  43510460   5474240  89% /
tmpfs                  1962952   1028528    934424  53% /dev/shm
/dev/sda1               495844     37919    432325   9% /boot
/dev/mapper/vg_iphone-lv_home
                     150309116    192344 142481420   1% /home
/dev/mapper/vg00-lv00
                       2064208    141636   1817716   8% /mnt/fs1

--so we need run below script                       
[root@iphone ~]# resize2fs /mnt/fs1/
resize2fs 1.41.12 (17-May-2010)
open: Is a directory while opening /mnt/fs1/
[root@iphone ~]#
[root@iphone ~]# resize2fs /dev/vg00/lv00
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg00/lv00 is mounted on /mnt/fs1; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg00/lv00 to 786432 (4k) blocks.
The filesystem on /dev/vg00/lv00 is now 786432 blocks long.

[root@iphone ~]# df              --after run scripts,filesystem is change as logical volume.
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_iphone-lv_root
                      51606140  43510464   5474236  89% /
tmpfs                  1962952   1028528    934424  53% /dev/shm
/dev/sda1               495844     37919    432325   9% /boot
/dev/mapper/vg_iphone-lv_home
                     150309116    192344 142481420   1% /home
/dev/mapper/vg00-lv00
                       3096336    141636   2797428   5% /mnt/fs1
                       

6.lvreduce   --logical volume reduce
[root@iphone ~]# resize2fs /dev/vg00/lv00 2G        --before we reduce the logical volumne,we need run some script.
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg00/lv00 is mounted on /mnt/fs1; on-line resizing required
On-line shrinking from 786432 to 524288 not supported.
[root@iphone ~]#
[root@iphone ~]# umount /mnt/fs1/
[root@iphone ~]# resize2fs /dev/vg00/lv00 2G
resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f /dev/vg00/lv00' first.

[root@iphone ~]# e2fsck -f /dev/vg00/lv00
e2fsck 1.41.12 (17-May-2010)
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/vg00/lv00: 12/196608 files (8.3% non-contiguous), 47757/786432 blocks
[root@iphone ~]#
[root@iphone ~]# resize2fs /dev/vg00/lv00 2G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg00/lv00 to 524288 (4k) blocks.
The filesystem on /dev/vg00/lv00 is now 524288 blocks long.

[root@iphone ~]# mount /dev/vg00/lv00 /mnt/fs1/
[root@iphone ~]#
[root@iphone ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_iphone-lv_root
                      51606140  43510492   5474208  89% /
tmpfs                  1962952   1028528    934424  53% /dev/shm
/dev/sda1               495844     37919    432325   9% /boot
/dev/mapper/vg_iphone-lv_home
                     150309116    192344 142481420   1% /home
/dev/mapper/vg00-lv00
                       2064208    141636   1817724   8% /mnt/fs1

[root@iphone fs1]# lvreduce -L 2G /dev/vg00/lv00
  WARNING: Reducing active and open logical volume to 2.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv00? [y/n]: y
  Reducing logical volume lv00 to 2.00 GiB
  Logical volume lv00 successfully resized
 
 
7.vgreduce   --vg reduce
[root@iphone fs1]# vgreduce vg00 /dev/sdd
  Removed "/dev/sdd" from volume group "vg00"
[root@iphone fs1]#
[root@iphone fs1]#
[root@iphone fs1]# vgdisplay -v vg00
    Using volume group(s) on command line
    Finding volume group "vg00"
  --- Volume group ---
  VG Name               vg00
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  8
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               15.99 GiB
  PE Size               4.00 MiB
  Total PE              4094
  Alloc PE / Size       512 / 2.00 GiB
  Free  PE / Size       3582 / 13.99 GiB
  VG UUID               Ui6Kbe-yuAV-KxTB-rIwc-BqQo-0nag-AvNfRF
   
  --- Logical volume ---
  LV Path                /dev/vg00/lv00
  LV Name                lv00
  VG Name                vg00
  LV UUID                TZ60jS-wT93-G5ym-n6yf-4g77-ng2S-3owaC3
  LV Write Access        read/write
  LV Creation host, time iphone, 2016-05-21 05:11:25 +0800
  LV Status              available
  # open                 1
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3
   
  --- Physical volumes ---
  PV Name               /dev/sdb     
  PV UUID               B2K17I-fed9-sOCq-rbbK-r9EJ-4bdQ-V392a8
  PV Status             allocatable
  Total PE / Free PE    2047 / 1535
   
  PV Name               /dev/sdc     
  PV UUID               rPIiBP-8NRC-JzCH-4ghf-2Ef1-SZtV-P1mOo5
  PV Status             allocatable
  Total PE / Free PE    2047 / 2047

 
8.pvremove       --physical volume remove
[root@iphone fs1]# pvremove /dev/sdd
  Labels on physical volume "/dev/sdd" successfully wiped
 
9.pvmove          --move physical extent
[root@iphone ~]# pvmove /dev/sdb
  /dev/sdb: Moved: 0.4%
  /dev/sdb: Moved: 55.0%
  /dev/sdb: Moved: 99.8%
  /dev/sdb: Moved: 100.0%


10.vgcfgbackup & vgcfgrestore
[root@iphone ~]# vgcfgbackup
  Volume group "vg00" successfully backed up.
  Volume group "vg_iphone" successfully backed up.  

[root@iphone ~]# cd /etc/lvm
[root@iphone lvm]# ll
total 52
drwx------. 2 root root  4096 May 21 06:24 archive
drwx------. 2 root root  4096 May 21 06:30 backup
drwx------. 2 root root  4096 Jan 24  2013 cache
-rw-r--r--. 1 root root 37554 Jan 24  2013 lvm.conf
[root@iphone lvm]# cd backup
[root@iphone backup]# ll
total 8
-rw-------. 1 root root 2300 May 21 06:30 vg00
-rw-------. 1 root root 2091 May 21 06:30 vg_iphone
[root@iphone backup]# vgcfgrestore
  Please specify a *single* volume group to restore.
[root@iphone backup]# vgcfgrestore vg00
  Restored volume group vg00  
 

11.vgchange    (http://blog.chinaunix.net/uid-14418690-id-2812380.html)
a.单节点
vgchange –a y vgXX   #激活卷组
vgchange –a n vgXX  #去激活卷组

b.cluster
vgchange –c y /dev/vgXX   #设置VG的exclusive属性,设置之后VG无法以vgchange –a y 激活
vgchange –c n /dev/vgXX   #去掉VG的exclusive属性,当然设置之后就无法用vgchange –a e来激活这个VG了。
vgchange –a e /dev/vgXX   #以exclusive模式激活卷组,只在cluster环境下有效,需要首先vgchange –c y /dev/vgXX
vgchange –a n /dev/vgXX     #在cluster模式下去激活一个VG,仍然是用这个命令。

c.shared
vgchange –c y –S y /dev/vgXX #设置VG为共享模式,设置成功后VG只能用vgchange –a s激活,如果要用vgchange –a y激活,则必须先将VG的共享模式去掉(用vgchange –S n /dev/vgxx).   #vgchange –a s /dev/vgXX #以共享方式激活VG
vgchange –a n /dev/vgXX #在共享模式下去激活方法不变

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24237320/viewspace-2104968/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/24237320/viewspace-2104968/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值