印度阿三17 / 开发 / LVM逻辑卷详解

分享

   

LVM逻辑卷详解

2020-01-11  印度阿三17

LVM: Logical Volume Manager 可以允许对卷进行方便操作的抽象层,包括重新设定文件系统的大小,允许在多个物理设备间重新组织文件系统,可增大可缩减(缩减必须取消挂载会导致数据丢失)弹性更改

逻辑分区与逻辑卷的区别

逻辑卷与逻辑分区不是同一概念,逻辑分区容量大小不能改变;逻辑卷容量大小可以改变(基于物理卷和卷组之上的逻辑卷);逻辑卷管理器(LVM)可以更轻松的管理磁盘空间(整合的磁盘池)

以下是原理图,可以更好的理解

在这里插入图片描述

#创建物理卷 

pvcreate /dev/sda3 

\#为卷组分配物理卷 

vgcreate vg0 /dev/sda3 

\#从卷组创建逻辑卷 

lvcreate  -L 256M  -n data vg0 

\#mkfs.xfs   /dev/vg0/data 
创建文件系统

\#挂载 

mount /dev/vg0/data /mnt/data#
扩展

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

\#针对ext 

resize2fs /dev/VG_NAME/LV_NAME 

\#针对xfs  

xfs_growfs MOUNTPOINT  

lvresize -r -l  100%FREE /dev/VG_NAME/LV_NAME
缩减 只支持ext4
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 

mount 

可以是硬盘 可以是分区 分区需要改类型

范例 :针对ext4 创建逻辑分区以及扩展分区

[root@27 ~]#fdisk -l /dev/sdb

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x2d890684

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   82  Linux swap / Solaris
/dev/sdb2         4196352     8390655     2097152   83  Linux #修改文件类型
[root@27 ~]#fdisk /dev/sdb2
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 0x59eb2927.

Command (m for help): t
No partition is defined yet!

Command (m for help): q

[root@27 ~]#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.


Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 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      
Hex code (type L to list all codes): 8e (改成Linux LVM)
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x2d890684

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   82  Linux swap / Solaris
/dev/sdb2         4196352     8390655     2097152   8e  Linux LVM  #发现已经修改

Command (m for help): w #保存
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
添加一块硬盘扫描
[root@27 ~]#for i in {0..32};do echo '- - -' >/sys/class/scsi_host/host$i/scan;done
[root@27 ~]#lsblk
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  100G  0 part /
├─sda3   8:3    0    2G  0 part [SWAP]
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0   50G  0 part /data
sdb      8:16   0   20G  0 disk 
├─sdb1   8:17   0    2G  0 part [SWAP]
└─sdb2   8:18   0    2G  0 part 
sdc      8:32   0    5G  0 disk  #是这块
sr0     11:0    1 1024M  0 rom 
[root@27 ~]#pvcreate /dev/sd{b2,c} 创建物理卷
  Physical volume "/dev/sdb2" successfully created.
  Physical volume "/dev/sdc" successfully created.
[root@27 ~]#pvs  查看物理卷
  PV         VG Fmt  Attr PSize PFree
  /dev/sdb2     lvm2 ---  2.00g 2.00g
  /dev/sdc      lvm2 ---  5.00g 5.00g
[root@27 ~]#pvdisplay 查看详细信息
  "/dev/sdb2" is a new physical volume of "2.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb2
  VG Name               
  PV Size               2.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               jmJ13J-XHgq-ou2J-QVvB-CXy1-FTYX-8mnC5r
   
  "/dev/sdc" is a new physical volume of "5.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc
  VG Name                              为空
  PV Size               5.00 GiB
  Allocatable           NO
  PE Size               0             PE大小没有指定 由卷组指定
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               IQ0xHD-btaL-XmmT-cE9Q-BQMU-kYA2-ZDUZxQ
[root@27 ~]#vgcreate vg1 /dev/sd{b2,c}    
#######vgcreate -s 16M vg1 /dev/sd{b2,c}   -s可以指定PE大小
  Volume group "vg1" successfully created
[root@27 ~]#vgs
  VG  #PV #LV #SN Attr   VSize VFree
  vg1   2   0   0 wz--n- 6.99g 6.99g
