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

Centos7配置LVM

时间:2018-03-09 13:16:58      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:centos   lvm   


1     创建一个10G的VG

1.1   创建物理卷

1.2   物理卷精简显示

1.3   创建卷组

1.4   创建逻辑卷

1.5   格式化逻辑卷

1.6   缩减卷组大小

1.7   扩展卷组

1.8   动态扩展逻辑卷

1.9   检测文件系统

1     创建一个10G的VG

[root@doc1 ~]# fdisk -l

Disk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@doc1 ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0x60f5244b.

 

Command (m for help): n

Partition type:

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Select (default p):   

Using default response p

Partition number (1-4, default 1):

First sector (2048-62914559, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559): +5G

Partition 1 of type Linux and of size 5 GiB is set

 

Command (m for help): n

Partition type:

   p   primary (1 primary, 0 extended, 3 free)

   e   extended

Select (default p):

Using default response p

Partition number (2-4, default 2):

First sector (10487808-62914559, default 10487808):

Using default value 10487808

Last sector, +sectors or +size{K,M,G} (10487808-62914559, default 62914559): +5G

Partition 2 of type Linux and of size 5 GiB is set

 

Command (m for help): p

 

Disk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x60f5244b

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    10487807     5242880   83  Linux

/dev/sdb2        10487808    20973567     5242880   83  Linux

 

查看分区类型

Command (m for help): L 

 

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris       

 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-

 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-

 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-

 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx        

 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data   

 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .

 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility  

 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt        

 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access    

 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O       

 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor     

 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs       

 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT           

 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/

10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b

11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor     

12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor     

14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary 

16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS   

17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE

18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto

1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep       

1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT           

1e  Hidden W95 FAT1 80  Old Minix      

 

调整两个分区类型为lvm

Command (m for help): t

Partition number (1,2, default 2): 1

Hex code (type L to list all codes): 8e  

Changed type of partition 'Linux' to 'Linux LVM'

 

Command (m for help): t

Partition number (1,2, default 2):

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'

 

在创建一个2G分区

Command (m for help): n

Partition type:

   p   primary (2 primary, 0 extended, 2 free)

   e   extended

Select (default p):

Using default response p

Partition number (3,4, default 3):

First sector (20973568-62914559, default 20973568):

Using default value 20973568

Last sector, +sectors or +size{K,M,G} (20973568-62914559, default 62914559): +2G

Partition 3 of type Linux and of size 2 GiB is set

 

Command (m for help): t

Partition number (1-3, default 3):

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'

 

Command (m for help): p

 

Disk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x60f5244b

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    10487807     5242880   8e  Linux LVM

/dev/sdb2        10487808    20973567     5242880   8e  Linux LVM

/dev/sdb3        20973568    25167871     2097152   8e  Linux LVM

 

保存配置

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

1.1   创建物理卷

[root@doc1 ~]# partprobe /dev/sdb

[root@doc1 ~]# pvcreate /dev/sdb1 /dev/sdb2

Physical volume "/dev/sdb1" successfully created

Physical volume "/dev/sdb2" successfully created

[root@doc1 ~]# pvdisplay

--- Physical volume ---

  PV Name               /dev/sda2

  VG Name               centos

  PV Size               49.51 GiB / not usable 3.00 MiB

  Allocatable           yes

  PE Size               4.00 MiB

  Total PE              12674

  Free PE               11

  Allocated PE          12663

  PV UUID               eXf62L-tRTW-Ojzq-WbY5-eRy0-xqaE-v24PDm

  

  "/dev/sdb2" is a new physical volume of "5.00 GiB"

  --- NEW Physical volume ---

  PV Name               /dev/sdb2

  VG Name              

  PV Size               5.00 GiB

  Allocatable           NO

  PE Size               0  

  Total PE              0

  Free PE               0

  Allocated PE          0

  PV UUID               TiT7CB-bAlz-JTmK-5LWp-gEfY-1VF0-vvZFtF

  

  "/dev/sdb1" is a new physical volume of "5.00 GiB"

  --- NEW Physical volume ---

  PV Name               /dev/sdb1

  VG Name              

  PV Size               5.00 GiB

  Allocatable           NO

  PE Size               0   

  Total PE              0

  Free PE               0

  Allocated PE          0

  PV UUID               vkvXIH-3zkk-Y2Pi-pq3v-VaVT-y6xR-LLdlmk

只有在将物理卷添加到卷组之后才会显示PE大小

