码迷,mamicode.com
首页 > 其他好文 > 详细

磁盘维护(LVM)

时间:2016-07-11 16:50:40      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

1.1       基本操作命令

注:这些命令需要root用户操作。

[root@racdb2 dev]# fdisk -l

 

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        1305    10482381   83  Linux

 

Disk /dev/sdc: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

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

 

通过fdisk -l可以看到我新增加的两块硬盘/dev/sdb/dev/sdc,其中

/dev/sdb已经将整个盘划分为一个分区,分区为/dev/sdb1

/dev/sdc没有做任何操作

 

 

创建物理卷PV(新增加的硬盘做过分区和没做过分区的都可以)

[root@racdb2 dev]# pvcreate /dev/sdc

  Physical volume "/dev/sdc" successfully created

[root@racdb2 dev]# pvcreate /dev/sdb1

  Physical volume "/dev/sdb1" successfully created

 

[root@racdb2 ~]# pvdisplay

  "/dev/sdb1" is a new physical volume of "10.00 GB"

  --- NEW Physical volume ---

  PV Name               /dev/sdb1

  VG Name              

  PV Size               10.00 GB

  Allocatable           NO

  PE Size (KByte)       0

  Total PE              0

  Free PE               0

  Allocated PE          0

  PV UUID               MJvq2Y-90D9-WRll-H0iS-D3Dk-FxQ0-XwOkgV

  

  "/dev/sdc" is a new physical volume of "10.00 GB"

  --- NEW Physical volume ---

  PV Name               /dev/sdc

  VG Name              

  PV Size               10.00 GB

  Allocatable           NO

  PE Size (KByte)       0

  Total PE              0

  Free PE               0

  Allocated PE          0

  PV UUID               f8YIH8-QeeS-9Bm5-03J7-aC7A-Jv3L-4oJWCp

  

 

创建卷组VG

[root@racdb2 dev]# vgcreate myVG /dev/sdb1 /dev/sdc

[root@racdb2 dev]# vgdisplay myVG

  --- Volume group ---

  VG Name               myVG

  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               19.99 GB

  PE Size               4.00 MB

  Total PE              5118

  Alloc PE / Size       0 / 0  

  Free  PE / Size       5118 / 19.99 GB

  VG UUID               MfR8kV-FPK8-uHCh-69Ov-U3Bv-1FGl-T6LJjc

 

创建逻辑卷LV

[root@racdb2 dev]# lvcreate -L 10G -n his01 myVG

[root@racdb2 myVG]# ll

lrwxrwxrwx 1 root root 22 05-22 11:21 his01 -> /dev/mapper/myVG-his01

[root@racdb2 ~]# lvdisplay

  --- Logical volume ---

  LV Name                /dev/myVG/his01

  VG Name                myVG

  LV UUID                KJonBk-01Zb-uWoe-Sq0N-7VLN-zz1c-EXYS3U

  LV Write Access        read/write

  LV Status              available

  # open                 0

  LV Size                10.00 GB

  Current LE             2560

  Segments               2

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:0

 

 

 

删除逻辑卷LV

[root@racdb2 ~]# lvremove /dev/myVG/his01

Do you really want to remove active logical volume his01? [y/n]: y

  Logical volume "his01" successfully removed

 

删除卷组VG

[root@racdb2 ~]# vgremove myVG

  Volume group "myVG" successfully removed

 

删除物理卷PV

[root@racdb2 ~]# pvremove /dev/sdb1

  Labels on physical volume "/dev/sdb1" successfully wiped

[root@racdb2 ~]# pvremove /dev/sdc

  Labels on physical volume "/dev/sdc" successfully wiped

 

给现有的卷组中添加物理卷

[root@racdb2 ~]# vgextend myvg /dev/sdc

  Volume group "myvg" successfully extended

[root@racdb2 ~]# vgreduce myvg /dev/sdc

  Removed "/dev/sdc" from volume group "myvg"

 

 

1.2       模拟操作场景

 

1.2.1       扩大app1空间

 

发现app1目录已经100%,无法再正常存储数据,需要扩大app1空间;  

 

 

 

[root@racdb2 app1]# df -h

 

文件系统              容量  已用可用已用% 挂载点

 

/dev/sda1              18G   14G  2.6G  85% /

 

tmpfs                 1.5G  154M  1.4G  11% /dev/shm

 

/dev/mapper/myvg-db_bak

 

                      5.0G  139M  4.6G   3% /db_bak

 

/dev/mapper/myvg-app1

 

                      9.9G  147M  0G   100% /app1

 

 

 

1)检查VG里面是否还有多余的空间可以利用

 