[root@27 ~]#pvs
  PV         VG  Fmt  Attr PSize  PFree 
  /dev/sdb2  vg1 lvm2 a--  <2.00g <2.00g
  /dev/sdc   vg1 lvm2 a--  <5.00g <5.00g
[root@27 ~]#vgdisplay
  --- Volume group ---
  VG Name               vg1
  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.99 GiB
  PE Size               4.00 MiB
  Total PE              1790
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1790 / 6.99 GiB
  VG UUID               OBZcYO-20eN-m2E6-bDn8-ZUCg-Pfro-7caBik
[root@27 ~]#lvcreate -n shuju -l 100%free vg1 分配所有空间 选择性分配
  Logical volume "shuju" created.
[root@27 ~]#lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg1/shuju   #逻辑卷的名称
  LV Name                shuju
  VG Name                vg1
  LV UUID                zKB4qu-XMnJ-U4Qx-2IlZ-XRT6-f7km-m6mB9q
  LV Write Access        read/write
  LV Creation host, time 27, 2020-01-04 14:47:28  0800
  LV Status              available
  # open                 0
  LV Size                6.99 GiB
  Current LE             1790
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:、
[root@27 ~]#mkfs.ext4 /dev/vg1/shuju 创建文件系统
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
458752 inodes, 1832960 blocks
91648 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1876951040
56 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@27 ~]#blkid
/dev/sda1: UUID="b09c53db-dbe8-4932-ad6e-2b0890ea8844" TYPE="xfs" 
/dev/sda2: UUID="703b7b55-0dc1-40fc-bfc5-e9a581c48a05" TYPE="xfs" 
/dev/sda3: UUID="16ba9174-387a-4725-8cdf-e67c7a52d3bc" TYPE="swap" 
/dev/sda5: UUID="b944d856-d1ac-4694-8c59-04399a8b4786" TYPE="xfs" 
/dev/sdb1: UUID="95565861-5268-4482-bf6d-349a97322559" TYPE="swap" 
/dev/sdb2: UUID="jmJ13J-XHgq-ou2J-QVvB-CXy1-FTYX-8mnC5r" TYPE="LVM2_member" 
/dev/sdc: UUID="IQ0xHD-btaL-XmmT-cE9Q-BQMU-kYA2-ZDUZxQ" TYPE="LVM2_member" 
/[root@27 ~]#mount /dev/vg1/shuju /mnt/shuju
[root@27 ~]#mkdir /mnt/shuju
[root@27 ~]#df
Filesystem            1K-blocks    Used Available Use% Mounted on
devtmpfs                1919944       0   1919944   0% /dev
tmpfs                   1930684       0   1930684   0% /dev/shm
tmpfs                   1930684   11908   1918776   1% /run
tmpfs                   1930684       0   1930684   0% /sys/fs/cgroup
/dev/sda2             104806400 1500324 103306076   2% /
/dev/sda5              52403200   32992  52370208   1% /data
/dev/sda1               1038336  144220    894116  14% /boot
tmpfs                    386140       0    386140   0% /run/user/0
/dev/mapper/vg1-shuju   7085560   32208   6670376   1% /mnt/shuju
/mapper/vg1-shuju: UUID="4e49d747-9616-418f-b66a-c07f41a0de98" TYPE="ext4" 
#写到 /etc/fstab 永久挂载
[root@27 ~]#vgextend vg1 /dev/sdb3 扩展逻辑卷
  Physical volume "/dev/sdb3" successfully created.
  Volume group "vg1" successfully extended
[root@27 ~]#pvs
  PV         VG  Fmt  Attr PSize    PFree   
  /dev/sdb2  vg1 lvm2 a--    <2.00g       0 
  /dev/sdb3  vg1 lvm2 a--  1020.00m 1020.00m
  /dev/sdc   vg1 lvm2 a--    <5.00g       0 
