LVM 项目实战

本文详细介绍了LVM的实践操作,包括如何创建、扩展和缩减逻辑卷,针对ext系列的快照创建与恢复,以及xfs文件系统的快照管理。此外,还涵盖了逻辑卷的迁移和删除流程。
摘要由CSDN通过智能技术生成

1.创建逻辑卷

[root@centos7 wu]# lsblk   ####计划使用sde硬盘和sdd的一个分区sdd1来制作逻辑卷

NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda               8:0    0  200G  0 disk

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

└─sda2            8:2    0  133G  0 part

  ├─centos-root 253:0    0   80G  0 lvm  /

  ├─centos-swap 253:1    0    3G  0 lvm  [SWAP]

  └─centos-data 253:2    0   50G  0 lvm  /data

sdb               8:16   0   20G  0 disk

sdc               8:32   0    5G  0 disk

sdd               8:48   0    5G  0 disk

sde               8:64   0    5G  0 disk

sr0              11:0    1 1024M  0 rom  

[root@centos7 wu]# fdisk /dev/sdd

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.





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-10485759, default 2048):

Using default value 2048

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

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



Command (m for help): t       #####将分区类型改成8e linux LVM

Selected partition 1

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

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



Command (m for help): p



Disk /dev/sdd: 5368 MB, 5368709120 bytes, 10485760 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: 0x00000000



   Device Boot      Start         End      Blocks   Id  System

/dev/sdd1            2048     4196351     2097152   8e  Linux LVM



Command (m for help): w

The partition table has been altered!



Calling ioctl() to re-read partition table.

Syncing disks.

[root@centos7 wu]# lsblk    ####原有的sda2的逻辑卷不属于本次实验范围

NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda               8:0    0  200G  0 disk

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

└─sda2            8:2    0  133G  0 part

  ├─centos-root 253:0    0   80G  0 lvm  /

  ├─centos-swap 253:1    0    3G  0 lvm  [SWAP]

  └─centos-data 253:2    0   50G  0 lvm  /data

sdb               8:16   0   20G  0 disk

sdc               8:32   0    5G  0 disk

sdd               8:48   0    5G  0 disk

└─sdd1            8:49   0    2G  0 part

sde               8:64   0    5G  0 disk

sr0              11:0    1 1024M  0 rom  

[root@centos7 wu]# pvs

  PV         VG     Fmt  Attr PSize   PFree

  /dev/sda2  centos lvm2 a--  133.00g 4.00m

[root@centos7 wu]# pvcreate /dev/sd{d1,e}    ####将块设备创建成物理卷pv

WARNING: dos signature detected on /dev/sde at offset 510. Wipe it? [y/n]: y

  Wiping dos signature on /dev/sde.

  Physical volume "/dev/sdd1" successfully created.

  Physical volume "/dev/sde" successfully created.

[root@centos7 wu]# pvs    ####查看当前物理卷信息

  PV         VG     Fmt  Attr PSize   PFree

  /dev/sda2  centos lvm2 a--  133.00g 4.00m

  /dev/sdd1         lvm2 ---    2.00g 2.00g

  /dev/sde          lvm2 ---    5.00g 5.00g

[root@centos7 wu]# ll /dev/dm*   ####逻辑卷对应的物理设备是/dev/dm-# 下列的名称是之前产生的

brw-rw----. 1 root disk  253, 0 Aug 17 09:48 /dev/dm-0

brw-rw----. 1 root disk  253, 1 Aug 17 09:48 /dev/dm-1

brw-rw----. 1 root disk  253, 2 Aug 17 09:48 /dev/dm-2

crw-rw----+ 1 root audio  14, 9 Aug 17 09:48 /dev/dmmidi

[root@centos7 wu]# pvdisplay   ###物理卷的信息显示的更详细

  --- Physical volume ---

  PV Name               /dev/sda2

  VG Name               centos

  PV Size               <133.01 GiB / not usable 4.00 MiB

  Allocatable           yes

  PE Size               4.00 MiB

  Total PE              34049

  Free PE               1

  Allocated PE          34048

  PV UUID               3rZlBm-Larr-QIsV-98j4-oyo3-seJr-ubgL2z

   

  "/dev/sdd1" is a new physical volume of "2.00 GiB"

  --- NEW Physical volume ---

  PV Name               /dev/sdd1

  VG Name               

  PV Size               2.00 GiB

  Allocatable           NO

  PE Size               0   

  Total PE              0

  Free PE               0

  Allocated PE          0

  PV UUID               6z0fPO-LVXW-BaIx-igGb-XJ3X-Gb42-bcdoJf

   

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

  --- NEW Physical volume ---

  PV Name               /dev/sde

  VG Name               

  PV Size               5.00 GiB

  Allocatable           NO

  PE Size               0   

  Total PE              0

  Free PE               0

  Allocated PE          0

  PV UUID               mm7utv-Kwrx-Yuj4-FuYz-86ko-KNci-fqq38i

   

