回忆之城
生命在于折腾
posts - 575,comments - 9,trackbacks - 0

lvextend

lvextend指令:扩展逻辑卷空间

【语    法】lvextend [选项] [参数]

【功能介绍】lvextend指令用于在线扩展逻辑卷的空间大小,而不中断应用程序对逻辑卷的访问。

主要参数

-L 指定逻辑卷的大小,单位为“kKmMgGtT”字节
-l 指定逻辑卷的大小(LE数)

磁盘信息

[root@www ~]# fdisk -l
Disk /dev/hda: 41.1 GB, 41174138880 bytes
255 heads, 63 sectors/track, 5005 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        1288    10241437+  83  Linux
/dev/hda3            1289        1925     5116702+  83  Linux
/dev/hda4            1926        5005    24740100    5  Extended
/dev/hda5            1926        2052     1020096   82  Linux swap / Solaris
/dev/hda6            2053        2235     1469916   8e  Linux LVM
/dev/hda7            2236        2418     1469916   8e  Linux LVM
/dev/hda8            2419        2601     1469916   8e  Linux LVM
/dev/hda9            2602        2784     1469916   8e  Linux LVM

LV阶段,逻辑卷操作

[root@www ~]# pvscan   #有三个 PV 被用去,剩下一个 /dev/hda9 的 PV 沒被用掉!
  PV /dev/hda6   VG vbirdvg   lvm2 [1.39 GB / 1.39 GB free]
  PV /dev/hda7   VG vbirdvg   lvm2 [1.39 GB / 1.39 GB free]
  PV /dev/hda8   VG vbirdvg   lvm2 [1.39 GB / 1.39 GB free]
  PV /dev/hda9                lvm2 [1.40 GB]
  Total: 4 [5.57 GB] / in use: 3 [4.17 GB] / in no VG: 1 [1.40 GB]

[root@www ~]# vgdisplay         # 最后那三行指的就是 PE 能够使用的情況!由于尚未切出 LV,因此所有的 PE均可自由使用。
  --- Volume group ---
  VG Name               vbirdvg
  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               4.17 GB     #整个 VG 容量就这么大
  PE Size               16.00 MB    #內部每个 PE 的大小
  Total PE              267         #总共的 PE 数量!
  Alloc PE / Size       0 / 0
  Free  PE / Size       267 / 4.17 GB
  VG UUID               4VU5Jr-gwOq-jkga-sUPx-vWPu-PmYm-dZH9EO


[root@www ~]# lvcreate -l 356 -n vbirdlv vbirdvg    #将整个 vbirdvg 通通分配給 vbirdlv 啊,要注意, PE 共有 356 个
  Logical volume "vbirdlv" created

[root@www ~]# ll /dev/vbirdvg/vbirdlv 
lrwxrwxrwx 1 root root 27 Mar 11 16:49 /dev/vbirdvg/vbirdlv -> /dev/mapper/vbirdvg-vbirdlv  # 看见了沒有啊!这就是我们最重要的一步


