LVM创建级管理

linux LVM 存储 磁盘

pv管理工具

  • u显示pv信息

pvs:简要pv信息显示

pvdisplay

  • u创建pv

pvcreate /dev/DEVICE

 

  •      移动pv空间中已将使用PE空间

pvmove DEVICE                                    #移动DEVICE中的已分配的PE空间自动移动到vg中空余的设备中

pvmove DEVICE1 DEVICE2       #移动DEVICE中的已分配的PE空间移动到vg中指定的设备中

 

  • pvremove DEVICE  取消设备的PV属性

 

可以使用硬盘来做pv,可以使用分区来做pv

 

本示例是以分区做pv

 

  • 示例:

1、划分分区,本次以/dev/sdb,/dev/sdc两块磁盘来做实现

[root@CentOS69 ~]#lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sr0     11:0    1  5.8G  0 rom

sda      8:0    0  100G  0 disk

├─sda1   8:1    0    1G  0 part /boot

├─sda2   8:2    0 29.3G  0 part /

├─sda3   8:3    0    3G  0 part [SWAP]

├─sda4   8:4    0    1K  0 part

└─sda5   8:5    0 19.5G  0 part /data

sdb      8:16   0   10G  0 disk

sdc      8:32   0  100G  0 disk

sdd      8:48   0  200G  0 disk

sde      8:64   0   60G  0 disk

[root@CentOS69 ~]#

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

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x0185b781.

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

After that, of course, the previous content won’t be recoverable.

 

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

 

WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to

switch off the mode (command ‘c’) and change display units to

sectors (command ‘u’).

 

Command (m for help): n

Command action

e   extended

p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-1305, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +2G

 

Command (m for help): t

Selected partition 1

Hex code (type L to list codes): L

 

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

1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-

2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-

3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-

4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx

5  Extended        42  SFS             86  NTFS volume set da  Non-FS data

6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .

7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility

8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt

9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access

a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O

b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor

c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs

e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT

f  W95 Ext’d (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/

10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b

11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor

12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor

14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary

16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS

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

18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto

1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep

1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT

1e  Hidden W95 FAT1

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

Changed system type of partition 1 to 8e (Linux LVM)

 

Command (m for help): p

 

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

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

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

Disk identifier: 0x0185b781

 

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         262     2104483+  8e  Linux LVM

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

[root@CentOS69 ~]#fdisk /dev/sdc

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x948e5018.

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

After that, of course, the previous content won’t be recoverable.

 

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

 

WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to

switch off the mode (command ‘c’) and change display units to

sectors (command ‘u’).

 

Command (m for help): n

Command action

e   extended

p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-13054, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054): +3G

 

Command (m for help): t

Selected partition 1

Hex code (type L to list codes): L

 

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

1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-

2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-

3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-

4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx

5  Extended        42  SFS             86  NTFS volume set da  Non-FS data

6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .

7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility

8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt

9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access

a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O

b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor

c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs

e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT

f  W95 Ext’d (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/

10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b

11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor

12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor

14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary

16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS

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

18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto

1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep

1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT

1e  Hidden W95 FAT1

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

Changed system type of partition 1 to 8e (Linux LVM)

 

Command (m for help): p

 

Disk /dev/sdc: 107.4 GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

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

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

Disk identifier: 0x948e5018

 

Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1         393     3156741   8e  Linux LVM

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

[root@CentOS69 ~]#

[root@CentOS69 ~]#

[root@CentOS69 ~]#lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sr0     11:0    1  5.8G  0 rom

sda      8:0    0  100G  0 disk

├─sda1   8:1    0    1G  0 part /boot

├─sda2   8:2    0 29.3G  0 part /

├─sda3   8:3    0    3G  0 part [SWAP]

├─sda4   8:4    0    1K  0 part

└─sda5   8:5    0 19.5G  0 part /data

sdb      8:16   0   10G  0 disk

└─sdb1   8:17   0    2G  0 part

sdc      8:32   0  100G  0 disk

└─sdc1   8:33   0    3G  0 part

sdd      8:48   0  200G  0 disk

sde      8:64   0   60G  0 disk

[root@CentOS69 ~]#

 

 

2、创建pv,将普通的硬盘分区变成物理卷,物理卷是相互独立的,并查看pv

命令:pvcreate DEVICE ……

[root@CentOS69 ~]#

[root@CentOS69 ~]#pvcreate /dev/sdb1

Physical volume “/dev/sdb1” successfully created

[root@CentOS69 ~]#pvcreate /dev/sdc1

Physical volume “/dev/sdc1” successfully created

[root@CentOS69 ~]#

 

[root@CentOS69 ~]#pvs

PV         VG   Fmt  Attr PSize PFree

/dev/sdb1       lvm2 —- 2.01g 2.01g

/dev/sdc1       lvm2 —- 3.01g 3.01g

[root@CentOS69 ~]#pvdisplay

“/dev/sdb1” is a new physical volume of “2.01 GiB”

— NEW Physical volume —

PV Name               /dev/sdb1

VG Name

PV Size               2.01 GiB

Allocatable           NO

PE Size               0

Total PE              0

Free PE               0

Allocated PE          0

PV UUID               YkLroN-Nq14-lY4k-3SBM-OrSD-FvRX-a5yygJ

 

“/dev/sdc1” is a new physical volume of “3.01 GiB”

— NEW Physical volume —

PV Name               /dev/sdc1

VG Name

PV Size               3.01 GiB

Allocatable           NO

PE Size               0

Total PE              0

Free PE               0

Allocated PE          0

PV UUID               62oDzs-YQmw-ctrO-kobU-sX20-AkgG-wiyrae

 

[root@CentOS69 ~]#

 

 

vg管理工具

  • u显示卷组

vgs

vgdisplay

  • u创建卷组

vgcreate [-s #[kKmMgGtTpPeE]] VolumeGroupName PhysicalDevicePath [PhysicalDevicePath…]

-s #:指定PE的大小

 

将做好的两个pv组合成卷组,使用-s指定PE大小,如果不加-s参数的话,系统使用默认PE

 

示例:

[root@CentOS69 ~]#vgs

[root@CentOS69 ~]#vgcreate -s 16M vg0 /dev/sd{b,c}1

Volume group “vg0″ successfully created

[root@CentOS69 ~]#vgs

VG   #PV #LV #SN Attr   VSize VFree

vg0    2   0   0 wz–n- 5.00g 5.00g

[root@CentOS69 ~]#vgdisplay

— Volume group —

VG Name               vg0

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

PE Size               16.00 MiB

Total PE              320

Alloc PE / Size       0 / 0

Free  PE / Size       320 / 5.00 GiB

VG UUID               Lx2BW8-WTuV-SStg-zQqc-PUUG-1qfM-nw2LTX

 

[root@CentOS69 ~]#pvs

PV         VG   Fmt  Attr PSize PFree

/dev/sdb1  vg0  lvm2 a–u 2.00g 2.00g

/dev/sdc1  vg0  lvm2 a–u 3.00g 3.00g

[root@CentOS69 ~]#pvdisplay

— Physical volume —

PV Name               /dev/sdb1

VG Name               vg0

PV Size               2.01 GiB / not usable 7.16 MiB  #PE是以16M为单位划分的,如果不足16M,就会被剩下,不使用

Allocatable           yes

PE Size               16.00 MiB

Total PE              128

Free PE               128

Allocated PE          0

PV UUID               YkLroN-Nq14-lY4k-3SBM-OrSD-FvRX-a5yygJ

 

— Physical volume —

PV Name               /dev/sdc1

VG Name               vg0

PV Size               3.01 GiB / not usable 10.75 MiB

Allocatable           yes

PE Size               16.00 MiB

Total PE              192

Free PE               192

Allocated PE          0

PV UUID               62oDzs-YQmw-ctrO-kobU-sX20-AkgG-wiyrae

 

[root@CentOS69 ~]#

[root@CentOS69 ~]#blkid

\/dev/sda2: UUID=”a710e155-b65b-4f32-a16a-7814fc2426f8″ TYPE=”ext4″

/dev/block/8:2: UUID=”a710e155-b65b-4f32-a16a-7814fc2426f8″ TYPE=”ext4″

/dev/sda1: UUID=”b4f6ad59-0748-493e-8d5f-4111b9b46c4e” TYPE=”ext4″

/dev/sda3: UUID=”304f8301-842e-450b-82db-e0d430004eb4″ TYPE=”swap”

/dev/sda5: UUID=”3b5f9df7-28c1-4178-80fa-8f26f01003f8″ TYPE=”ext4″

/dev/sdb1: UUID=”YkLroN-Nq14-lY4k-3SBM-OrSD-FvRX-a5yygJ” TYPE=”LVM2_member”

/dev/sdc1: UUID=”62oDzs-YQmw-ctrO-kobU-sX20-AkgG-wiyrae” TYPE=”LVM2_member”

[root@CentOS69 ~]#

 

 

 

  • u管理卷组

vg扩容:vgextend VolumeGroupName PhysicalDevicePath [PhysicalDevicePath…]

vg缩容:vgreduce VolumeGroupName PhysicalDevicePath [PhysicalDevicePath…]

 

 

  • u删除卷组

删除卷设备前,必须先将vg下的lv设备先取消挂载

先做pvmove,再做vgremove

 

 

lv管理工具

  • u显示逻辑卷

lvs

Lvdisplay

  • u创建逻辑卷

lvcreate -L #[mMgGtT] -n NAME VolumeGroup

lvcreate -l 60%VG -n mylv testvg

lvcreate -l 100%FREE -n yourlv testvg

 

参数:

-L #:直接指定lv的空间的大小(空间大小是PE的整数倍,指定大小不是16的整数倍,系统会根据其机制自动换算成整数倍)

-l #:指定相对空间大小(可以指定PE个数指定空间大小)

 

在vg上划分lv,lv的空间大小不能超过vg,本次示例以PE个数划分lv空间

 

示例:

[root@CentOS69 ~]#lvcreate -n lv0 -l 250 vg0

Logical volume “lv0” created.

[root@CentOS69 ~]#lvs

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

lv0  vg0  -wi-a—– 3.91g

[root@CentOS69 ~]#lvdisplay

— Logical volume —

LV Path                /dev/vg0/lv0

LV Name                lv0

VG Name                vg0

LV UUID                x1zRKh-caDy-xZTg-wruV-oN3f-otTG-L0ncw3

LV Write Access        read/write

LV Creation host, time CentOS69.magedu.com, 2018-04-29 03:18:56 +0800

LV Status              available

# open                 0

LV Size                3.91 GiB

Current LE             250

Segments               2

Allocation             inherit

Read ahead sectors     auto

– currently set to     256

Block device           253:0

 

[root@CentOS69 ~]#ll /dev/vg0/lv0

lrwxrwxrwx. 1 root root 7 Apr 29 03:18 /dev/vg0/lv0 -> ../dm-0

[root@CentOS69 ~]#ll /dev/dm-0

brw-rw—-. 1 root disk 253, 0 Apr 29 03:18 /dev/dm-0

[root@CentOS69 ~]#vgs

VG   #PV #LV #SN Attr   VSize VFree

vg0    2   1   0 wz–n- 5.00g 1.09g

[root@CentOS69 ~]#vgdisplay

— Volume group —

VG Name               vg0

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               0

Max PV                0

Cur PV                2

Act PV                2

VG Size               5.00 GiB

PE Size               16.00 MiB

Total PE              320

Alloc PE / Size       250 / 3.91 GiB

Free  PE / Size       70 / 1.09 GiB

VG UUID               Lx2BW8-WTuV-SStg-zQqc-PUUG-1qfM-nw2LTX

 

[root@CentOS69 ~]#pvs

PV         VG   Fmt  Attr PSize PFree

/dev/sdb1  vg0  lvm2 a–u 2.00g 1.09g

/dev/sdc1  vg0  lvm2 a–u 3.00g    0

[root@CentOS69 ~]#pvdisplay

— Physical volume —

PV Name               /dev/sdb1

VG Name               vg0

PV Size               2.01 GiB / not usable 7.16 MiB

Allocatable           yes

PE Size               16.00 MiB

Total PE              128

Free PE               70

Allocated PE          58

PV UUID               YkLroN-Nq14-lY4k-3SBM-OrSD-FvRX-a5yygJ

 

— Physical volume —

PV Name               /dev/sdc1

VG Name               vg0

PV Size               3.01 GiB / not usable 10.75 MiB

Allocatable           yes (but full)

PE Size               16.00 MiB

Total PE              192

Free PE               0

Allocated PE          192

PV UUID               62oDzs-YQmw-ctrO-kobU-sX20-AkgG-wiyrae

 

[root@CentOS69 ~]#

 

 

再创建一个lv,将剩余空间全部使用完

[root@CentOS69 ~]#vgdisplay

— Volume group —

VG Name               vg0

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               0

Max PV                0

Cur PV                2

Act PV                2

VG Size               5.00 GiB

PE Size               16.00 MiB

Total PE              320

Alloc PE / Size       250 / 3.91 GiB

Free  PE / Size       70 / 1.09 GiB

VG UUID               Lx2BW8-WTuV-SStg-zQqc-PUUG-1qfM-nw2LTX

 

[root@CentOS69 ~]#lvcreate -n lv1 -l 100%FREE vg0

Logical volume “lv1” created.

[root@CentOS69 ~]#lvs

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

lv0  vg0  -wi-a—– 3.91g

lv1  vg0  -wi-a—– 1.09g

[root@CentOS69 ~]#vgdisplay

— Volume group —

VG Name               vg0

System ID

Format                lvm2

Metadata Areas        2

Metadata Sequence No  3

VG Access             read/write

VG Status             resizable

MAX LV                0

Cur LV                2

Open LV               0

Max PV                0

Cur PV                2

Act PV                2

VG Size               5.00 GiB

PE Size               16.00 MiB

Total PE              320

Alloc PE / Size       320 / 5.00 GiB

Free  PE / Size       0 / 0

VG UUID               Lx2BW8-WTuV-SStg-zQqc-PUUG-1qfM-nw2LTX

 

[root@CentOS69 ~]#ll /dev/mapper/vg0-lv0

lrwxrwxrwx. 1 root root 7 Apr 29 03:18 /dev/mapper/vg0-lv0 -> ../dm-0

[root@CentOS69 ~]#ll /dev/mapper/vg0-lv1

lrwxrwxrwx. 1 root root 7 Apr 29 03:24 /dev/mapper/vg0-lv1 -> ../dm-1

[root@CentOS69 ~]#

 

给lv0,lv1创建文件系统

[root@CentOS69 ~]#blkid /dev/vg0/lv0

[root@CentOS69 ~]#mkfs.ext4 /dev/vg0/lv0

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

256000 inodes, 1024000 blocks

51200 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=1048576000

32 block groups

32768 blocks per group, 32768 fragments per group

8000 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736

 

Writing inode tables: done

Creating journal (16384 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 30 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@CentOS69 ~]#blkid /dev/vg0/lv0

/dev/vg0/lv0: UUID=”54f9ec72-b153-4c5e-9ab5-c16aae65ab39″ TYPE=”ext4″

[root@CentOS69 ~]#

 

[root@CentOS69 ~]#blkid /dev/vg0/lv1

[root@CentOS69 ~]#mkfs.ext4 /dev/vg0/lv1

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

71712 inodes, 286720 blocks

14336 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=293601280

9 block groups

32768 blocks per group, 32768 fragments per group

7968 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376

 

Writing inode tables: done

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 34 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@CentOS69 ~]#blkid /dev/vg0/lv1

/dev/vg0/lv1: UUID=”cff2e769-8874-4df5-b13b-276e1f6458fb” TYPE=”ext4″

[root@CentOS69 ~]#

 

挂载lv0,lv1文件系统

[root@CentOS69 ~]#cat /etc/fstab | grep “/data/lv*”

UUID=54f9ec72-b153-4c5e-9ab5-c16aae65ab39 /data/lv0 ext4 defaults 0 0

UUID=cff2e769-8874-4df5-b13b-276e1f6458fb /data/lv1 ext4 defaults 0 0

[root@CentOS69 ~]#mount -a

[root@CentOS69 ~]#df

Filesystem          1K-blocks     Used Available Use% Mounted on

/dev/sda2            30106576 15031324  13539252  53% /

tmpfs                  953636        4    953632   1% /dev/shm

/dev/sda1              999320    60284    886608   7% /boot

/dev/sda5            20027260    69876  18933384   1% /data

/dev/mapper/vg0-lv0   3966144     7992   3753352   1% /data/lv0

/dev/mapper/vg0-lv1   1096072     1404   1037324   1% /data/lv1

[root@CentOS69 ~]#mount

/dev/sda2 on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw,rootcontext=”system_u:object_r:tmpfs_t:s0″)