[root@racdb2 app1]# vgdisplay

 

  --- Volume group ---

 

  VG Name               myvg

 

  System ID            

 

  Format                lvm2

 

  Metadata Areas        3

 

  Metadata Sequence No  9

 

  VG Access             read/write

 

  VG Status             resizable

 

  MAX LV                0

 

  Cur LV                7

 

  Open LV               2

 

  Max PV                0

 

  Cur PV                3

 

  Act PV                3

 

  VG Size               29.99 GB

 

  PE Size               4.00 MB

 

  Total PE              7677

 

  Alloc PE / Size       3865 / 15.10 GB

 

  Free  PE / Size       3812 / 14.89 GB

 

  VG UUID               4CehT9-tzot-AkJW-yNRp-NFTx-SnPm-2BPSUI

 

 

 

  myvg总共有30G的空间,已经使用了15G,还有15G可以利用。

 

 

 

[root@racdb2 app1]# umount -l /dev/myvg/app1

 

 

 

2)使用命令lvextend -L|--size +逻辑卷大小增量逻辑卷全路径名

 

[root@racdb2 app1]# lvextend -L +3G /dev/myvg/app1

 

  Extending logical volume app1 to 13.00 GB

 

  Logical volume app1 successfully resized

 

 

 

[root@racdb2 app1]# lvdisplay /dev/myvg/app1

 

  --- Logical volume ---

 

  LV Name                /dev/myvg/app1

 

  VG Name                myvg

 

  LV UUID                RkVYoo-3R5r-4s7A-jTpI-9jkS-W7y4-Oekmgm

 

  LV Write Access        read/write

 

  LV Status              available

 

  # open                 1

 

  LV Size                13.00 GB

 

  Current LE             3328

 

  Segments               2

 

  Allocation             inherit

 

  Read ahead sectors     auto

 

  - currently set to     256

 

  Block device           253:6

 

 

 

3)强行检查磁盘

 

[root@racdb2 ~]# e2fsck -f /dev/myvg/app1

 

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/myvg/app1: 11/1048576 files (9.1% non-contiguous), 70321/2097152 blocks

 

 

 

4)重新定义磁盘

 

[root@racdb2 app1]# resize2fs /dev/myvg/app1

 

resize2fs 1.39 (29-May-2006)

 

Filesystem at /dev/myvg/app1 is mounted on /app1; on-line resizing required

 

Performing an on-line resize of /dev/myvg/app1 to 3407872 (4k) blocks.

 

The filesystem on /dev/myvg/app1 is now 3407872 blocks long.

 

 

 

5)挂载磁盘

 

[root@racdb2 app1]#mount /dev/myvg/app1

 

 

 

--查看已经成功增加

 

[root@racdb2 app1]# df -h

 

文件系统              容量  已用可用已用% 挂载点

 

/dev/sda1              18G   14G  2.6G  85% /

 

tmpfs                 1.5G  154M  1.4G  11% /dev/shm

 

/dev/mapper/myvg-db_bak

 

                      5.0G  139M  4.6G   3% /db_bak

 

/dev/mapper/myvg-app1

 

                       13G  149M   13G   2% /app1

 

 

 

1.2.2       虚拟机增加硬盘空间提供给数据库

 

例如从300G增加成400G

 

1、先删除VG,系统提示是否删除LV,选择是

 

2、删除PV

 

3、创建PV PV变成400G

 

4、创建VGLV,直到原来的LV数量后,

 

5、激活chunks 例如:onspaces-s <spacename> -p <path> -o <offset> -O -y

 

6、多余的空间增加LV,并增加到表空间

 

 

 

1.2.3       给虚拟机增加空间

 

1)给虚拟机增加一块磁盘

 

 

 

2)重启虚拟机

 

3fdisk -l 看一下,例如新增的磁盘是/dev/sdb

 

4)创建物理卷PV,执行pvcreate /dev/sdb

 

 

 

5vgdisplaypvdisplay 分别查看一下

 

 

 

 

 

6)给现有的卷组中添加物理卷 vgextend vghome /dev/sdb

 

 

 

7)这个时候我们看vghome已经扩大了,lvdisplay命名查看我们要扩展哪个LV

 

 

 

8)使用命令lvextend -L|--size +逻辑卷大小增量逻辑卷全路径名

 

lvextend -L +30G /dev/vghome/lv_home   

 

先添加了30G,原本是追加的50G磁盘,VG还剩余约20G没有使用。

 

 

 

9)强行检查磁盘e2fsck -f /dev/vghome/lv_home

 

需要一点儿时间,选择y就行。

 

 

 

10)重新定义磁盘 resize2fs /dev/vghome/lv_home

 

等待执行完成,再df -h 看一下,这个时候50G了,扩展了30G(记住此时我们还有20G空间没用,在VG里,下次可以拿来一用,参见“扩大app1空间”)

 

 

 

磁盘维护(LVM)

标签:

原文地址:http://www.cnblogs.com/tobyHome/p/5660664.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!