[root@27 ~]#df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               1.9G     0  1.9G   0% /dev
tmpfs                  1.9G     0  1.9G   0% /dev/shm
tmpfs                  1.9G   12M  1.9G   1% /run
tmpfs                  1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda2              100G  1.5G   99G   2% /
/dev/sda5               50G   33M   50G   1% /data
/dev/sda1             1014M  141M  874M  14% /boot
tmpfs                  378M     0  378M   0% /run/user/0
/dev/mapper/vg1-shuju  6.8G   32M  6.4G   1% /mnt/shuju 查看
[root@27 ~]#lvextend -r -L  500M /dev/vg1/shuju 加500M
  Size of logical volume vg1/shuju changed from 6.99 GiB (1790 extents) to 7.48 GiB (1915 extents).
  Logical volume vg1/shuju successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/vg1-shuju is mounted on /mnt/shuju; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/vg1-shuju is now 1960960 blocks long.
[root@27 ~]#df -h 
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               1.9G     0  1.9G   0% /dev
tmpfs                  1.9G     0  1.9G   0% /dev/shm
tmpfs                  1.9G   12M  1.9G   1% /run
tmpfs                  1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda2              100G  1.5G   99G   2% /
/dev/sda5               50G   33M   50G   1% /data
/dev/sda1             1014M  141M  874M  14% /boot
tmpfs                  378M     0  378M   0% /run/user/0
/dev/mapper/vg1-shuju  7.3G   32M  6.9G   1% /mnt/shuju   与上面对比空间增大
#######删除lvm逻辑卷
[root@27 ~]#lvremove /dev/vg1/shuju
Do you really want to remove active logical volume vg1/shuju? [y/n]: y 提示是否删除
  Logical volume "shuju" successfully removed
  [root@27 ~]#vgdisplay
  --- Volume group ---
  VG Name               vg1
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  10
  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               <7.99 GiB
  PE Size               4.00 MiB
  Total PE              2045
  Alloc PE / Size       0 / 0   
  Free  PE / Size       2045 / <7.99 GiB
  VG UUID               OBZcYO-20eN-m2E6-bDn8-ZUCg-Pfro-7caBik
   
[root@27 ~]#vgremove vg1 删除卷组
  Volume group "vg1" successfully removed
  [root@27 ~]#pvs
  PV         VG Fmt  Attr PSize PFree
  /dev/sdb2     lvm2 ---  2.00g 2.00g
  /dev/sdb3     lvm2 ---  1.00g 1.00g
  /dev/sdc      lvm2 ---  5.00g 5.00g
[root@27 ~]#pvremove /dev/sd{b2,b3,c} 删除逻辑卷
  Labels on physical volume "/dev/sdb2" successfully wiped.
  Labels on physical volume "/dev/sdb3" successfully wiped.
  Labels on physical volume "/dev/sdc" successfully wiped.
[root@27 ~]#fdisk -l /dev/sdb

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x2d890684

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   82  Linux swap / Solaris
/dev/sdb2         4196352     8390655     2097152   8e  Linux LVM  #也可以删除
/dev/sdb3         8390656    10487807     1048576   83  Linux
/dev/sdb4        10487808    12584959     1048576   83  Linux

逻辑卷快照

快照是特殊的逻辑卷,它是在生成快照时存在的逻辑卷的准确拷贝,对于需要备份或者复制的现有数据临时拷贝以及其它操作来说,快照是最合适的选择,快照只有在它们和原来的逻辑卷不同时才会消耗空间,建立快照的卷大小小于等于原始逻辑卷,也可以使用lvextend扩展快照
逻辑卷管理器快照
快照就是将当时的系统信息记录下来,就好像照相一般,若将来有任何数据改动了,则原始数据会被移动到快照区,没有改动的区域则由快照区和文件系统共享
逻辑卷快照工作原理
在生成快照时会分配给它一定的空间,但只有在原来的逻辑卷或者快照有所改变才会使用这些空间,当原来的逻辑卷中有所改变时,会将旧的数据复制到快照中,快照中只含有原来的逻辑卷中更改的数据或者自生成快照后的快照中更改的数据,由于快照区与原本的LV共用很多PE的区块,因此快照与被快照的LV必须在同一个VG中.系统恢复的时候的文件数量不能高于快照区的实际容量

#为现有逻辑卷创建快照 快照大小小于等于逻辑卷大小 快照包括属性备份

lvcreate -l 64 -s -n data-snapshot -p r /dev/vg0/data 

\#挂载快照 

mkdir  -p /mnt/snap 

mount -o ro /dev/vg0/data-snapshot   /mnt/snap 

\#恢复快照 

umount /dev/vg0/data-snapshot 