/dev/sda1 on /boot type ext4 (rw)

/dev/sda5 on /data type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)

/dev/mapper/vg0-lv0 on /data/lv0 type ext4 (rw)

/dev/mapper/vg0-lv1 on /data/lv1 type ext4 (rw)

[root@CentOS69 ~]#cd /data/lv0

[root@CentOS69 lv0]#touch f1

[root@CentOS69 lv0]#ll

total 16

-rw-r–r–. 1 root root     0 Apr 29 03:36 f1

drwx——. 2 root root 16384 Apr 29 03:28 lost+found

[root@CentOS69 lv0]#

[root@CentOS69 lv0]#mkdir test_centos69

[root@CentOS69 lv0]#ll

total 20

-rw-r–r–. 1 root root     0 Apr 29 03:36 f1

drwx——. 2 root root 16384 Apr 29 03:28 lost+found

drwxr-xr-x. 2 root root  4096 Apr 29 03:37 test_centos69

[root@CentOS69 lv0]#

 

使用dd命令测试读写LVM性能

[root@CentOS69 lv0]#dd if=/dev/zero of=test_f2 bs=1M count=1024 conv=fdatasync

1024+0 records in

1024+0 records out

1073741824 bytes (1.1 GB) copied, 11.2223 s, 95.7 MB/s

[root@CentOS69 lv0]#

 

[root@CentOS69 lv0]#dd if=test_f2 of=/dev/null

2097152+0 records in

2097152+0 records out

1073741824 bytes (1.1 GB) copied, 1.80879 s, 594 MB/s

[root@CentOS69 lv0]#

 

  • u删除逻辑卷
lvremove /dev/VG_NAME/LV_NAME

 

[root@CentOS74 ~]#lvremove /dev/mapper/centos6vg0-centos6lv1

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

Logical volume “centos6lv1” successfully removed

[root@CentOS74 ~]#

[root@CentOS74 ~]#lvdisplay

— Logical volume —

LV Path                /dev/centos6vg0/centos6lv0

LV Name                centos6lv0

VG Name                centos6vg0

LV UUID                x1zRKh-caDy-xZTg-wruV-oN3f-otTG-L0ncw3

LV Write Access        read/write

LV Creation host, time CentOS69.magedu.com, 2018-04-29 03:18:56 +0800

LV Status              available

# open                 0

LV Size                <3.91 GiB

Current LE             250

Segments               1

Allocation             inherit

Read ahead sectors     auto

– currently set to     8192

Block device           253:0

 

[root@CentOS74 ~]#

 

  • u重设文件系统大小

fsadm [options] resize device [new_size[BKMGTEP]]

resize2fs [-f] [-F] [-M] [-P] [-p] device [new_size]

 

 

扩展和缩减逻辑卷

  • u扩展逻辑卷:

lvextend -L [+]#[mMgGtT] /dev/VG_NAME/LV_NAME

参数:

-r:给lv扩容的同时把文件系统也同步了

 

resize2fs /dev/VG_NAME/LV_NAME    (如果不加-r参数,ext系列的文件系统同步文件系统)

xfs_growfs /dev/VG_NAME/LV_NAME   (如果不加-r参数,xfs系列的文件系统同步文件系统)

 

lvresize -r -l +100%FREE /dev/ VG_NAME/LV_NAME

 

扩展逻辑卷