1.2   物理卷精简显示

[root@doc1 ~]# pvs

PV         VG     Fmt  Attr PSize  PFree

  /dev/sda2  centos lvm2 a--  49.51g 44.00m

  /dev/sdb1         lvm2 ---   5.00g  5.00g

  /dev/sdb2         lvm2 ---   5.00g  5.00g

1.3   创建卷组

指定pe大小,创建卷组

[root@doc1 ~]# vgcreate -s 8m datavg /dev/sdb{1,2}

Volume group "datavg" successfully created

[root@doc1 ~]# vgdisplay

--- Volume group ---

  VG Name               datavg

  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               9.98 GiB

  PE Size               8.00 MiB

  Total PE              1278

  Alloc PE / Size       0 / 0  

  Free  PE / Size       1278 / 9.98 GiB

  VG UUID               pOYM3Z-rNzR-ygs1-PMvM-0eEX-Dn6p-LmyBjt

  

  --- Volume group ---

  VG Name               centos

  System ID            

  Format                lvm2

  Metadata Areas        1

  Metadata Sequence No  3

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                2

  Open LV               2

  Max PV                0

  Cur PV                1

  Act PV                1

  VG Size               49.51 GiB

  PE Size               4.00 MiB

  Total PE              12674

  Alloc PE / Size       12663 / 49.46 GiB

  Free  PE / Size       11 / 44.00 MiB

  VG UUID               tcR5Tq-O3NV-SCwI-ZcR0-3HXb-l4HA-N7MF15

[root@doc1 ~]# vgdisplay datavg

--- Volume group ---

  VG Name               datavg

  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               9.98 GiB

  PE Size               8.00 MiB

  Total PE              1278

  Alloc PE / Size       0 / 0  

  Free  PE / Size       1278 / 9.98 GiB

  VG UUID               pOYM3Z-rNzR-ygs1-PMvM-0eEX-Dn6p-LmyBjt

[root@doc1 ~]# vgs

VG     #PV #LV #SN Attr   VSize  VFree

  centos   1   2   0 wz--n- 49.51g 44.00m

  datavg   2   0   0 wz--n-  9.98g  9.98g

1.4   创建逻辑卷

[root@doc1 ~]# lvcreate -L 500M -n lv_data datavg

Rounding up size to full physical extent 504.00 MiB

  Logical volume "lv_data" created.

[root@doc1 ~]# lvdisplay

--- Logical volume ---

  LV Path                /dev/datavg/lv_data

  LV Name                lv_data

  VG Name                datavg

  LV UUID                n11ATC-vqSk-Ablf-dkd9-NGHj-Hjt4-y38xj8

  LV Write Access        read/write

  LV Creation host, time doc1, 2017-11-03 21:47:17 +0800

  LV Status              available

  # open                 0

  LV Size                504.00 MiB

  Current LE             63

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:2

  

  --- Logical volume ---

  LV Path                /dev/centos/swap

  LV Name                swap

  VG Name                centos

  LV UUID                QvLRUj-8uZ4-y6al-0P1T-puu4-nePO-T5B3n4

  LV Write Access        read/write

  LV Creation host, time localhost, 2017-09-19 20:08:42 +0800

  LV Status              available

  # open                 2

  LV Size                2.00 GiB

  Current LE             512

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:1

  

  --- Logical volume ---

  LV Path                /dev/centos/root

  LV Name                root

  VG Name                centos

  LV UUID                Tt3SZD-ceBH-oQKN-yCf9-0w2L-VX45-Db1vh7

  LV Write Access        read/write

  LV Creation host, time localhost, 2017-09-19 20:08:43 +0800

  LV Status              available

  # open                 1

  LV Size                47.46 GiB

  Current LE             12151

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:0

[root@doc1 ~]# ll /dev/datavg/lv_data

lrwxrwxrwx 1 root root 7 Nov  3 21:47 /dev/datavg/lv_data -> ../dm-2

[root@doc1 ~]# lvs

LV      VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  root    centos -wi-ao----  47.46g                                                   

  swap    centos -wi-ao----   2.00g                                                   

  lv_data datavg -wi-a----- 504.00m

1.5   格式化逻辑卷

[root@doc1 ~]# mkfs.xfs /dev/datavg/lv_data

meta-data=/dev/datavg/lv_data    isize=256    agcount=4, agsize=32256 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0        finobt=0

data     =                       bsize=4096   blocks=129024, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