umount /dev/vg0/data 

lvconvert --merge /dev/vg0/data-snapshot  

\#删除快照 

umount /mnt/databackup 

lvremove /dev/vg0/databackup
快照范例
[root@27 ~]#df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               1.9G     0  1.9G   0% /dev
tmpfs                  1.9G     0  1.9G   0% /dev/shm
tmpfs                  1.9G   12M  1.9G   1% /run
tmpfs                  1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda2              100G  1.5G   99G   2% /
/dev/sda5               50G   33M   50G   1% /data
/dev/sda1             1014M  141M  874M  14% /boot
tmpfs                  378M     0  378M   0% /run/user/0
/dev/mapper/vg1-shuju  7.3G   32M  6.9G   1% /mnt/shuju
[root@27 ~]#cp /etc/fstab /mnt/shuju/f1
[root@27 ~]#cp /etc/fstab /mnt/shuju/f2
[root@27 ~]#cp /etc/fstab /mnt/shuju/f3
[root@27 ~]#ls /mnt/shuju
f1  f2  f3  lost found
[root@27 ~]#lvcreate -n shuju_snapshot -s -p r -L 300M /dev/vg1/shuju
##### -n 指定名字 -s快照  r只读
  Logical volume "shuju_snapshot" created.
[root@27 ~]#lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg1/shuju
  LV Name                shuju
  VG Name                vg1
  LV UUID                zKB4qu-XMnJ-U4Qx-2IlZ-XRT6-f7km-m6mB9q
  LV Write Access        read/write
  LV Creation host, time 27, 2020-01-04 14:47:28  0800
  LV snapshot status     source of
                         shuju_snapshot [active]   显示有快照
  LV Status              available
  # open                 1
  LV Size                7.48 GiB
  Current LE             1915
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/vg1/shuju_snapshot
  LV Name                shuju_snapshot   快照
  VG Name                vg1
  LV UUID                G8n4yi-FOkw-RlbZ-GtEf-8IHh-4fRw-hYnoma
  LV Write Access        read only   只读属性
  LV Creation host, time 27, 2020-01-04 15:39:49  0800
  LV snapshot status     active destination for shuju  对数据的备份
  LV Status              available
  # open                 0
  LV Size                7.48 GiB
  Current LE             1915
  COW-table size         300.00 MiB
  COW-table LE           75
  Allocated to snapshot  0.01%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3
[root@27 ~]#mkdir /mnt/snap
root@27 ~]#mount /dev/vg1/shuju_snapshot /mnt/snap
mount: /dev/mapper/vg1-shuju_snapshot is write-protected, mounting read-only
[root@27 ~]#ls /mnt/snap/
f1  f2  f3  lost found  视觉欺骗 你看到的数据并不在这里
[root@27 ~]#df
Filesystem                     1K-blocks    Used Available Use% Mounted on
devtmpfs                         1919940       0   1919940   0% /dev
tmpfs                            1930680       0   1930680   0% /dev/shm
tmpfs                            1930680   11904   1918776   1% /run
tmpfs                            1930680       0   1930680   0% /sys/fs/cgroup
/dev/sda2                      104806400 1499084 103307316   2% /
/dev/sda5                       52403200   32992  52370208   1% /data
/dev/sda1                        1038336  144348    893988  14% /boot
tmpfs                             386140       0    386140   0% /run/user/0
/dev/mapper/vg1-shuju            7589336   32220   7153988   1% /mnt/shuju
/dev/mapper/vg1-shuju_snapshot   7589336   32220   7153988   1% /mnt/snap
[root@27 ~]#echo > /mnt/shuju/f1
[root@27 ~]#ll /mnt/shuju
total 28
-rw-r--r--. 1 root root     1 Jan  4 15:57 f1  数据清空
-rw-r--r--. 1 root root   689 Jan  4 15:30 f2
-rw-r--r--. 1 root root   689 Jan  4 15:30 f3
drwx------. 2 root root 16384 Jan  4 14:54 lost found
[root@27 ~]#ll /mnt/snap/f1
-rw-r--r--. 1 root root 689 Jan  4 15:30 /mnt/snap/f1  查看数据在快照中
[root@27 ~]#rm -f /mnt/shuju/f2 删除f2
[root@27 ~]#ll /mnt/shuju/
total 24
-rw-r--r--. 1 root root     1 Jan  4 15:57 f1
-rw-r--r--. 1 root root   689 Jan  4 15:30 f3
drwx------. 2 root root 16384 Jan  4 14:54 lost found
[root@27 ~]#ll /mnt/snap 快照依旧存在
total 28
-rw-r--r--. 1 root root   689 Jan  4 15:30 f1
-rw-r--r--. 1 root root   689 Jan  4 15:30 f2
-rw-r--r--. 1 root root   689 Jan  4 15:30 f3
drwx------. 2 root root 16384 Jan  4 14:54 lost found
[root@27 ~]#umount /mnt/shuju
[root@27 ~]#umount /mnt/snap
[root@27 ~]#lvconvert --merge /dev/vg1/shuju_snapshot   恢复快照
  Merging of volume vg1/shuju_snapshot started.
  vg1/shuju: Merged: 100.00%