如果卷组中还有剩余空间,可以直接把卷组的剩余空间扩展到卷组中,

如果卷组空间不足,需要先扩展卷组空间,需要创建卷组空间必选先准备空间创建pv

 

本次示例,创建pv,扩用vg,然后扩容lv

1、以/dev/sdf整块硬盘创建pv

2、给vg扩用

3、在线给lv扩容

4、同步lv文件系统(resize2fs /dev/VG_NAME/LV_NAME)

[root@CentOS69 ~]#lsblk /dev/sdf

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sdf    8:80   0   5G  0 disk

[root@CentOS69 ~]#pvcreate /dev/sdf

Physical volume “/dev/sdf” successfully created

[root@CentOS69 ~]#pvs

PV         VG   Fmt  Attr PSize PFree

/dev/sdb1  vg0  lvm2 a–u 2.00g    0

/dev/sdc1  vg0  lvm2 a–u 3.00g    0

/dev/sdf        lvm2 —- 5.00g 5.00g

[root@CentOS69 ~]#vgextend vg0 /dev/sdf

Volume group “vg0” successfully extended

[root@CentOS69 ~]#vgs

VG   #PV #LV #SN Attr   VSize VFree

vg0    3   2   0 wz–n- 9.98g 4.98g

[root@CentOS69 ~]#pvs

PV         VG   Fmt  Attr PSize PFree

/dev/sdb1  vg0  lvm2 a–u 2.00g    0

/dev/sdc1  vg0  lvm2 a–u 3.00g    0

/dev/sdf   vg0  lvm2 a–u 4.98g 4.98g

[root@CentOS69 ~]#vgdisplay

— Volume group —

VG Name               vg0

System ID

Format                lvm2

Metadata Areas        3

Metadata Sequence No  4

VG Access             read/write

VG Status             resizable

MAX LV                0

Cur LV                2

Open LV               2

Max PV                0

Cur PV                3

Act PV                3

VG Size               9.98 GiB

PE Size               16.00 MiB

Total PE              639

Alloc PE / Size       320 / 5.00 GiB

Free  PE / Size       319 / 4.98 GiB

VG UUID               Lx2BW8-WTuV-SStg-zQqc-PUUG-1qfM-nw2LTX

 

[root@CentOS69 ~]#lvextend -L +2G /dev/vg0/lv0

Size of logical volume vg0/lv0 changed from 3.91 GiB (250 extents) to 5.91 GiB (378 extents).

Logical volume lv0 successfully resized.

[root@CentOS69 ~]#lvs

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

lv0  vg0  -wi-ao—- 5.91g

lv1  vg0  -wi-ao—- 1.09g

[root@CentOS69 ~]#

[root@CentOS69 ~]#df -h | grep “lv0”

/dev/mapper/vg0-lv0  3.8G  1.1G  2.6G  29% /data/lv0

[root@CentOS69 ~]#resize2fs /dev/vg0/lv0

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/vg0/lv0 is mounted on /data/lv0; on-line resizing required

old desc_blocks = 1, new_desc_blocks = 1

Performing an on-line resize of /dev/vg0/lv0 to 1548288 (4k) blocks.

The filesystem on /dev/vg0/lv0 is now 1548288 blocks long.

 

[root@CentOS69 ~]#df -h | grep “lv0”

/dev/mapper/vg0-lv0  5.8G  1.1G  4.5G  19% /data/lv0

[root@CentOS69 ~]#

 

 

 

#lvextend -r  -l +100%FREE /dev/vg0/lv0    将所有剩余空间都加到lv0中(-r参数:表示lv扩展的同时自动同步文件系统)

 

 

  • u缩减逻辑卷:

umount /dev/VG_NAME/LV_NAME   取消挂载

e2fsck -f /dev/VG_NAME/LV_NAME  文件系统检查

resize2fs /dev/VG_NAME/LV_NAME #[mMgGtT]   缩小文件系统(表示缩减到#大小的空间)(在这里特别要注意(缩减了,缩减到)多大空间的概念)

lvreduce -L [-]#[mMgGtT] /dev/VG_NAME/LV_NAME  缩小lv空间大小

mount            重新挂载文件系统

 

linux运维心得:

 

缩小逻辑卷,是一个很危险操作,缩小逻辑卷要确保保留出现有数据的空余空间,

建议在做缩小逻辑卷操作之前,实现对逻辑卷数据进行备份,避免缩小逻辑卷失败,造成数据丢失或损坏。

 

ext系列的文件系可以缩减,xfs系统的文件系统不可以缩减

 

缩减操作不可以在线缩减,必须实现取消挂载

 

缩减操作:

lv分区数据备份

1、取消挂载

2、文件系统检查

3、缩减文件系统

3、缩小lv空间

4、重新挂载文件系统

[root@CentOS69 ~]#df -h | grep “lv0”

/dev/mapper/vg0-lv0  5.8G  1.1G  4.5G  19% /data/lv0

[root@CentOS69 ~]#umount /dev/vg0/lv0

[root@CentOS69 ~]#e2fsck -f /dev/vg0/lv0

e2fsck 1.41.12 (17-May-2010)

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/vg0/lv0: 14/384000 files (0.0% non-contiguous), 304640/1548288 blocks

[root@CentOS69 ~]#resize2fs /dev/vg0/lv0 2G

resize2fs 1.41.12 (17-May-2010)

Resizing the filesystem on /dev/vg0/lv0 to 524288 (4k) blocks.

The filesystem on /dev/vg0/lv0 is now 524288 blocks long.

 

[root@CentOS69 ~]#lvreduce -L 2G /dev/vg0/lv0

WARNING: Reducing active logical volume to 2.00 GiB.

THIS MAY DESTROY YOUR DATA (filesystem etc.)

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

Size of logical volume vg0/lv0 changed from 5.91 GiB (378 extents) to 2.00 GiB (128 extents).

Logical volume lv0 successfully resized.

[root@CentOS69 ~]#mount -a

[root@CentOS69 ~]#df -h | grep “lv0”

/dev/mapper/vg0-lv0  2.0G  1.1G  822M  56% /data/lv0

[root@CentOS69 ~]#

 

 

跨主机迁移卷组

  • u源计算机上
    • Ø1 在旧系统中,umount所有卷组上的逻辑卷
    • Ø2 vgchange –a n vg0   禁用vg

lvdisplay

  • Ø3 vgexport vg0              导出vg

pvscan

vgdisplay

拆下旧硬盘

  • u 在目标计算机上
    • Ø4 在新系统中安装旧硬盘,并vgimport vg0     导入vg
    • Ø5 vgchange –ay vg0                                                   启用vg
    • Ø6 mount所有卷组上的逻辑卷                       挂载vg

 

跨主机迁移卷组,但是迁移只要求拆一块盘

