ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Linux LVM管理

Linux LVM管理

原创 Linux操作系统 作者:DBA_oracle_java 时间:2013-07-09 22:46:18 0 删除 编辑
1.前期准备
1.1 添加三块新的硬盘
1.2 fdisk格式化这三块硬盘,因为做LVM,所以文件系统为LVM,格式化完之后,输入t(change a partition's system id)更改
[root@RHEL5 ~]# fdisk /dev/sdb
[root@RHEL5 ~]# fdisk /dev/sdc
[root@RHEL5 ~]# fdisk /dev/sdd
[root@RHEL5 ~]# fdisk -l

[root@RHEL5 ~]# fdisk -l

Disk /dev/sda: 26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        3002    24113533+  83  Linux
/dev/sda2            3003        3263     2096482+  82  Linux swap / Solaris

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          62      497983+  8e  Linux LVM
/dev/sdb2              63         130      546210   8e  Linux LVM

Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         130     1044193+  8e  Linux LVM

Disk /dev/sdd: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         130     1044193+  8e  Linux LVM



2.创建物理卷
[root@RHEL5 ~]# partprobe 
[ root@RHEL5 ~]# vgscan   -----先进行卷组扫描,生成逻辑卷所需要的文件)
  Reading all physical volumes.  This may take a while...
[root@RHEL5 ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
[root@RHEL5 ~]# pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created
[root@RHEL5 ~]# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created
[root@RHEL5 ~]# pvcreate /dev/sdd1
  Physical volume "/dev/sdd1" successfully created
[root@RHEL5 ~]# pvscan
  PV /dev/sdb1                      lvm2 [486.31 MB]
   PV /dev/sdb2                      lvm2 [533.41 MB]
   PV /dev/sdc1                      lvm2 [1019.72 MB]
   PV /dev/sdd1                      lvm2 [1019.72 MB]
   Total: 4 [2.99 GB] / in use: 0 [0   ] / in no VG: 4 [2.99 GB]
  
3.创建卷组
[root@RHEL5 ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2 /dev/sdc1
  Volume group "vg1" successfully created
[root@RHEL5 ~]# vgdisplay 
 
  
4.增减卷组
##需要注意的是,以下的操作必须是卷组没有划分逻辑卷的前提下才可以
[root@RHEL5 network-scripts]# vgextend vg1 /dev/sdd1                     ---将PV /dev/sdd1加入卷组vg1中
  Volume group "vg1" successfully extended
  [root@RHEL5 network-scripts]# pvscan
  PV /dev/sdb1   VG vg1   lvm2 [1016.00 MB / 1016.00 MB free]
  PV /dev/sdc1   VG vg1   lvm2 [1016.00 MB / 1016.00 MB free]
  PV /dev/sdd1   VG vg1   lvm2 [1016.00 MB / 1016.00 MB free]
  Total: 3 [2.98 GB] / in use: 3 [2.98 GB] / in no VG: 0 [0   ]
  
  [root@RHEL5 network-scripts]# vgdisplay
   --- Volume group ---
  VG Name               vg1
  System ID             
  Format                lvm2
  Metadata Areas        3
  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                3
  Act PV                3
  VG Size               1.98 GB
  PE Size               4.00 MB
  Total PE              508
  Alloc PE / Size       0 / 0   
  Free  PE / Size       508 / 1.98 GB
  VG UUID               iv2mo0-x5Ky-KP1v-HJ2i-HCU9-qooV-wzNdzf
  
  [root@RHEL5 ~]# pvscan 
  PV /dev/sdb1   VG vg1             lvm2 [484.00 MB / 484.00 MB free]
  PV /dev/sdb2   VG vg1             lvm2 [532.00 MB / 532.00 MB free]
  PV /dev/sdc1   VG vg1             lvm2 [1016.00 MB / 1016.00 MB free]
  PV /dev/sdd1                      lvm2 [1019.72 MB]
  
  ###以下步聚操作,必须是卷组未划分逻辑卷的前提下才可增减卷组的物理卷
  [root@RHEL5 network-scripts]# vgreduce vg1 /dev/sdc1  -----将PV /dev/sdc1脱离卷组vg1
  Removed "/dev/sdc1" from volume group "vg1"
  
  [root@RHEL5 ~]# vgextend vg1 /dev/sdd1 -------将PV /dev/sdd1加入卷组vg1
  Volume group "vg1" successfully extended
  
  [root@RHEL5 ~]# pvscan 
  PV /dev/sdb1   VG vg1             lvm2 [484.00 MB / 484.00 MB free]
  PV /dev/sdb2   VG vg1             lvm2 [532.00 MB / 532.00 MB free]
  PV /dev/sdd1   VG vg1             lvm2 [1016.00 MB / 1016.00 MB free]
  PV /dev/sdc1                      lvm2 [1019.72 MB]
  Total: 4 [2.98 GB] / in use: 3 [1.98 GB] / in no VG: 1 [1019.72 MB]
  
  [root@RHEL5 network-scripts]# vgchange -a n vg1                       ----将卷组vg1的激活状态关闭
  0 logical volume(s) in volume group "vg1" now active
  
  [root@RHEL5 network-scripts]# vgchange -a y vg1 ----激活vg1
  0 logical volume(s) in volume group "vg1" now active
  
  [root@RHEL5 network-scripts]# vgremove vg1 -----删除卷组vg1
  Volume group "vg1" successfully removed
  
  
  
5.创建逻辑卷
 [root@RHEL5 ~]# lvcreate -L 1G -n lv1 vg1    ---在卷组vg1 中创建逻辑卷lv1
  Logical volume "lv1" created
  
  [root@RHEL5 ~]# lvscan ----查看逻辑卷状态
    ACTIVE            '/dev/vg1/lv1' [1.00 GB] inherit
  
  [root@RHEL5 ~]# mkfs.ext3 /dev/vg1/lv1   ---格式化逻辑卷
  
  [root@RHEL5 ~]# mkdir /lv1 ---创建挂载点
  
 [root@RHEL5 ~]# mount /dev/vg1/lv1 /lv1/ --moun逻辑卷到/lv1挂载点
 [root@RHEL5 ~]# df -lh ----查看挂载情况
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              23G  7.3G   14G  35% /
tmpfs                 506M     0  506M   0% /dev/shm
/dev/mapper/vg1-lv1  1008M   34M  924M   4% /lv1
[root@RHEL5 ~]# more /etc/fstab 
LABEL=/                 /                       ext3    defaults        1 1
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP-sda2         swap                    swap    defaults        0 0

/dev/mapper/vg1-lv1     /ORADATA                ext3    defaults        1 2
6. 在不损坏现有数据的情况下,动态调整分区大小
[root@RHEL5 ~]# lvextend -L +500M /dev/vg1/lv1 
  Extending logical volume lv1 to 2.50 GB
  Logical volume lv1 successfully resized
  
[root@RHEL5 ORADATA]# resize2fs /dev/vg1/lv1 
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vg1/lv1 is mounted on /lv1; on-line resizing required
Performing an on-line resize of /dev/vg1/lv1 to 656384 (4k) blocks.
The filesystem on /dev/vg1/lv1 is now 656384 blocks long.

[root@RHEL5 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              23G  7.1G   15G  34% /
tmpfs                 506M     0  506M   0% /dev/shm
/dev/mapper/vg1-lv1   2.5G  204M  2.2G   9% /lv1
/dev/mapper/vg1-lv1   2.5G  204M  2.2G   9% /ORADATA


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

请登录后发表评论 登录
全部评论

注册时间:2013-07-02

  • 博文量
    31
  • 访问量
    116880