linux下卷组管理

1、首先通过fdisk -l查看当前存在的物理磁盘

[root@rac1 work]# fdisk -l

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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        2610    20860402+  8e  Linux LVM

Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Disk /dev/sdc doesn't contain a valid partition table

2、使用pvcreate创建PV物理分区(可以pvcreate /dev/sdb /dev/sdd同时创建多个PV)

[root@rac1 work]# pvcreate /dev/sdd
  Physical volume "/dev/sdd" successfully created

3、PV创建成功,可以是用pvscan和pvdisplay进行查询当前PV状况

[root@rac1 work]# pvscan
  PV /dev/sdb    VG vg01         lvm2 [508.00 MB / 8.00 MB free]
  PV /dev/sdc    VG vg01         lvm2 [508.00 MB / 508.00 MB free]
  PV /dev/sdd    VG vg01         lvm2 [508.00 MB / 508.00 MB free]
  PV /dev/sda2   VG VolGroup00   lvm2 [19.88 GB / 0    free]
  PV /dev/sde                    lvm2 [512.00 MB]
  PV /dev/sdf                    lvm2 [512.00 MB]
  Total: 6 [22.36 GB] / in use: 4 [21.36 GB] / in no VG: 2 [1.00 GB]

4、通过vgscan和vgdisplay查询当前VG信息

[root@rac1 work]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "vg01" using metadata type lvm2
  Found volume group "VolGroup00" using metadata type lvm2
[root@rac1 work]# vgdisplay
  --- Volume group ---
  VG Name               vg01
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               1.49 GB
  PE Size               4.00 MB
  Total PE              381
  Alloc PE / Size       125 / 500.00 MB
  Free  PE / Size       256 / 1.00 GB
  VG UUID               tBqgwY-7PdL-I1B0-JsXP-240U-MMN0-zviktm

5、使用vgcreate创建卷组

[root@rac1 work]#vgcreate vg1 /dev/sdb
                #vgcreate vg2 /dev/sdc
                #vgscan
                #vgdisplay

6、vgextend扩充卷组

[root@rac1 work]# vgextend vg01 /dev/sde 
  Volume group "vg01" successfully extended

[root@rac1 work]# pvscan
  PV /dev/sdb    VG vg01         lvm2 [508.00 MB / 8.00 MB free]
  PV /dev/sdc    VG vg01         lvm2 [508.00 MB / 508.00 MB free]
  PV /dev/sdd    VG vg01         lvm2 [508.00 MB / 508.00 MB free]
  PV /dev/sde    VG vg01         lvm2 [508.00 MB / 508.00 MB free]
  PV /dev/sdf    VG vg01         lvm2 [508.00 MB / 508.00 MB free]
  PV /dev/sda2   VG VolGroup00   lvm2 [19.88 GB / 0    free]
  Total: 6 [22.36 GB] / in use: 6 [22.36 GB] / in no VG: 0 [0   ]

7、lvcreate创建逻辑卷(分别创建work和study两个逻辑卷)

    #lvcreate -L 1200M -n oracle  oravg
    #lvcreate -L 500M -n study vg2
    #lvscan
    #lvdisplay
 --- Logical volume ---
  LV Name                /dev/vg2/study
  VG Name                vg2
  LV UUID                53VT9v-dyp0-lSST-eDFz-w2Ns-Os0Z-ERnqVU
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size            500.00 MB
  Current LE         125
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

8、lvextend增加减少LV大小

[root@rac1 work]# lvextend -L +100M /dev/vg01/lv11
  Extending logical volume lv11 to 800.00 MB
  Logical volume lv11 successfully resized

9、 删除逻辑卷-卷组-物理卷 (必需按照先后顺序来执行删除) 
#lvremove /dev/vg0/vg1 删除逻辑卷 
a、先卸载目录挂载 umount
使用lvchange -a n /dev/vg01/lv11更改lv在线状态
[root@rac1 ~]# lvscan
  ACTIVE   Original '/dev/vg01/lv11' [800.00 MB] inherit
  ACTIVE   Snapshot '/dev/vg01/kuaizhao' [12.00 MB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol00' [17.94 GB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol01' [1.94 GB] inherit
[root@rac1 ~]# lvchange -a n /dev/vg01/lv11
[root@rac1 ~]# lvscan
  inactive Original '/dev/vg01/lv11' [800.00 MB] inherit
  inactive Snapshot '/dev/vg01/kuaizhao' [12.00 MB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol00' [17.94 GB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol01' [1.94 GB] inherit

b、如果删除不了,要先确认是否已经做过快照(snapshot),先删除快照

#vgremove /dev/vg0 删除卷组 
这里有一个问题,如果建立的卷组是活动的,他就不能删除 
这里需要使用一个命令来是他变成固定的,以便删除 
#vgchage -a n /dev/vg0 
-a 参数指定卷组是否是活动的,n表示固定,y表示活动 
#vgremove /dev/vg0  
成功 
物理卷的删除,移除/etc下的lvmconf 和lvmtab的两个文件,然后将分区转换为linux的就可以了 




10、 分区格式化

#mkfs.ext3 /dev/vg1/work         //或 #mkfs -j /dev/vg1/work
#mkfs.ext3 /dev/vg2/study        //...
#df–l

Disk /dev/hda:8589 MB,8589934592 bytes
255 heads,63 sectors/track,1044 cylinders
Units=cylindersof16065*512=8225280 bytes
 
  Device Boot Start End  Blocks   Id System
/dev/hda1*    1    32   257008+  83  Linux
/dev/hda2     33    97   522112+  83  Linux
/dev/hda3     98    358  2096482+83  Linux
/dev/hda4     359   1044 5510295  5  Extended
/dev/hda5     359   549  1534176  83  Linux
/dev/hda6     550   848  2401686  83  Linux
/dev/hda7     849   913  522081   82  Linux swap / Solaris
/dev/hda8     914   978  522081   83  Linux
/dev/hda9     979   1043 522081   83  Linux


11、挂载新分区

#mkdir../home/work../home/study
#mount../dev/vg1/work../home/work
#mount../dev/vg2/study../home/study
#df–Th

Filesystem  Type SizeUsed Avail Use% Mounted on
/dev/hda2   ext3 494M 212M 257M  46%   /
/dev/hda9   ext3 494M 45M 425M   10%   /var
/dev/hda8   ext3 494M 11M 458M   3%    /opt
/dev/hda6   ext3 2.3G 68M 2.1G   4%    /home
/dev/hda3   ext3 2.0G 1.7G 182M  91%   /usr
/dev/hda5   ext3 1.5G 35M 1.4G   3%    /usr/local
/dev/hda1   ext3 244M 12M 219M   6%    /boot
tmpfs       tmpfs 125M 0  125M   0%    /dev/shm


/dev/mapper/vg1-work
            ext3  485M 11M 449M  3%    /home/work
/dev/mapper/vg2-study
            ext3  485M 11M 449M  3%    /home/study









本文转自 hsbxxl 51CTO博客,原文链接:http://blog.51cto.com/hsbxxl/813595,如需转载请自行联系原作者

你可能感兴趣的:(linux下卷组管理)