log      =internal log           bsize=4096   blocks=853, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@doc1 ~]# mount /dev/datavg/lv_data /mnt

[root@doc1 ~]# df -lh

Filesystem                  Size  Used Avail Use% Mounted on

/dev/mapper/centos-root      48G  1.3G   47G   3% /

devtmpfs                    910M     0  910M   0% /dev

tmpfs                       921M     0  921M   0% /dev/shm

tmpfs                       921M  8.5M  912M   1% /run

tmpfs                       921M     0  921M   0% /sys/fs/cgroup

/dev/sda1                   497M  125M  373M  26% /boot

tmpfs                       185M     0  185M   0% /run/user/0

/dev/mapper/datavg-lv_data  501M   26M  476M   6% /mnt

[root@doc1 ~]# cp /etc/rc.d/init.d/functions /mnt

[root@doc1 ~]# ls /mnt

functions

1.6   缩减卷组大小

[root@doc1 ~]# vgdisplay datavg

--- Volume group ---

  VG Name               datavg

  System ID            

  Format                lvm2

  Metadata Areas        2

  Metadata Sequence No  2

  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               9.98 GiB

  PE Size               8.00 MiB

  Total PE              1278

  Alloc PE / Size       63 / 504.00 MiB

  Free  PE / Size       1215 / 9.49 GiB

  VG UUID               pOYM3Z-rNzR-ygs1-PMvM-0eEX-Dn6p-LmyBjt

查看pv使用情况

[root@doc1 ~]# pvs

PV         VG     Fmt  Attr PSize  PFree

  /dev/sda2  centos lvm2 a--  49.51g 44.00m

  /dev/sdb1  datavg lvm2 a--   4.99g  4.50g       空间减少,说明lv在此pv

  /dev/sdb2  datavg lvm2 a--   4.99g  4.99g

移除卷组中/dev/sdb2物理卷设备减少卷组空间,先要将物理卷数据转移

[root@doc1 ~]# pvmove /dev/sdb2

No data to move for datavg

[root@doc1 ~]# vgreduce datavg /dev/sdb2

Removed "/dev/sdb2" from volume group "datavg"

[root@doc1 ~]# vgs

VG     #PV #LV #SN Attr   VSize  VFree

  centos   1   2   0 wz--n- 49.51g 44.00m

  datavg   1   1   0 wz--n-  4.99g  4.50g      空间已减小

[root@doc1 ~]# pvremove /dev/sdb2

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

[root@doc1 ~]# pvs

PV         VG     Fmt  Attr PSize  PFree

  /dev/sda2  centos lvm2 a--  49.51g 44.00m

  /dev/sdb1  datavg lvm2 a--   4.99g  4.50g

1.7   扩展卷组

[root@doc1 ~]# pvcreate /dev/sdb3

Physical volume "/dev/sdb3" successfully created

[root@doc1 ~]# pvs

PV         VG     Fmt  Attr PSize  PFree

  /dev/sda2  centos lvm2 a--  49.51g 44.00m

  /dev/sdb1  datavg lvm2 a--   4.99g  4.50g

  /dev/sdb3         lvm2 ---   2.00g  2.00g

[root@doc1 ~]# vgextend datavg /dev/sdb3

Volume group "datavg" successfully extended

[root@doc1 ~]# vgs

VG     #PV #LV #SN Attr   VSize  VFree

  centos   1   2   0 wz--n- 49.51g 44.00m

  datavg   2   1   0 wz--n-  6.98g  6.49g

[root@doc1 ~]# pvs

PV         VG     Fmt  Attr PSize  PFree

  /dev/sda2  centos lvm2 a--  49.51g 44.00m

  /dev/sdb1  datavg lvm2 a--   4.99g  4.50g

  /dev/sdb3  datavg lvm2 a--   1.99g  1.99g

[root@doc1 ~]# pvdisplay /dev/sdb3

--- Physical volume ---

  PV Name               /dev/sdb3

  VG Name               datavg

  PV Size               2.00 GiB / not usable 8.00 MiB

  Allocatable           yes

  PE Size               8.00 MiB

  Total PE              255

  Free PE               255

  Allocated PE          0

  PV UUID               PDtYcJ-ksBr-QPWe-7Z5M-e0hY-Uxca-MU1B2p

1.8   动态扩展逻辑卷

-L为扩展到的容量,+为扩展的容量

[root@doc1 ~]# lvextend -L 1G /dev/datavg/lv_data