[root@www ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vbirdvg/vbirdlv  #LV逻辑卷的名字
  VG Name                vbirdvg
  LV UUID                8vFOPG-Jrw0-Runh-ug24-t2j7-i3nA-rPEyq0
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                5.56 GB               #LV的大小
  Current LE             356
  Segments               4
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  

格式化逻辑卷,并且挂载

[root@www ~]# mkfs -t ext3 /dev/vbirdvg/vbirdlv    #格式化

[root@www ~]# mkdir /mnt/lvm

[root@www ~]# mount /dev/vbirdvg/vbirdlv /mnt/lvm  #挂载目录

[root@www ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda2              9920624   3858984   5549572  42% /
/dev/hda3              4956316   1056996   3643488  23% /home
/dev/hda1               101086     21408     74459  23% /boot
tmpfs                   371332         0    371332   0% /dev/shm
/dev/mapper/vbirdvg-vbirdlv
                       5741020    142592   5306796   3% /mnt/lvm

增加 LV 容量

[root@www ~]# fdisk -l   
   Device Boot      Start         End      Blocks   Id  System
....(中间省略)....
/dev/hda10           2785        3150     2939863+  8e  Linux LVM   #增加一下lvm /dev/hda10

[root@www ~]# pvcreate /dev/hda10   建立新的 PV
  Physical volume "/dev/hda10" successfully created
  
[root@www ~]# pvscan     #查看PG物理卷
  PV /dev/hda6    VG vbirdvg   lvm2 [1.39 GB / 0    free]
  PV /dev/hda7    VG vbirdvg   lvm2 [1.39 GB / 0    free]
  PV /dev/hda8    VG vbirdvg   lvm2 [1.39 GB / 0    free]
  PV /dev/hda9    VG vbirdvg   lvm2 [1.39 GB / 0    free]
  PV /dev/hda10                lvm2 [2.80 GB]              # 可以看到 /dev/hda10 是新加入,尚未使用
  Total: 5 [8.37 GB] / in use: 4 [5.56 GB] / in no VG: 1 [2.80 GB]

[root@www ~]# vgextend vbirdvg /dev/hda10   #加大 VG ,利用 vgextend 功能
  Volume group "vbirdvg" successfully extended
  
[root@www ~]# vgdisplay     #查看VG逻辑卷组
  --- Volume group ---
  VG Name               vbirdvg
  System ID
  Format                lvm2
  Metadata Areas        5
  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                5
  Act PV                5
  VG Size               8.36 GB
  PE Size               16.00 MB
  Total PE              535
  Alloc PE / Size       356 / 5.56 GB
  Free  PE / Size       179 / 2.80 GB
  VG UUID               4VU5Jr-gwOq-jkga-sUPx-vWPu-PmYm-dZH9EO


[root@www ~]# lvresize -l +179 /dev/vbirdvg/vbirdlv   #利用 lvresize 的功能來增加LV
  Extending logical volume vbirdlv to 8.36 GB
  Logical volume vbirdlv successfully resized

[root@www ~]# lvdisplay       #显示LV逻辑卷
  --- Logical volume ---
  LV Name                /dev/vbirdvg/vbirdlv
  VG Name                vbirdvg
  LV UUID                8vFOPG-Jrw0-Runh-ug24-t2j7-i3nA-rPEyq0
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                8.36 GB
  Current LE             535
  Segments               5
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

[root@www ~]# df /mnt/lvm     #查看大小
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vbirdvg-vbirdlv
                       5741020    261212   5188176   5% /mnt/lvm

[root@www ~]# resize2fs /dev/vbirdvg/vbirdlv   #LV分区重设大小
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vbirdvg/vbirdlv is mounted on /mnt/lvm; on-line resizing 
Performing an on-line resize of /dev/vbirdvg/vbirdlv to 2191360 (4k) blocks.
The filesystem on /dev/vbirdvg/vbirdlv is now 2191360 blocks long.
					   

减小 LV 容量

[root@www ~]# umount /mnt/lvm    #取消挂载

[root@www ~]# e2fsck -f /dev/vbirdvg/vbirdlv  #磁盘检测
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/vbirdvg/vbirdlv: 2438/1087008 files (0.1% non-contiguous), 

[root@www ~]# resize2fs /dev/vbirdvg/vbirdlv 6900M  #重设大小
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vbirdvg/vbirdlv to 1766400 (4k) blocks.
The filesystem on /dev/vbirdvg/vbirdlv is now 1766400 blocks long.

[root@www ~]# mount /dev/vbirdvg/vbirdlv /mnt/lvm  #挂载LVM

[root@www ~]# df /mnt/lvm
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vbirdvg-vbirdlv
                       6955584    262632   6410328   4% /mnt/lvm

[root@www ~]# lvresize -l -89 /dev/vbirdvg/vbirdlv      #降低 LV 的容量
  WARNING: Reducing active and open logical volume to 6.97 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
  Do you really want to reduce vbirdlv? [y/n]: y
  Reducing logical volume vbirdlv to 6.97 GB
  Logical volume vbirdlv successfully resized
  
[root@www ~]# lvdisplay       #查看lv逻辑卷信息
  --- Logical volume ---
  LV Name                /dev/vbirdvg/vbirdlv
  VG Name                vbirdvg
  LV UUID                8vFOPG-Jrw0-Runh-ug24-t2j7-i3nA-rPEyq0
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                6.97 GB
  Current LE             446
  Segments               5
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  
[root@www ~]# pvdisplay      #先确认 /dev/hda6 是否將 PE 都移除了
  --- Physical volume ---
  PV Name               /dev/hda6
  VG Name               vbirdvg
  PV Size               1.40 GB / not usable 11.46 MB
  Allocatable           yes (but full)
  PE Size (KByte)       16384
  Total PE              89
  Free PE               0
  Allocated PE          89
  PV UUID               Z13Jk5-RCls-UJ8B-HzDa-Gesn-atku-rf2biN
....(中間省略)....

  --- Physical volume ---
  PV Name               /dev/hda10
  VG Name               vbirdvg
  PV Size               2.80 GB / not usable 6.96 MB
  Allocatable           yes
  PE Size (KByte)       16384
  Total PE              179
  Free PE               89   
  Allocated PE          90
  PV UUID               7MfcG7-y9or-0Jmb-H7RO-5Pa5-D3qB-G426Vq

[root@www ~]# pvmove /dev/hda6 /dev/hda10  #將 /dev/hda6 內的 PE 移动到 /dev/hda10

[root@www ~]# vgreduce vbirdvg /dev/hda6   #將 /dev/hda6从vbirdvg 移出
  Removed "/dev/hda6" from volume group "vbirdvg"

[root@www ~]# pvscan
  PV /dev/hda7    VG vbirdvg   lvm2 [1.39 GB / 0    free]
  PV /dev/hda8    VG vbirdvg   lvm2 [1.39 GB / 0    free]
  PV /dev/hda9    VG vbirdvg   lvm2 [1.39 GB / 0    free]
  PV /dev/hda10   VG vbirdvg   lvm2 [2.80 GB / 0    free]
  PV /dev/hda6                 lvm2 [1.40 GB]
  Total: 5 [8.37 GB] / in use: 4 [6.97 GB] / in no VG: 1 [1.40 GB]

[root@www ~]# pvremove /dev/hda6    #移出物理卷hda6
  Labels on physical volume "/dev/hda6" successfully wiped
  

快照区的建立

[root@www ~]# vgdisplay       #查看VG容量
  --- Volume group ---
  VG Name               vbirdvg
....(其他省略)....
  VG Size               6.97 GB
  PE Size               16.00 MB
  Total PE              446
  Alloc PE / Size       446 / 6.97 GB
  Free  PE / Size       0 / 0  

[root@www ~]# pvcreate /dev/hda6    #创建PV物理卷
  Physical volume "/dev/hda6" successfully created
  
[root@www ~]# vgextend vbirdvg /dev/hda6    #将刚刚移除的 /dev/hda6 加入這個 VG
  Volume group "vbirdvg" successfully extended
  
[root@www ~]# vgdisplay    #查看VG
  --- Volume group ---
  VG Name               vbirdvg
....(其他省略)....
  VG Size               8.36 GB
  PE Size               16.00 MB
  Total PE              535
  Alloc PE / Size       446 / 6.97 GB
  Free  PE / Size       89 / 1.39 GB   #多出了 89 个 可用PE

[root@www ~]# lvcreate -l 60 -s -n vbirdss /dev/vbirdvg/vbirdlv    #利用 lvcreate 建立系统快照区,命名为vbirdss,且经于 60 个 PE
  Logical volume "vbirdss" created

[root@www ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vbirdvg/vbirdss
  VG Name                vbirdvg
  LV UUID                K2tJ5E-e9mI-89Gw-hKFd-4tRU-tRKF-oeB03a
  LV Write Access        read/write
  LV snapshot status     active destination for /dev/vbirdvg/vbirdlv
  LV Status              available
  # open                 0
  LV Size                6.97 GB    #原LV的大小
  Current LE             446
  COW-table size         960.00 MB  #新建快照区的实际大小
  COW-table LE           60         #快照区占有的PE
  Allocated to snapshot  0.00%
  Snapshot chunk size    4.00 KB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

[root@www ~]# mkdir /mnt/snapshot
[root@www ~]# mount /dev/vbirdvg/vbirdss /mnt/snapshot
[root@www ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda2              9920624   3859032   5549524  42% /
/dev/hda3              4956316   1056996   3643488  23% /home
/dev/hda1               101086     21408     74459  23% /boot
tmpfs                   371332         0    371332   0% /dev/shm
/dev/mapper/vbirdvg-vbirdlv
                       6955584    262632   6410328   4% /mnt/lvm        #二个一样
/dev/mapper/vbirdvg-vbirdss
                       6955584    262632   6410328   4% /mnt/snapshot   #二个一样
posted on 2014-12-25 17:31 回忆之城 阅读(306) 评论(0)  编辑 收藏 引用 所属分类: unix/linux服务器配置
只有注册用户登录后才能发表评论。