[root@centos7 wu]# blkid    ####可以查看到sdd1和sde属于LVM成员,并有UUID

/dev/sda1: UUID="9b42acab-3775-414e-b5ef-b00ad3417bd3" TYPE="xfs"

/dev/sda2: UUID="3rZlBm-Larr-QIsV-98j4-oyo3-seJr-ubgL2z" TYPE="LVM2_member"

/dev/mapper/centos-root: UUID="5c347ccc-b04c-41af-b08e-6b77ac5ed013" TYPE="xfs"

/dev/mapper/centos-swap: UUID="73df2278-0e61-4089-948f-8dd32d4a7837" TYPE="swap"

/dev/mapper/centos-data: UUID="c84e29d6-656a-4d38-b001-6c7e85b11b4d" TYPE="xfs"

/dev/sdb: PTTYPE="dos"

/dev/sdd1: UUID="6z0fPO-LVXW-BaIx-igGb-XJ3X-Gb42-bcdoJf" TYPE="LVM2_member"

/dev/sdc: PTTYPE="dos"

/dev/sde: UUID="mm7utv-Kwrx-Yuj4-FuYz-86ko-KNci-fqq38i" TYPE="LVM2_member"

[root@centos7 wu]# ll /dev/mapper/  ####创建逻辑卷时自动会生成软连接,便于记忆

total 0

lrwxrwxrwx. 1 root root       7 Aug 17 09:48 centos-data -> ../dm-2

lrwxrwxrwx. 1 root root       7 Aug 17 09:48 centos-root -> ../dm-0

lrwxrwxrwx. 1 root root       7 Aug 17 09:48 centos-swap -> ../dm-1

crw-------. 1 root root 10, 236 Aug 17 09:48 control

[root@centos7 wu]# vgcreate vg0 -s 16M /dev/sd{d1,e} ####-s指定PE大小,16M作为PE

  Volume group "vg0" successfully created

[root@centos7 wu]# pvs

  PV         VG     Fmt  Attr PSize   PFree

  /dev/sda2  centos lvm2 a--  133.00g 4.00m

  /dev/sdd1  vg0    lvm2 a--    1.98g 1.98g

  /dev/sde   vg0    lvm2 a--    4.98g 4.98g

[root@centos7 wu]# pvdisplay     #####查看相应的物理卷已经有了相应的卷组名

  --- Physical volume ---

  PV Name               /dev/sda2

  VG Name               centos

  PV Size               <133.01 GiB / not usable 4.00 MiB

  Allocatable           yes

  PE Size               4.00 MiB

  Total PE              34049

  Free PE               1

  Allocated PE          34048

  PV UUID               3rZlBm-Larr-QIsV-98j4-oyo3-seJr-ubgL2z

   

  --- Physical volume ---

  PV Name               /dev/sdd1

  VG Name               vg0

  PV Size               2.00 GiB / not usable 16.00 MiB

  Allocatable           yes

  PE Size               16.00 MiB

  Total PE              127

  Free PE               127

  Allocated PE          0

  PV UUID               6z0fPO-LVXW-BaIx-igGb-XJ3X-Gb42-bcdoJf

   

  --- Physical volume ---

  PV Name               /dev/sde

  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               mm7utv-Kwrx-Yuj4-FuYz-86ko-KNci-fqq38i

   

[root@centos7 wu]# vgdisplay    ####查看卷组的详情

  --- Volume group ---

  VG Name               centos

  System ID             

  Format                lvm2

  Metadata Areas        1

  Metadata Sequence No  4

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                3

  Open LV               3

  Max PV                0

  Cur PV                1

  Act PV                1

  VG Size               133.00 GiB

  PE Size               4.00 MiB

  Total PE              34049

  Alloc PE / Size       34048 / 133.00 GiB

  Free  PE / Size       1 / 4.00 MiB

  VG UUID               qo9iuP-nFZF-G794-GmAm-jbJS-Kn31-7vT7g9

   

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

  PE Size               16.00 MiB

  Total PE              446

  Alloc PE / Size       0 / 0   

  Free  PE / Size       446 / <6.97 GiB

  VG UUID               5FDPqC-7ihy-eYQK-OXlx-eVac-Z3I2-gjup3X

   