Size of logical volume datavg/lv_data changed from 504.00 MiB (63 extents) to 1.00 GiB (128 extents).

  Logical volume lv_data successfully resized.

[root@doc1 ~]# lvs

LV      VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  root    centos -wi-ao---- 47.46g                                                    

  swap    centos -wi-ao----  2.00g                                                   

  lv_data datavg -wi-ao----  1.00g   

[root@doc1 ~]# mount

/dev/mapper/datavg-lv_data on /mnt type xfs (rw,relatime,attr2,inode64,noquota)

[root@doc1 ~]# ls /mnt

functions

[root@doc1 ~]# df -lPh

Filesystem                  Size  Used Avail Use% Mounted on

/dev/mapper/centos-root      48G  1.3G   47G   3% /

devtmpfs                    910M     0  910M   0% /dev

tmpfs                       921M     0  921M   0% /dev/shm

tmpfs                       921M  8.5M  912M   1% /run

tmpfs                       921M     0  921M   0% /sys/fs/cgroup

/dev/sda1                   497M  125M  373M  26% /boot

tmpfs                       185M     0  185M   0% /run/user/0

/dev/mapper/datavg-lv_data  501M   26M  476M   6% /mnt     不是1G

扩展逻辑边界,到物理边界

[root@doc1 ~]# resize2fs /dev/datavg/lv_data      ##centos6

[root@doc1 ~]# xfs_growfs /dev/datavg/lv_data     ##centos7

meta-data=/dev/mapper/datavg-lv_data isize=256    agcount=4, agsize=32256 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0        finobt=0

data     =                       bsize=4096   blocks=129024, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

log      =internal               bsize=4096   blocks=853, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

data blocks changed from 129024 to 262144

[root@doc1 ~]# df -lPh

Filesystem                  Size  Used Avail Use% Mounted on

/dev/mapper/centos-root      48G  1.3G   47G   3% /

devtmpfs                    910M     0  910M   0% /dev

tmpfs                       921M     0  921M   0% /dev/shm

tmpfs                       921M  8.5M  912M   1% /run

tmpfs                       921M     0  921M   0% /sys/fs/cgroup

/dev/sda1                   497M  125M  373M  26% /boot

tmpfs                       185M     0  185M   0% /run/user/0

/dev/mapper/datavg-lv_data 1021M   26M  996M   3% /mnt

1.9   检测文件系统

root@doc1 ~]# e2fsck -f /dev/datavg/lv_data      #centos6

[root@doc1 ~]# xfs_repair /dev/datavg/lv_data     #centos7

Phase 1 - find and verify superblock...

Phase 2 - using internal log

        - zero log...

        - scan filesystem freespace and inode maps...

        - found root inode chunk

Phase 3 - for each AG...

        - scan and clear agi unlinked lists...

        - process known inodes and perform inode discovery...

        - agno = 0

        - agno = 1

        - agno = 2

        - agno = 3

        - agno = 4

        - agno = 5

        - agno = 6

        - agno = 7

        - agno = 8

        - process newly discovered inodes...

Phase 4 - check for duplicate blocks...

        - setting up duplicate extent list...

        - check for inodes claiming duplicate blocks...

        - agno = 0

        - agno = 1

        - agno = 2

        - agno = 3

        - agno = 4

        - agno = 5

        - agno = 6

        - agno = 7

        - agno = 8

Phase 5 - rebuild AG headers and trees...

        - reset superblock...

Phase 6 - check inode connectivity...

        - resetting contents of realtime bitmap and summary inodes

        - traversing filesystem ...

        - traversal finished ...

        - moving disconnected inodes to lost+found ...

Phase 7 - verify and correct link counts...

done

[root@doc1 ~]# resize2fs /dev/datavg/lv_data 200M     #centos6

[root@doc1 ~]# lvreduce -L 200M /dev/datavg/lv_data   #centos7

WARNING: Reducing active logical volume to 200.00 MiB

  THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce lv_data? [y/n]: y

  Size of logical volume datavg/lv_data changed from 1.00 GiB (128 extents) to 200.00 MiB (25 extents).

  Logical volume lv_data successfully resized.

[root@doc1 ~]# lvs

LV      VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  root    centos -wi-ao----  47.46g                                                   

  swap    centos -wi-ao----   2.00g                                                   

  lv_data datavg -wi-a----- 200.00m 

 


Centos7配置LVM

标签:centos   lvm   

原文地址:http://blog.51cto.com/11199460/2084526

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