1、将其他磁盘的已分配的PE空间,移动到指定的磁盘(磁盘要足够大)中,然后将其从vg中分离,不让其参与到迁移操作中

 

使用pvmove进行PE移动

[root@CentOS69 ~]#pvdisplay

— Physical volume —

PV Name               /dev/sdb1

VG Name               vg0

PV Size               2.01 GiB / not usable 7.16 MiB

Allocatable           yes

PE Size               16.00 MiB

Total PE              128

Free PE               20

Allocated PE          108

PV UUID               YkLroN-Nq14-lY4k-3SBM-OrSD-FvRX-a5yygJ

 

— Physical volume —

PV Name               /dev/sdf

VG Name               vg0

PV Size               5.00 GiB / not usable 16.00 MiB

Allocatable           yes

PE Size               16.00 MiB

  Total PE              319

  Free PE               127

  Allocated PE          192

PV UUID               GzyIA6-LruV-iC1S-fCk0-iw8J-z2qy-Gzxq3X

 

[root@CentOS69 ~]#pvmove /dev/sdb1 /dev/sdf

/dev/sdb1: Moved: 3.7%

/dev/sdb1: Moved: 53.7%

/dev/sdb1: Moved: 100.0%

[root@CentOS69 ~]#pvdisplay

— Physical volume —

PV Name               /dev/sdb1

VG Name               vg0

PV Size               2.01 GiB / not usable 7.16 MiB

Allocatable           yes

PE Size               16.00 MiB

Total PE              128

Free PE               128

Allocated PE          0

PV UUID               YkLroN-Nq14-lY4k-3SBM-OrSD-FvRX-a5yygJ

 

— Physical volume —

PV Name               /dev/sdf

VG Name               vg0

PV Size               5.00 GiB / not usable 16.00 MiB

Allocatable           yes

PE Size               16.00 MiB

Total PE              319

Free PE               19

Allocated PE          300

PV UUID               GzyIA6-LruV-iC1S-fCk0-iw8J-z2qy-Gzxq3X

 

[root@CentOS69 ~]#

 

 

2、将/dev/sdb1从vg移除

[root@CentOS69 ~]#vgreduce vg0 /dev/sdb1

Removed “/dev/sdb1” from volume group “vg0”

[root@CentOS69 ~]#pvdisplay

— Physical volume —

PV Name               /dev/sdf

VG Name               vg0

PV Size               5.00 GiB / not usable 16.00 MiB

Allocatable           yes

PE Size               16.00 MiB

Total PE              319

Free PE               19

Allocated PE          300

PV UUID               GzyIA6-LruV-iC1S-fCk0-iw8J-z2qy-Gzxq3X

 

“/dev/sdb1” is a new physical volume of “2.01 GiB”

— NEW Physical volume —

PV Name               /dev/sdb1

VG Name

PV Size               2.01 GiB

Allocatable           NO

PE Size               0

Total PE              0

Free PE               0

Allocated PE          0

PV UUID               YkLroN-Nq14-lY4k-3SBM-OrSD-FvRX-a5yygJ

 

[root@CentOS69 ~]#pvs

PV         VG   Fmt  Attr PSize PFree

/dev/sdb1       lvm2 —- 2.01g   2.01g

/dev/sdf   vg0  lvm2 a–u 4.98g 304.00m

[root@CentOS69 ~]#

 

现在所有的数据和vg都在sdf中,只要把sdf拔下来换到新系统上,就可以实现迁移操作了,

但是还有一个问题,就是新系统上也有可能存在同名的vg和lv,迁移前要检查新系统中是否存在

同名冲突,如果命令冲突需要修改vg和lv名字。

 

3、修改vg和lv名字

[root@CentOS69 ~]#vgdisplay

— Volume group —

VG Name               vg0

System ID

Format                lvm2

Metadata Areas        1

Metadata Sequence No  17

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

PE Size               16.00 MiB

Total PE              319

Alloc PE / Size       300 / 4.69 GiB

Free  PE / Size       19 / 304.00 MiB

VG UUID               Lx2BW8-WTuV-SStg-zQqc-PUUG-1qfM-nw2LTX

 

[root@CentOS69 ~]#vgs

VG   #PV #LV #SN Attr   VSize VFree

vg0    1   2   0 wz–n- 4.98g 304.00m

[root@CentOS69 ~]#vgrename vg0 centos6vg0

Volume group “vg0” successfully renamed to “centos6vg0”

[root@CentOS69 ~]#vgdisplay

— Volume group —

VG Name               centos6vg0

System ID

Format                lvm2

Metadata Areas        1

Metadata Sequence No  18

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

PE Size               16.00 MiB

Total PE              319

Alloc PE / Size       300 / 4.69 GiB

Free  PE / Size       19 / 304.00 MiB

VG UUID               Lx2BW8-WTuV-SStg-zQqc-PUUG-1qfM-nw2LTX

 

[root@CentOS69 ~]#vgs

VG         #PV #LV #SN Attr   VSize VFree

centos6vg0   1   2   0 wz–n- 4.98g 304.00m

[root@CentOS69 ~]#lvdisplay

— Logical volume —

LV Path                /dev/centos6vg0/lv0

LV Name                lv0

VG Name                centos6vg0

LV UUID                x1zRKh-caDy-xZTg-wruV-oN3f-otTG-L0ncw3

LV Write Access        read/write

LV Creation host, time CentOS69.magedu.com, 2018-04-29 03:18:56 +0800

LV Status              available

# open                 1

LV Size                3.91 GiB

Current LE             250

Segments               1

Allocation             inherit

Read ahead sectors     auto

– currently set to     256

Block device           253:0

 

— Logical volume —

LV Path                /dev/centos6vg0/lv1

LV Name                lv1

VG Name                centos6vg0

LV UUID                Lumaj1-NpW0-pTUP-fiXU-fayf-ZIZQ-X4Dtkz

LV Write Access        read/write

LV Creation host, time CentOS69.magedu.com, 2018-04-29 03:24:47 +0800

LV Status              available

# open                 1

LV Size                800.00 MiB

Current LE             50

Segments               1

Allocation             inherit

Read ahead sectors     auto

– currently set to     256

Block device           253:1

 

[root@CentOS69 ~]#lvs

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

lv0  centos6vg0 -wi-ao—-   3.91g

lv1  centos6vg0 -wi-ao—- 800.00m

[root@CentOS69 ~]#lvrename /dev/centos6vg0/lv0 /dev/centos6vg0/centos6lv0

Renamed “lv0” to “centos6lv0” in volume group “centos6vg0”

[root@CentOS69 ~]#lvrename /dev/centos6vg0/lv1 /dev/centos6vg0/centos6lv1

Renamed “lv1” to “centos6lv1” in volume group “centos6vg0”

[root@CentOS69 ~]#lvdisplay

— Logical volume —