[root@centos7 wu]# lvcreate -n lv0 -L 1.5G vg0    #####创建逻辑卷,-n接逻辑卷名,-L接大小,也可以用-l接PE的个数

  Logical volume "lv0" created.

[root@centos7 wu]# lvs

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

  data centos -wi-ao---- 50.00g                                                    

  root centos -wi-ao---- 80.00g                                                    

  swap centos -wi-ao----  3.00g                                                    

  lv0  vg0    -wi-a-----  1.50g                                                    

[root@centos7 wu]# pvs

  PV         VG     Fmt  Attr PSize   PFree  

  /dev/sda2  centos lvm2 a--  133.00g   4.00m

  /dev/sdd1  vg0    lvm2 a--    1.98g 496.00m

  /dev/sde   vg0    lvm2 a--    4.98g   4.98g

[root@centos7 wu]# lvs

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

  data centos -wi-ao---- 50.00g                                                    

  root centos -wi-ao---- 80.00g                                                    

  swap centos -wi-ao----  3.00g                                                    

  lv0  vg0    -wi-a-----  1.50g                                                    

[root@centos7 wu]# lvdisplay

  --- Logical volume ---

  LV Path                /dev/centos/data

  LV Name                data

  VG Name                centos

  LV UUID                bWJr3f-Qo3m-qlul-92Xr-4cmw-hovC-ppVKNP

  LV Write Access        read/write

  LV Creation host, time centos7.localdomain, 2018-07-19 09:22:52 +0800

  LV Status              available

  # open                 1

  LV Size                50.00 GiB

  Current LE             12800

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:2

   

  --- Logical volume ---

  LV Path                /dev/centos/root

  LV Name                root

  VG Name                centos

  LV UUID                Azqf1E-S3Cg-50vz-wwPx-eKew-ZM85-2EzLHO

  LV Write Access        read/write

  LV Creation host, time centos7.localdomain, 2018-07-19 09:22:52 +0800

  LV Status              available

  # open                 1

  LV Size                80.00 GiB

  Current LE             20480

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:0

   

  --- Logical volume ---

  LV Path                /dev/centos/swap

  LV Name                swap

  VG Name                centos

  LV UUID                kNauft-ydTo-nP4e-jMdo-kTsp-so8x-i9yOsg

  LV Write Access        read/write

  LV Creation host, time centos7.localdomain, 2018-07-19 09:22:53 +0800

  LV Status              available

  # open                 2

  LV Size                3.00 GiB

  Current LE             768

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:1

   

  --- Logical volume ---

  LV Path                /dev/vg0/lv0

  LV Name                lv0

  VG Name                vg0

  LV UUID                NezWB7-Iycl-WcIS-m3uG-A9u5-KUXp-FlSVfe

  LV Write Access        read/write

  LV Creation host, time centos7.localdomain, 2018-08-17 16:43:34 +0800

  LV Status              available

  # open                 0

  LV Size                1.50 GiB

  Current LE             96

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     8192

  Block device           253:3

   

[root@centos7 wu]# ll /dev/vg0/lv0    ####另一个软连接名称,此软连接名更好记一点

lrwxrwxrwx. 1 root root 7 Aug 17 16:43 /dev/vg0/lv0 -> ../dm-3

[root@centos7 wu]# ll /dev/mapper/vg0-lv0

lrwxrwxrwx. 1 root root 7 Aug 17 16:43 /dev/mapper/vg0-lv0 -> ../dm-3

[root@centos7 wu]# vgs

  VG     #PV #LV #SN Attr   VSize   VFree

  centos   1   3   0 wz--n- 133.00g  4.00m

  vg0      2   1   0 wz--n-  <6.97g <5.47g

[root@centos7 wu]# lvcreate -n lv1 -l 100%FREE vg0   ####将卷组的剩余空间全部分配给逻辑卷lv1使用

  Logical volume "lv1" created.

[root@centos7 wu]# lvs

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

  data centos -wi-ao---- 50.00g                                                    

  root centos -wi-ao---- 80.00g                                                    

  swap centos -wi-ao----  3.00g                                                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值