[root@27 ~]#mount /dev/vg1/shuju /mnt/shuju
[root@27 ~]#ls /mnt/shuju
f1  f2  f3  lost found
注意:快照是一次性的 用完就没有了
假如sdb2快将要坏掉
[root@27 ~]#pvs
  PV         VG  Fmt  Attr PSize    PFree  
  /dev/sdb2  vg1 lvm2 a--    <2.00g      0 
  /dev/sdb3  vg1 lvm2 a--  1020.00m 520.00m
  /dev/sdc   vg1 lvm2 a--    <5.00g      0 
[root@27 ~]#pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb2
  VG Name               vg1
  PV Size               2.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              511
  Free PE               0
  Allocated PE          511
  PV UUID               jmJ13J-XHgq-ou2J-QVvB-CXy1-FTYX-8mnC5r
   
  --- Physical volume ---
  PV Name               /dev/sdc
  VG Name               vg1
  PV Size               2.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              511
  Free PE               0
  Allocated PE          511
  PV UUID               IQ0xHD-btaL-XmmT-cE9Q-BQMU-kYA2-ZDUZxQ
   
  --- Physical volume ---
  PV Name               /dev/sdb3
  VG Name               vg1
  PV Size               5.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              1279
  Free PE               1154 我们发现这个还有1154 PE
  Allocated PE          125
  PV UUID               RGQEM5-1beD-BzaI-I1Pq-gng4-aUJZ-lEKlrP
[root@27 ~]#pvmove /dev/sdc 将sdb2的PE移动到其他上 (有空间就行随便哪个)
Removed "/dev/sdb2" from volume group "vg1"
[root@27 ~]#pvdisplay /dev/sdbc
  --- Physical volume ---
  PV Name               /dev/sdc
  VG Name                           可以看到不属于任何vg 空间也会相应的变少
  PV Size               2.00 GiB 
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               jmJ13J-XHgq-ou2J-QVvB-CXy1-FTYX-8mnC5r
[root@27 ~]#pvs
  PV         VG  Fmt  Attr PSize    PFree  
  /dev/sdb2  vg1 lvm2 a--    <2.00g      0 
  /dev/sdb3  vg1 lvm2 a--  1020.00m 520.00m
  /dev/sdc        lvm2 a--    <5.00g      0 
  [root@27 ~]#pvremove /dev/sdc 移除就可以直接拔掉 分区可以删除
 
volume ---
  PV Name               /dev/sdc
  VG Name                           可以看到不属于任何vg 空间也会相应的变少
  PV Size               2.00 GiB 
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               jmJ13J-XHgq-ou2J-QVvB-CXy1-FTYX-8mnC5r
[root@27 ~]#pvs
  PV         VG  Fmt  Attr PSize    PFree  
  /dev/sdb2  vg1 lvm2 a--    <2.00g      0 
  /dev/sdb3  vg1 lvm2 a--  1020.00m 520.00m
  /dev/sdc        lvm2 a--    <5.00g      0 
  [root@27 ~]#pvremove /dev/sdc 移除就可以直接拔掉 分区可以删除  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多
    喜欢该文的人也喜欢 更多

    ×
    ×

    ¥.00

    微信或支付宝扫码支付:

    开通即同意《个图VIP服务协议》

    全部>>