LV Path                /dev/centos6vg0/centos6lv0

LV Name                centos6lv0

VG Name                centos6vg0

LV UUID                x1zRKh-caDy-xZTg-wruV-oN3f-otTG-L0ncw3

LV Write Access        read/write

LV Creation host, time CentOS69.magedu.com, 2018-04-29 03:18:56 +0800

LV Status              available

# open                 1

LV Size                3.91 GiB

Current LE             250

Segments               1

Allocation             inherit

Read ahead sectors     auto

– currently set to     256

Block device           253:0

 

— Logical volume —

LV Path                /dev/centos6vg0/centos6lv1

LV Name                centos6lv1

VG Name                centos6vg0

LV UUID                Lumaj1-NpW0-pTUP-fiXU-fayf-ZIZQ-X4Dtkz

LV Write Access        read/write

LV Creation host, time CentOS69.magedu.com, 2018-04-29 03:24:47 +0800

LV Status              available

# open                 1

LV Size                800.00 MiB

Current LE             50

Segments               1

Allocation             inherit

Read ahead sectors     auto

– currently set to     256

Block device           253:1

 

[root@CentOS69 ~]#lvs

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

centos6lv0 centos6vg0 -wi-ao—-   3.91g

centos6lv1 centos6vg0 -wi-ao—- 800.00m

[root@CentOS69 ~]#

[root@CentOS69 ~]#ll /dev/centos6vg0/centos6lv0

lrwxrwxrwx. 1 root root 7 Apr 29 08:10 /dev/centos6vg0/centos6lv0 -> ../dm-0

[root@CentOS69 ~]#ll /dev/centos6vg0/centos6lv1

lrwxrwxrwx. 1 root root 7 Apr 29 08:10 /dev/centos6vg0/centos6lv1 -> ../dm-1

[root@CentOS69 ~]#

 

 

4、取消挂载

[root@CentOS69 ~]#df

Filesystem          1K-blocks     Used Available Use% Mounted on

/dev/sda2            30106576 15031516  13539060  53% /

tmpfs                  953636        4    953632   1% /dev/shm

/dev/sda1              999320    60284    886608   7% /boot

/dev/sda5            20027260    69876  18933384   1% /data

/dev/mapper/vg0-lv0   3966144  1056576   2708052  29% /data/lv0

/dev/mapper/vg0-lv1    772400     1132    730308   1% /data/lv1

[root@CentOS69 ~]#umount /dev/mapper/vg0-lv0

[root@CentOS69 ~]#umount /dev/mapper/vg0-lv1

[root@CentOS69 ~]#df

Filesystem     1K-blocks     Used Available Use% Mounted on

/dev/sda2       30106576 15031516  13539060  53% /

tmpfs             953636        4    953632   1% /dev/shm

/dev/sda1         999320    60284    886608   7% /boot

/dev/sda5       20027260    69876  18933384   1% /data

[root@CentOS69 ~]#

 

5、禁用卷组

[root@CentOS69 ~]#vgchange -an centos6vg0

0 logical volume(s) in volume group “centos6vg0” now active

[root@CentOS69 ~]#

[root@CentOS69 ~]#lvdisplay

— Logical volume —

LV Path                /dev/centos6vg0/centos6lv0

LV Name                centos6lv0

VG Name                centos6vg0

LV UUID                x1zRKh-caDy-xZTg-wruV-oN3f-otTG-L0ncw3

LV Write Access        read/write

LV Creation host, time CentOS69.magedu.com, 2018-04-29 03:18:56 +0800

LV Status              NOT available

LV Size                3.91 GiB

Current LE             250

Segments               1

Allocation             inherit

Read ahead sectors     auto

 

— Logical volume —

LV Path                /dev/centos6vg0/centos6lv1

LV Name                centos6lv1

VG Name                centos6vg0

LV UUID                Lumaj1-NpW0-pTUP-fiXU-fayf-ZIZQ-X4Dtkz

LV Write Access        read/write

LV Creation host, time CentOS69.magedu.com, 2018-04-29 03:24:47 +0800

LV Status              NOT available

LV Size                800.00 MiB

Current LE             50

Segments               1

Allocation             inherit

Read ahead sectors     auto

 

[root@CentOS69 ~]#

 

6、导出vg

[root@CentOS69 ~]#vgexport centos6vg0

Volume group “centos6vg0” successfully exported

[root@CentOS69 ~]#lvdisplay

Volume group centos6vg0 is exported

[root@CentOS69 ~]#vgdisplay

— Volume group —

VG Name               centos6vg0

System ID

Format                lvm2

Metadata Areas        1

Metadata Sequence No  21

VG Access             read/write

VG Status             exported/resizable

MAX LV                0

Cur LV                2

Open LV               0

Max PV                0

Cur PV                1

Act PV                1

VG Size               4.98 GiB

PE Size               16.00 MiB

Total PE              319

Alloc PE / Size       300 / 4.69 GiB

Free  PE / Size       19 / 304.00 MiB

VG UUID               Lx2BW8-WTuV-SStg-zQqc-PUUG-1qfM-nw2LTX

 

[root@CentOS69 ~]#

 

[root@CentOS69 ~]#pvdisplay

Physical volume “/dev/sdf” of volume group “centos6vg0” is exported

— Physical volume —

PV Name               /dev/sdf

VG Name               centos6vg0 (exported)

PV Size               5.00 GiB / not usable 16.00 MiB

Allocatable           yes

PE Size               16.00 MiB

Total PE              319

Free PE               19

Allocated PE          300

PV UUID               GzyIA6-LruV-iC1S-fCk0-iw8J-z2qy-Gzxq3X

 

“/dev/sdb1” is a new physical volume of “2.01 GiB”

— NEW Physical volume —

PV Name               /dev/sdb1

VG Name

PV Size               2.01 GiB

Allocatable           NO

PE Size               0

Total PE              0

Free PE               0

Allocated PE          0

PV UUID               YkLroN-Nq14-lY4k-3SBM-OrSD-FvRX-a5yygJ

 

[root@CentOS69 ~]#

 

 

7、将硬盘迁移到新机器

在系统中拆除磁盘

 

在新系统中插入磁盘

 

生效磁盘

[root@CentOS74 ~]#lsblk /dev/sdf

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sdf    8:80   0   5G  0 disk

[root@CentOS74 ~]#

 

8、查看LVM的pv vg lv状态     pv为导出状态

[root@CentOS74 ~]#pvdisplay

Physical volume “/dev/sdf” of volume group “centos6vg0” is exported

— Physical volume —

PV Name               /dev/sdf

VG Name               centos6vg0 (exported)

PV Size               5.00 GiB / not usable 16.00 MiB

Allocatable           yes

PE Size               16.00 MiB

Total PE              319

Free PE               19

Allocated PE          300

PV UUID               GzyIA6-LruV-iC1S-fCk0-iw8J-z2qy-Gzxq3X

 

[root@CentOS74 ~]#vgs

VG         #PV #LV #SN Attr   VSize VFree

centos6vg0   1   2   0 wzx-n- 4.98g 304.00m

[root@CentOS74 ~]#vgdisplay

— Volume group —

VG Name               centos6vg0

System ID

Format                lvm2

Metadata Areas        1

Metadata Sequence No  21

VG Access             read/write

VG Status             exported/resizable

MAX LV                0

Cur LV                2

Open LV               0

Max PV                0

Cur PV                1

Act PV                1

VG Size               4.98 GiB

PE Size               16.00 MiB

Total PE              319

Alloc PE / Size       300 / <4.69 GiB

Free  PE / Size       19 / 304.00 MiB

VG UUID               Lx2BW8-WTuV-SStg-zQqc-PUUG-1qfM-nw2LTX

 

[root@CentOS74 ~]#lvs

Volume group centos6vg0 is exported

[root@CentOS74 ~]#lvdisplay

Volume group centos6vg0 is exported

[root@CentOS74 ~]#

 

 

9、导入vg,但是lv还是不可用

[root@CentOS74 ~]#vgimport centos6vg0

Volume group “centos6vg0” successfully imported

[root@CentOS74 ~]#vgdisplay

— Volume group —

VG Name               centos6vg0

System ID

Format                lvm2

Metadata Areas        1

Metadata Sequence No  22

VG Access             read/write

VG Status             resizable

MAX LV                0

Cur LV                2

Open LV               0

Max PV                0

Cur PV                1

Act PV                1

VG Size               4.98 GiB

PE Size               16.00 MiB

Total PE              319

Alloc PE / Size       300 / <4.69 GiB

Free  PE / Size       19 / 304.00 MiB

VG UUID               Lx2BW8-WTuV-SStg-zQqc-PUUG-1qfM-nw2LTX

 

[root@CentOS74 ~]#pvdisplay

— Physical volume —

PV Name               /dev/sdf

VG Name               centos6vg0

PV Size               5.00 GiB / not usable 16.00 MiB

Allocatable           yes

PE Size               16.00 MiB

Total PE              319

Free PE               19

Allocated PE          300

PV UUID               GzyIA6-LruV-iC1S-fCk0-iw8J-z2qy-Gzxq3X

 

[root@CentOS74 ~]#lvdisplay

— Logical volume —

LV Path                /dev/centos6vg0/centos6lv0

LV Name                centos6lv0

VG Name                centos6vg0

LV UUID                x1zRKh-caDy-xZTg-wruV-oN3f-otTG-L0ncw3

LV Write Access        read/write

LV Creation host, time CentOS69.magedu.com, 2018-04-29 03:18:56 +0800

LV Status              NOT available

LV Size                <3.91 GiB

Current LE             250

Segments               1

Allocation             inherit

Read ahead sectors     auto

 

— Logical volume —

LV Path                /dev/centos6vg0/centos6lv1

LV Name                centos6lv1

VG Name                centos6vg0

LV UUID                Lumaj1-NpW0-pTUP-fiXU-fayf-ZIZQ-X4Dtkz

LV Write Access        read/write

LV Creation host, time CentOS69.magedu.com, 2018-04-29 03:24:47 +0800

LV Status              NOT available

LV Size                800.00 MiB

Current LE             50

Segments               1

Allocation             inherit

Read ahead sectors     auto

 

[root@CentOS74 ~]#

 

 

10、启用vg lv,可用

[root@CentOS74 ~]#vgchange -ay centos6vg0

2 logical volume(s) in volume group “centos6vg0” now active

[root@CentOS74 ~]#lvdisplay

— Logical volume —

LV Path                /dev/centos6vg0/centos6lv0

LV Name                centos6lv0

VG Name                centos6vg0

LV UUID                x1zRKh-caDy-xZTg-wruV-oN3f-otTG-L0ncw3

LV Write Access        read/write

LV Creation host, time CentOS69.magedu.com, 2018-04-29 03:18:56 +0800

LV Status              available

# open                 0

LV Size                <3.91 GiB

Current LE             250

Segments               1

Allocation             inherit

Read ahead sectors     auto

– currently set to     8192

Block device           253:0

 

— Logical volume —

LV Path                /dev/centos6vg0/centos6lv1

LV Name                centos6lv1

VG Name                centos6vg0

LV UUID                Lumaj1-NpW0-pTUP-fiXU-fayf-ZIZQ-X4Dtkz

LV Write Access        read/write

LV Creation host, time CentOS69.magedu.com, 2018-04-29 03:24:47 +0800

LV Status              available

# open                 0

LV Size                800.00 MiB

Current LE             50

Segments               1

Allocation             inherit

Read ahead sectors     auto

– currently set to     8192

Block device           253:1

 

[root@CentOS74 ~]#

 

11、挂载测试(OK)

[root@CentOS74 ~]#mount /dev/centos6vg0/centos6lv0 /data/lv0

[root@CentOS74 ~]#mount /dev/centos6vg0/centos6lv1 /data/lv1

[root@CentOS74 ~]#df | grep “lv”

/dev/mapper/centos6vg0-centos6lv0   3966144 1056576   2691668  29% /data/lv0

/dev/mapper/centos6vg0-centos6lv1    772400    1132    713924   1% /data/lv1

[root@CentOS74 ~]#

[root@CentOS74 ~]#cd /data/lv0/

[root@CentOS74 lv0]#ls

f1  lost+found  test_centos69  test_f2

[root@CentOS74 lv0]#ll

total 1048600

-rw-r–r–. 1 root root          0 Apr 29 03:36 f1

drwx——  2 root root      16384 Apr 29 03:28 lost+found

drwxr-xr-x. 2 root root       4096 Apr 29 03:37 test_centos69

-rw-r–r–. 1 root root 1073741824 Apr 29 03:40 test_f2

[root@CentOS74 lv0]#cd ../lv1

[root@CentOS74 lv1]#ls

lost+found  test

[root@CentOS74 lv1]#cat test

test

test2

[root@CentOS74 lv1]#

 

 

创建逻辑卷示例

  • u创建物理卷

pvcreate /dev/sda3

  • u为卷组分配物理卷

vgcreate vg0 /dev/sda3

  • u从卷组创建逻辑卷

lvcreate -L 256M -n data vg0

mke2fs -j /dev/vg0/data

  • umount /dev/vg0/data /mnt/data

 

 

模拟移除LVM中的磁盘或者缩减VG总容量(删除VG中的PV

移除前磁盘前的准备工作,查看磁盘是否存储了数据,如果存储了数据,需要把数据移动到其他PV中。

 

1、检查pv存储,移动pv数据

 

本次示例:

本次要将磁盘/dev/sdc1,从LVM中移除,

使用pvdisplay命令可以看到/dev/sdc1,PE全部都被分配出去(也许被用户正在使用或存储了数据),/dev/sdb1中的PE也全部都被分配出去了,

因此,/dev/sdc1中的PE没有足够的剩余空间可以移动,所以添加/dev/sdf磁盘设备(要保证新添加的分区空间容量大于等于/dev/sdc1被分配出去的PE总容量)

,并制作成pv扩容到vg0中,

/dev/sdf中有足够的空余PE空间来存储/dev/sdc1中的PE。

[root@CentOS69 ~]#pvdisplay

— Physical volume —

PV Name               /dev/sdb1

VG Name               vg0

PV Size               2.01 GiB / not usable 7.16 MiB

Allocatable           yes (but full)

PE Size               16.00 MiB

Total PE              128

Free PE               0

Allocated PE          128

PV UUID               YkLroN-Nq14-lY4k-3SBM-OrSD-FvRX-a5yygJ

 

— Physical volume —

PV Name               /dev/sdc1

VG Name               vg0

PV Size               3.01 GiB / not usable 10.75 MiB

Allocatable           yes (but full)

PE Size               16.00 MiB

Total PE              192

Free PE               0

Allocated PE          192

PV UUID               62oDzs-YQmw-ctrO-kobU-sX20-AkgG-wiyrae

 

— Physical volume —

PV Name               /dev/sdf

VG Name               vg0

PV Size               5.00 GiB / not usable 16.00 MiB

Allocatable           yes

PE Size               16.00 MiB

Total PE              319

Free PE               319

Allocated PE          0

PV UUID               GzyIA6-LruV-iC1S-fCk0-iw8J-z2qy-Gzxq3X

 

[root@CentOS69 ~]#

 

2、移动/dev/sdc1中的PE移动到/dev/sdf中(将/dev/sdc1中的PE移动到同一卷组中的其他成员中),只要剩余成员空间足够,系统自动判断移动到那个磁盘上

pvmove DEVICE  :移除设备中PE空间,

注意不是直接移动数据,而是移动PE空间(PE空间=数据+剩余空间)(空间大小>=数据大小)

 

/dev/sdc1将PE移动到/dev/sdf中了

[root@CentOS69 ~]#pvmove /dev/sdc1

/dev/sdc1: Moved: 1.0%

/dev/sdc1: Moved: 100.0%

[root@CentOS69 ~]#pvdisplay

— Physical volume —

PV Name               /dev/sdb1

VG Name               vg0

PV Size               2.01 GiB / not usable 7.16 MiB

Allocatable           yes (but full)

PE Size               16.00 MiB

Total PE              128

Free PE               0

Allocated PE          128

PV UUID               YkLroN-Nq14-lY4k-3SBM-OrSD-FvRX-a5yygJ

 

— Physical volume —

PV Name               /dev/sdc1

VG Name               vg0

PV Size               3.01 GiB / not usable 10.75 MiB

Allocatable           yes

PE Size               16.00 MiB

Total PE              192

Free PE               192

Allocated PE          0

PV UUID               62oDzs-YQmw-ctrO-kobU-sX20-AkgG-wiyrae

 

— Physical volume —

PV Name               /dev/sdf

VG Name               vg0

PV Size               5.00 GiB / not usable 16.00 MiB

Allocatable           yes

PE Size               16.00 MiB

Total PE              319

Free PE               127

Allocated PE          192

PV UUID               GzyIA6-LruV-iC1S-fCk0-iw8J-z2qy-Gzxq3X

 

[root@CentOS69 ~]#

 

 

3、将/dev/sdc1从vg0中移除

[root@CentOS69 ~]#pvs

PV         VG   Fmt  Attr PSize PFree

/dev/sdb1  vg0  lvm2 a–u 2.00g    0

/dev/sdc1  vg0  lvm2 a–u 3.00g 3.00g

/dev/sdf   vg0  lvm2 a–u 4.98g 1.98g

[root@CentOS69 ~]#vgreduce vg0 /dev/sdc1

Removed “/dev/sdc1” from volume group “vg0”

[root@CentOS69 ~]#pvs

PV         VG   Fmt  Attr PSize PFree

/dev/sdb1  vg0  lvm2 a–u 2.00g    0

/dev/sdc1       lvm2 —- 3.01g 3.01g

/dev/sdf   vg0  lvm2 a–u 4.98g 1.98g

[root@CentOS69 ~]#vgs

VG   #PV #LV #SN Attr   VSize VFree

vg0    2   2   0 wz–n- 6.98g 1.98g

[root@CentOS69 ~]#

 

4、将/dev/sdc1变成普通分区,去除pv属性(然后可以拆除)

[root@CentOS69 ~]#pvremove /dev/sdc1

Labels on physical volume “/dev/sdc1” successfully wiped

[root@CentOS69 ~]#pvs

PV         VG   Fmt  Attr PSize PFree

/dev/sdb1  vg0  lvm2 a–u 2.00g    0

/dev/sdf   vg0  lvm2 a–u 4.98g 1.98g

[root@CentOS69 ~]#

 

 

 

 

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/98398

(0)
linux_testlinux_test
上一篇 2018-05-13
下一篇 2018-05-13

相关推荐

  • 网络管理。

    网络管理: IEEE 802.3 (以太网)(物理层及数据联络层)wifiFDDI 城市网络OSI 开放系统互联,网络国际ISO 国际标准化组织ATM 异步传输模式细轴网线 最大185m粗轴网线 最大500m普通网线 最大100m 单工:单向传输数据双工:双向传输数据全双工:同时双向半双工:轮流双向 冲突域:网桥可以隔离冲突域。广播域:单播:unicast广…

    Linux笔记 2018-05-13
  • 网络安全基础知识和ssh

    加密基础 NISI定义的数据安全 保密性:数据保密性,隐私性 完整性:数据完整性,系统完整性 可用性:能正常获取其中信息 安全攻击 被动攻击:窃听 主动攻击:伪装(利用telnet伪装身份发邮件,利用dig查找邮件服务器),重放,消息篡改,拒绝服务 安全机制 加密,数据签字,访问控制,数据完整性,认证交换,流量填充,路由控制,公正 安全服务 认证;访问控制;…

    2018-05-20
  • docker学习记录系列(一)

    虚拟化与容器

    Linux笔记 2018-06-02
  • awk

    awk介绍awk里表示字符串要用双引号引起来awk:Aho, Weinberger, Kernighan,报告生成器,格式化文本输出有多种版本:New awk(nawk),GNU awk( gawk)gawk:模式扫描和处理语言基本用法:awk [options] ‘program’ var=value file… 选项,程序(语言),变量赋值awk [op…

    Linux笔记 2018-05-20