LVM逻辑卷管理
LVM逻辑卷管理
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 基本概念 9 Logical Volume Manager 10 ** 多个物理分区/磁盘 ==> 组合成一个整体 ==>划分逻辑存储单位,即逻辑卷 11 ** 逻辑分区的大小可以根据需要扩大、缩减 12 ** /boot 用来存放引导文件,不能使用LVM逻辑卷(启动时会找不到内核) 13 14 PV(Physical Volume,物理卷): 15 物理分区,或整个物理磁盘 16 由PE(Physical Extent,基本单元)组成 【PE默认4MB】 17 VG(Volume Group,卷组) 18 一个或多个物理卷组成的逻辑整体 19 LV(Logical Volume,逻辑卷) 20 从卷组中分割出的一块逻辑存储空间 21 经过格式化可建立文件系统 22 23 '''
注意:逻辑卷不能直接使用!也是需要格式化,格式化的过程就是指定文件系统。让我们一起看看如何管理这些逻辑卷呢?如果将PV转换成VG呢?又是如何将VG转换成LV的呢?我们可以利用图像化工具:图形化管理工具: system-config-lvm。但是作为运维的我们一般都是会用命令来实现,因此我下面的教程也都是基于命令的,先把基本的命令给大家总览一下吧:
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 LVM:Logical Volume Manager,将多块设备组合成一个来使用 9 10 11 盘区: 12 13 14 dm:device maooer 设备映射 15 16 设备文件 /dev/卷组名/逻辑卷名 17 /dev/mapper/卷组名-逻辑卷名 18 19 20 物理卷命令命令:pv 21 pvcreate pvremove psdisplay pvscan pvs pvmove(移动数据) 22 pvcreate 物理卷 23 卷组的管理命令:vg 24 vgcreate vgscan vgs vgextend(扩充)、vgremove(删除) vgreduce(移除,缩容) 25 vgcreate 26 -s:pe大小,默认4M 27 逻辑卷的管理命令:lv 28 lvcreate lvscan lvs lvextend(扩充)、lvremove(删除) vgreduce(移除,缩容) 29 30 lvcreate 31 -n:指定名称 32 -L: 指定大小 33 -l:%vg|pvs|FREE,打算分配% 34 35 36 逻辑卷扩展的步骤: 37 1.先确保扩展的大小;并确保所属的卷组有足够的剩余空间 38 2、扩展物理边界 39 lvextend -L [+]size /path/to/lv_device 40 3、扩展逻辑边界 41 resize2fs /path/to/lv_devive 42 缩减逻辑卷的步骤: 43 1、卸载卷,并执行强制检查 44 e2fsck -f /path/to/lv_devive 45 2、缩减逻辑边界 46 resize2fs /path/to/lv_device SIZE 47 3、缩减物理边界: 48 lvreduce -L [-]size /path/to/lv_device 49 4、挂载卷 50 51 快照: 52 也是逻辑卷的一种,提供过去某一时间的元卷的通道 53 lvcreate -s -L Size -n name 卷组名 -p r,rw /path/to/lv_devsive 54 -p:访问权限 55 56 57 扩展卷组: 58 1.准备要添加的物理卷 59 2 扩展卷组: 60 添加物理卷至卷组中 61 vgextend vg_name /path/to/device 62 缩减卷组: 63 1.确定要移除的物理卷的总空间大小,要小于VG当前的可用空间大小 64 2.将要移除的物理卷上的所有pe移动至其他PV 65 pvmove /path/to/pv_device 66 3.缩减vg 67 #vgreduce vg_name /path/to/pv/device
68 4、挂载卷 69 '''
操作环境:
创建一个10G的LVM
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 [root@yinzhengjie ~]# ls /dev/sdb* #查看有一块空磁盘 9 /dev/sdb 10 [root@yinzhengjie ~]# fdisk /dev/sdb #对这个空磁盘进行分区 11 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel 12 Building a new DOS disklabel with disk identifier 0x7ecc698f. 13 Changes will remain in memory only, until you decide to write them. 14 After that, of course, the previous content won't be recoverable. 15 16 Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 17 18 WARNING: DOS-compatible mode is deprecated. It's strongly recommended to 19 switch off the mode (command 'c') and change display units to 20 sectors (command 'u'). 21 22 Command (m for help): p 23 24 Disk /dev/sdb: 21.5 GB, 21474836480 bytes 25 255 heads, 63 sectors/track, 2610 cylinders 26 Units = cylinders of 16065 * 512 = 8225280 bytes 27 Sector size (logical/physical): 512 bytes / 512 bytes 28 I/O size (minimum/optimal): 512 bytes / 512 bytes 29 Disk identifier: 0x7ecc698f 30 31 Device Boot Start End Blocks Id System 32 33 Command (m for help): n 34 Command action 35 e extended 36 p primary partition (1-4) 37 p 38 Partition number (1-4): 1 39 First cylinder (1-2610, default 1): 40 Using default value 1 41 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +3G 42 43 Command (m for help): n 44 Command action 45 e extended 46 p primary partition (1-4) 47 p 48 Partition number (1-4): 2 49 First cylinder (394-2610, default 394): 50 Using default value 394 51 Last cylinder, +cylinders or +size{K,M,G} (394-2610, default 2610): +7G 52 53 Command (m for help): t #调整分区的ID,似的其分区类型为LVM 54 Partition number (1-4): 1 55 Hex code (type L to list codes): L 56 57 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 58 1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- 59 2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 60 3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 61 4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx 62 5 Extended 42 SFS 86 NTFS volume set da Non-FS data 63 6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 64 7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 65 8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt 66 9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access 67 a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O 68 b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor 69 c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs 70 e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT 71 f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ 72 10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b 73 11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 74 12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor 75 14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 76 16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS 77 17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE 78 18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto 79 1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep 80 1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT 81 1e Hidden W95 FAT1 82 Hex code (type L to list codes): 8e 83 Changed system type of partition 1 to 8e (Linux LVM) 84 85 Command (m for help): t #调整分区的ID,似的其分区类型为LVM 86 Partition number (1-4): 2 87 Hex code (type L to list codes): 8e 88 Changed system type of partition 2 to 8e (Linux LVM) 89 90 Command (m for help): p #查看以上分区情况 91 92 Disk /dev/sdb: 21.5 GB, 21474836480 bytes 93 255 heads, 63 sectors/track, 2610 cylinders 94 Units = cylinders of 16065 * 512 = 8225280 bytes 95 Sector size (logical/physical): 512 bytes / 512 bytes 96 I/O size (minimum/optimal): 512 bytes / 512 bytes 97 Disk identifier: 0x7ecc698f 98 99 Device Boot Start End Blocks Id System 100 /dev/sdb1 1 393 3156741 8e Linux LVM 101 /dev/sdb2 394 1308 7349737+ 8e Linux LVM 102 103 Command (m for help): w #保存当前配置。 104 The partition table has been altered! 105 106 Calling ioctl() to re-read partition table. 107 Syncing disks. 108 [root@yinzhengjie ~]# 109 [root@yinzhengjie ~]# cat /proc/partitions #查看系统是否有分区信息,如果没有就得重读分区表再次查看。 110 major minor #blocks name 111 112 8 16 20971520 sdb 113 8 17 3156741 sdb1 114 8 18 7349737 sdb2 115 8 0 20971520 sda 116 8 1 307200 sda1 117 8 2 18631680 sda2 118 8 3 2031616 sda3 119 [root@yinzhengjie ~]# 120 121 '''
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 [root@yinzhengjie ~]# pvcreate /dev/sdb{1,2} #创建物理卷组(将sdb1和sdb2这2个分区添加到物理卷组中去)。 9 Physical volume "/dev/sdb1" successfully created 10 Physical volume "/dev/sdb2" successfully created 11 [root@yinzhengjie ~]# pvs #查看当前物理卷组信息。 12 PV VG Fmt Attr PSize PFree 13 /dev/sdb1 lvm2 --- 3.01g 3.01g 14 /dev/sdb2 lvm2 --- 7.01g 7.01g 15 [root@yinzhengjie ~]# 16 [root@yinzhengjie ~]# pvdisplay #查看所有物理卷信息 17 "/dev/sdb1" is a new physical volume of "3.01 GiB" 18 --- NEW Physical volume --- 19 PV Name /dev/sdb1 20 VG Name 21 PV Size 3.01 GiB 22 Allocatable NO 23 PE Size 0 24 Total PE 0 25 Free PE 0 26 Allocated PE 0 27 PV UUID A25Lv7-ZOKU-dtqm-eZDG-rFt0-up22-ofm8Oc 28 29 "/dev/sdb2" is a new physical volume of "7.01 GiB" 30 --- NEW Physical volume --- 31 PV Name /dev/sdb2 32 VG Name 33 PV Size 7.01 GiB 34 Allocatable NO 35 PE Size 0 36 Total PE 0 37 Free PE 0 38 Allocated PE 0 39 PV UUID pM2qr0-yz7k-GRfo-a6Qw-BksQ-kxdh-050IXh 40 41 [root@yinzhengjie ~]# pvdisplay /dev/sdb1 #单独查看某个物理卷信息 42 "/dev/sdb1" is a new physical volume of "3.01 GiB" 43 --- NEW Physical volume --- 44 PV Name /dev/sdb1 45 VG Name 46 PV Size 3.01 GiB 47 Allocatable NO 48 PE Size 0 49 Total PE 0 50 Free PE 0 51 Allocated PE 0 52 PV UUID A25Lv7-ZOKU-dtqm-eZDG-rFt0-up22-ofm8Oc 53 54 [root@yinzhengjie ~]# 55 '''
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 [root@yinzhengjie ~]# vgcreate yinzhengjie_vgs /dev/sdb{1,2} #创建卷组 9 Volume group "yinzhengjie_vgs" successfully created 10 [root@yinzhengjie ~]# vgs #查看当前以及创建的卷组信息 11 VG #PV #LV #SN Attr VSize VFree 12 yinzhengjie_vgs 2 0 0 wz--n- 10.02g 10.02g 13 [root@yinzhengjie ~]# vgdisplay 14 --- Volume group --- 15 VG Name yinzhengjie_vgs 16 System ID 17 Format lvm2 18 Metadata Areas 2 19 Metadata Sequence No 1 20 VG Access read/write 21 VG Status resizable 22 MAX LV 0 23 Cur LV 0 24 Open LV 0 25 Max PV 0 26 Cur PV 2 27 Act PV 2 28 VG Size 10.02 GiB 29 PE Size 4.00 MiB 30 Total PE 2564 31 Alloc PE / Size 0 / 0 32 Free PE / Size 2564 / 10.02 GiB 33 VG UUID 7IVn6j-raKQ-JAUp-rmLp-tWf8-vsE8-B76Uiq 34 35 [root@yinzhengjie ~]# vgdisplay yinzhengjie_vgs #只看名称为“yinzhengjie_vgs”的卷组 36 --- Volume group --- 37 VG Name yinzhengjie_vgs 38 System ID 39 Format lvm2 40 Metadata Areas 2 41 Metadata Sequence No 1 42 VG Access read/write 43 VG Status resizable 44 MAX LV 0 45 Cur LV 0 46 Open LV 0 47 Max PV 0 48 Cur PV 2 49 Act PV 2 50 VG Size 10.02 GiB 51 PE Size 4.00 MiB #默认PE大小就是4M,这个参数是可以修改的,当然这个参数是在创建卷组的时候指定的,创建之后就无法修改,除非删除后重新创建。 52 Total PE 2564 53 Alloc PE / Size 0 / 0 54 Free PE / Size 2564 / 10.02 GiB 55 VG UUID 7IVn6j-raKQ-JAUp-rmLp-tWf8-vsE8-B76Uiq 56 57 [root@yinzhengjie ~]# pvdisplay /dev/sdb1 #当我们将物理磁盘创建卷组的时候,再去查看物理卷信息的是就多出来一些参数了。 58 --- Physical volume --- 59 PV Name /dev/sdb1 60 VG Name yinzhengjie_vgs 61 PV Size 3.01 GiB / not usable 2.75 MiB 62 Allocatable yes 63 PE Size 4.00 MiB 64 Total PE 770 65 Free PE 770 66 Allocated PE 0 67 PV UUID A25Lv7-ZOKU-dtqm-eZDG-rFt0-up22-ofm8Oc 68 69 [root@yinzhengjie ~]# vgremove yinzhengjie_vgs #删除卷组,切记,我这里是因为磁盘没有数据,直接就vgremove啦,如果有数据应该用vgmove命令将数据拷贝到其他磁盘上去,在去移除设备哟! 70 Volume group "yinzhengjie_vgs" successfully removed 71 [root@yinzhengjie ~]# vgcreate -s 8MB yinzhengjie_data /dev/sdb{1,2} #指定PE的大小就是用-s参数,如果不指定就是4M,创建完毕后将 无法修改 72 Volume group "yinzhengjie_data" successfully created 73 [root@yinzhengjie ~]# pvdisplay /dev/sdb1 #查看该设备的PE分区。 74 --- Physical volume --- 75 PV Name /dev/sdb1 76 VG Name yinzhengjie_data 77 PV Size 3.01 GiB / not usable 2.75 MiB 78 Allocatable yes 79 PE Size 8.00 MiB #过真,变为8M的大小了 80 Total PE 385 81 Free PE 385 82 Allocated PE 0 83 PV UUID A25Lv7-ZOKU-dtqm-eZDG-rFt0-up22-ofm8Oc 84 85 [root@yinzhengjie ~]# 86 [root@yinzhengjie ~]# vgdisplay yinzhengjie_data #查看卷组的大小 87 --- Volume group --- 88 VG Name yinzhengjie_data 89 System ID 90 Format lvm2 91 Metadata Areas 2 92 Metadata Sequence No 1 93 VG Access read/write 94 VG Status resizable 95 MAX LV 0 96 Cur LV 0 97 Open LV 0 98 Max PV 0 99 Cur PV 2 100 Act PV 2 101 VG Size 10.02 GiB 102 PE Size 8.00 MiB 103 Total PE 1282 104 Alloc PE / Size 0 / 0 105 Free PE / Size 1282 / 10.02 GiB 106 VG UUID rdaCR9-1Hah-K2ON-nm1V-6W0C-mjRL-3skazJ 107 108 [root@yinzhengjie ~]# 109 [root@yinzhengjie ~]# vgrename yinzhengjie_data yinzhengjie_vgs #修改卷组名 110 Volume group "yinzhengjie_data" successfully renamed to "yinzhengjie_vgs" 111 [root@yinzhengjie ~]# 112 [root@yinzhengjie ~]# vgdisplay yinzhengjie_vgs #查看修改后的卷组名参数和物理卷参数是一致的。 113 --- Volume group --- 114 VG Name yinzhengjie_vgs 115 System ID 116 Format lvm2 117 Metadata Areas 2 118 Metadata Sequence No 2 119 VG Access read/write 120 VG Status resizable 121 MAX LV 0 122 Cur LV 0 123 Open LV 0 124 Max PV 0 125 Cur PV 2 126 Act PV 2 127 VG Size 10.02 GiB 128 PE Size 8.00 MiB 129 Total PE 1282 130 Alloc PE / Size 0 / 0 131 Free PE / Size 1282 / 10.02 GiB 132 VG UUID rdaCR9-1Hah-K2ON-nm1V-6W0C-mjRL-3skazJ 133 134 [root@yinzhengjie ~]# 135 '''
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 [root@yinzhengjie ~]# fdisk /dev/sdb #由于我想扩展卷组,所以需要一块新的物理卷,这个物理卷不一定是要来自同一块磁盘,你可以在其他磁盘上添加也是可以的。 9 10 WARNING: DOS-compatible mode is deprecated. It's strongly recommended to 11 switch off the mode (command 'c') and change display units to 12 sectors (command 'u'). 13 14 Command (m for help): n 15 Command action 16 e extended 17 p primary partition (1-4) 18 p 19 Partition number (1-4): 3 20 First cylinder (1309-2610, default 1309): 21 Using default value 1309 22 Last cylinder, +cylinders or +size{K,M,G} (1309-2610, default 2610): +5G 23 24 Command (m for help): P 25 26 Disk /dev/sdb: 21.5 GB, 21474836480 bytes 27 255 heads, 63 sectors/track, 2610 cylinders 28 Units = cylinders of 16065 * 512 = 8225280 bytes 29 Sector size (logical/physical): 512 bytes / 512 bytes 30 I/O size (minimum/optimal): 512 bytes / 512 bytes 31 Disk identifier: 0x7ecc698f 32 33 Device Boot Start End Blocks Id System 34 /dev/sdb1 1 393 3156741 8e Linux LVM 35 /dev/sdb2 394 1308 7349737+ 8e Linux LVM 36 /dev/sdb3 1309 1962 5253255 83 Linux 37 38 Command (m for help): T 39 Partition number (1-4): 3 40 Hex code (type L to list codes): 8e 41 Changed system type of partition 3 to 8e (Linux LVM) 42 43 Command (m for help): p #注意ID的信息是否是LVM类型 44 45 Disk /dev/sdb: 21.5 GB, 21474836480 bytes 46 255 heads, 63 sectors/track, 2610 cylinders 47 Units = cylinders of 16065 * 512 = 8225280 bytes 48 Sector size (logical/physical): 512 bytes / 512 bytes 49 I/O size (minimum/optimal): 512 bytes / 512 bytes 50 Disk identifier: 0x7ecc698f 51 52 Device Boot Start End Blocks Id System 53 /dev/sdb1 1 393 3156741 8e Linux LVM 54 /dev/sdb2 394 1308 7349737+ 8e Linux LVM 55 /dev/sdb3 1309 1962 5253255 8e Linux LVM 56 57 Command (m for help): w 58 The partition table has been altered! 59 60 Calling ioctl() to re-read partition table. 61 Syncing disks. 62 [root@yinzhengjie ~]# cat /proc/partitions #记得看下分区信息 63 major minor #blocks name 64 65 8 16 20971520 sdb 66 8 17 3156741 sdb1 67 8 18 7349737 sdb2 68 8 19 5253255 sdb3 69 8 0 20971520 sda 70 8 1 307200 sda1 71 8 2 18631680 sda2 72 8 3 2031616 sda3 73 [root@yinzhengjie ~]# 74 [root@yinzhengjie ~]# 75 [root@yinzhengjie ~]# pvs #查看物理磁盘 76 PV VG Fmt Attr PSize PFree 77 /dev/sdb1 yinzhengjie_vgs lvm2 a-- 3.01g 3.01g 78 /dev/sdb2 yinzhengjie_vgs lvm2 a-- 7.01g 7.01g 79 [root@yinzhengjie ~]# pvcreate /dev/sdb3 #创建成物理卷 80 Physical volume "/dev/sdb3" successfully created 81 [root@yinzhengjie ~]# 82 [root@yinzhengjie ~]# pvs #再次查看物理卷 83 PV VG Fmt Attr PSize PFree 84 /dev/sdb1 yinzhengjie_vgs lvm2 a-- 3.01g 3.01g 85 /dev/sdb2 yinzhengjie_vgs lvm2 a-- 7.01g 7.01g 86 /dev/sdb3 lvm2 --- 5.01g 5.01g 87 [root@yinzhengjie ~]# 88 [root@yinzhengjie ~]# vgs #查看卷组信息,其大小是10G,卷组名称叫做:yinzhengjie_vgs 89 VG #PV #LV #SN Attr VSize VFree 90 yinzhengjie_vgs 2 0 0 wz--n- 10.02g 10.02g 91 [root@yinzhengjie ~]# 92 [root@yinzhengjie ~]# vgextend yinzhengjie_vgs /dev/sdb3 #为"yinzhengjie_vgs"这个卷扩展卷组大小,指定设备为/dev/sdb3 93 Volume group "yinzhengjie_vgs" successfully extended 94 [root@yinzhengjie ~]# 95 [root@yinzhengjie ~]# vgdisplay yinzhengjie_vgs #显示"yinzhengjie_vgs"卷组信息。 96 --- Volume group --- 97 VG Name yinzhengjie_vgs 98 System ID 99 Format lvm2 100 Metadata Areas 3 101 Metadata Sequence No 3 102 VG Access read/write 103 VG Status resizable 104 MAX LV 0 105 Cur LV 0 106 Open LV 0 107 Max PV 0 108 Cur PV 3 109 Act PV 3 110 VG Size 15.02 GiB #果真由之前的10扩增到了15G 111 PE Size 8.00 MiB 112 Total PE 1923 113 Alloc PE / Size 0 / 0 114 Free PE / Size 1923 / 15.02 GiB 115 VG UUID rdaCR9-1Hah-K2ON-nm1V-6W0C-mjRL-3skazJ 116 117 [root@yinzhengjie ~]# vgs #也可以查看简要信息。 118 VG #PV #LV #SN Attr VSize VFree 119 yinzhengjie_vgs 3 0 0 wz--n- 15.02g 15.02g 120 [root@yinzhengjie ~]# 121 122 123 '''
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 [root@yinzhengjie ~]# vgdisplay yinzhengjie_vgs #查看“yinzhengjie_vgs”卷组信息 9 --- Volume group --- 10 VG Name yinzhengjie_vgs 11 System ID 12 Format lvm2 13 Metadata Areas 3 14 Metadata Sequence No 3 15 VG Access read/write 16 VG Status resizable 17 MAX LV 0 18 Cur LV 0 19 Open LV 0 20 Max PV 0 21 Cur PV 3 22 Act PV 3 23 VG Size 15.02 GiB #当前物理卷组信息为15G 24 PE Size 8.00 MiB 25 Total PE 1923 26 Alloc PE / Size 0 / 0 27 Free PE / Size 1923 / 15.02 GiB 28 VG UUID rdaCR9-1Hah-K2ON-nm1V-6W0C-mjRL-3skazJ 29 30 [root@yinzhengjie ~]# 31 [root@yinzhengjie ~]# pvmove /dev/sdb1 #将该分区的数据迁移走,由于我没有挂载存入东西,所以没有数据可以迁移。下面的提示可以忽略 32 No data to move for yinzhengjie_vgs 33 [root@yinzhengjie ~]# 34 [root@yinzhengjie ~]# vgreduce yinzhengjie_vgs /dev/sdb1 #缩减"yinzhengjie_vgs"卷组中的/dev/sdb1设备 35 Removed "/dev/sdb1" from volume group "yinzhengjie_vgs" 36 [root@yinzhengjie ~]# vgdisplay yinzhengjie_vgs #查看物理卷组信息。 37 --- Volume group --- 38 VG Name yinzhengjie_vgs 39 System ID 40 Format lvm2 41 Metadata Areas 2 42 Metadata Sequence No 4 43 VG Access read/write 44 VG Status resizable 45 MAX LV 0 46 Cur LV 0 47 Open LV 0 48 Max PV 0 49 Cur PV 2 50 Act PV 2 51 VG Size 12.02 GiB #Duang~发现整理的物理卷组信息变化了,缩减了3个G的大小。 52 PE Size 8.00 MiB 53 Total PE 1538 54 Alloc PE / Size 0 / 0 55 Free PE / Size 1538 / 12.02 GiB 56 VG UUID rdaCR9-1Hah-K2ON-nm1V-6W0C-mjRL-3skazJ 57 58 [root@yinzhengjie ~]# 59 [root@yinzhengjie ~]# pvs #删除完卷组信息,就可以移除PV了,我们既然没有用该卷组,就随时可以将其卸载掉! 60 PV VG Fmt Attr PSize PFree 61 /dev/sdb1 lvm2 --- 3.01g 3.01g 62 /dev/sdb2 yinzhengjie_vgs lvm2 a-- 7.01g 7.01g 63 /dev/sdb3 yinzhengjie_vgs lvm2 a-- 5.01g 5.01g 64 [root@yinzhengjie ~]# 65 [root@yinzhengjie ~]# pvremove /dev/sdb1 #移除物理卷组 66 Labels on physical volume "/dev/sdb1" successfully wiped 67 [root@yinzhengjie ~]# 68 [root@yinzhengjie ~]# pvs #查看信息,发现/dev/sdb1设备的确是不见了。 69 PV VG Fmt Attr PSize PFree 70 /dev/sdb2 yinzhengjie_vgs lvm2 a-- 7.01g 7.01g 71 /dev/sdb3 yinzhengjie_vgs lvm2 a-- 5.01g 5.01g 72 [root@yinzhengjie ~]# 73 '''
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 [root@yinzhengjie ~]# vgs #查看当前卷组信息 9 VG #PV #LV #SN Attr VSize VFree 10 yinzhengjie_vgs 2 1 0 wz--n- 12.02g 9.02g 11 [root@yinzhengjie ~]# 12 [root@yinzhengjie ~]# lvcreate -L 3G -n yinzhengjie_lv1 yinzhengjie_vgs #从“yinzhengjie_vgs”卷组创建一个名字叫做“yinzhengjie_lv1”的逻辑卷。 13 Logical volume "yinzhengjie_lv1" created 14 [root@yinzhengjie ~]# 15 [root@yinzhengjie ~]# lvs #查看逻辑卷信息 16 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert 17 yinzhengjie_lv1 yinzhengjie_vgs -wi-a----- 3.00g 18 [root@yinzhengjie ~]# 19 [root@yinzhengjie ~]# lvdisplay #这个可以查看逻辑卷的详细信息 20 --- Logical volume --- 21 LV Path /dev/yinzhengjie_vgs/yinzhengjie_lv1 #这是该设备的存放路径,注意,逻辑卷必须通过设备文件来访问。其家目录就是其卷组目录(“/dev/yinzhengjie_vgs/”)所对应的设备文件“yinzhengjie_lv1” 22 LV Name yinzhengjie_lv1 23 VG Name yinzhengjie_vgs 24 LV UUID R53uuH-ALj3-bdkf-tG6Y-Wbb5-Y1My-MMqR3B 25 LV Write Access read/write 26 LV Creation host, time yinzhengjie, 2017-05-17 23:10:05 +0800 27 LV Status available 28 # open 0 29 LV Size 3.00 GiB 30 Current LE 384 31 Segments 1 32 Allocation inherit 33 Read ahead sectors auto 34 - currently set to 256 35 Block device 253:0 36 37 [root@yinzhengjie ~]# lvdisplay yinzhengjie_lv1 #我们直接查看逻辑卷名称,发现是没有的,会出现以下报错。 38 Volume group "yinzhengjie_lv1" not found 39 Skipping volume group yinzhengjie_lv1 40 [root@yinzhengjie ~]# 41 [root@yinzhengjie ~]# ls -l /dev/yinzhengjie_vgs/ #发现卷组目录下对应着一个连接文件,真正的设备应该是“../dm-0” 42 total 0 43 lrwxrwxrwx. 1 root root 7 May 17 23:10 yinzhengjie_lv1 -> ../dm-0 44 [root@yinzhengjie ~]# 45 [root@yinzhengjie ~]# ls -l /dev/mapper/yinzhengjie_vgs-yinzhengjie_lv1 #其实我们也可以这样看到相关信息 46 lrwxrwxrwx. 1 root root 7 May 17 23:10 /dev/mapper/yinzhengjie_vgs-yinzhengjie_lv1 -> ../dm-0 47 [root@yinzhengjie ~]# 48 [root@yinzhengjie ~]# lvdisplay /dev/yinzhengjie_vgs/yinzhengjie_lv1 #所以查看逻辑卷的时候需要敲击其绝对路径。 49 --- Logical volume --- 50 LV Path /dev/yinzhengjie_vgs/yinzhengjie_lv1 51 LV Name yinzhengjie_lv1 52 VG Name yinzhengjie_vgs 53 LV UUID R53uuH-ALj3-bdkf-tG6Y-Wbb5-Y1My-MMqR3B 54 LV Write Access read/write 55 LV Creation host, time yinzhengjie, 2017-05-17 23:10:05 +0800 56 LV Status available 57 # open 0 58 LV Size 3.00 GiB 59 Current LE 384 60 Segments 1 61 Allocation inherit 62 Read ahead sectors auto 63 - currently set to 256 64 Block device 253:0 65 66 [root@yinzhengjie ~]# 67 68 '''
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 [root@yinzhengjie ~]# 9 [root@yinzhengjie ~]# mke2fs -t ext4 -b 2048 /dev/yinzhengjie_vgs/yinzhengjie_lv1 #格式化逻辑卷,可以指定块大小为2048 10 mke2fs 1.41.12 (17-May-2010) 11 Filesystem label= 12 OS type: Linux 13 Block size=2048 (log=1) 14 Fragment size=2048 (log=1) 15 Stride=0 blocks, Stripe width=0 blocks 16 196608 inodes, 1572864 blocks 17 78643 blocks (5.00%) reserved for the super user 18 First data block=0 19 Maximum filesystem blocks=538968064 20 96 block groups 21 16384 blocks per group, 16384 fragments per group 22 2048 inodes per group 23 Superblock backups stored on blocks: 24 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104 25 26 Writing inode tables: done 27 Creating journal (32768 blocks): done 28 Writing superblocks and filesystem accounting information: done 29 30 This filesystem will be automatically checked every 28 mounts or 31 180 days, whichever comes first. Use tune2fs -c or -i to override. 32 [root@yinzhengjie ~]# 33 [root@yinzhengjie ~]# mkdir /yinzhengjie/lvm #创建一个挂载目录 34 [root@yinzhengjie ~]# mount /dev/yinzhengjie_vgs/yinzhengjie_lv1 /yinzhengjie/lvm/ #将文件挂载到创建目录上去 35 [root@yinzhengjie ~]# ll /yinzhengjie/lvm #出现"lost+found"说明是挂载成功了。 36 total 16 37 drwx------. 2 root root 16384 May 18 00:03 lost+found 38 [root@yinzhengjie ~]# cp -r /etc/[a-z]* /yinzhengjie/lvm/ #拷贝文件到该目录上去 39 [root@yinzhengjie ~]# 40 [root@yinzhengjie ~]# ll /yinzhengjie/lvm #查看该目录下的文件。 41 total 1498 42 drwxr-xr-x. 3 root root 2048 May 18 00:05 abrt 43 drwxr-xr-x. 4 root root 2048 May 18 00:05 acpi 44 -rw-r--r--. 1 root root 44 May 18 00:05 adjtime 45 -rw-r--r--. 1 root root 1512 May 18 00:05 aliases 46 -rw-r--r--. 1 root root 12288 May 18 00:05 aliases.db 47 drwxr-xr-x. 2 root root 2048 May 18 00:05 alsa 48 drwxr-xr-x. 2 root root 6144 May 18 00:05 alternatives 49 -rw-------. 1 root root 541 May 18 00:05 anacrontab 50 -rw-r--r--. 1 root root 148 May 18 00:05 asound.conf 51 -rw-r--r--. 1 root root 1 May 18 00:05 at.deny 52 drwxr-x---. 3 root root 2048 May 18 00:05 audisp 53 drwxr-x---. 3 root root 2048 May 18 00:05 audit 54 drwxr-xr-x. 2 root root 2048 May 18 00:05 avahi 55 drwxr-xr-x. 2 root root 2048 May 18 00:05 bash_completion.d 56 -rw-r--r--. 1 root root 2681 May 18 00:05 bashrc 57 drwxr-xr-x. 2 root root 2048 May 18 00:05 blkid 58 drwxr-xr-x. 2 root root 2048 May 18 00:05 bluetooth 59 drwxr-xr-x. 2 root root 2048 May 18 00:05 bonobo-activation 60 -rw-r--r--. 1 root root 27 May 18 00:05 centos-release 61 drwxr-xr-x. 2 root root 2048 May 18 00:05 chkconfig.d 62 drwxr-xr-x. 5 root root 2048 May 18 00:05 ConsoleKit 63 drwxr-xr-x. 2 root root 2048 May 18 00:05 cron.d 64 drwxr-xr-x. 2 root root 2048 May 18 00:05 cron.daily 65 -rw-------. 1 root root 0 May 18 00:05 cron.deny 66 drwxr-xr-x. 2 root root 2048 May 18 00:05 cron.hourly 67 drwxr-xr-x. 2 root root 2048 May 18 00:05 cron.monthly 68 -rw-r--r--. 1 root root 457 May 18 00:05 crontab 69 drwxr-xr-x. 2 root root 2048 May 18 00:05 cron.weekly 70 -rw-r--r--. 1 root root 0 May 18 00:05 crypttab 71 -rw-r--r--. 1 root root 1602 May 18 00:05 csh.cshrc 72 -rw-r--r--. 1 root root 794 May 18 00:05 csh.login 73 drwxr-xr-x. 5 root root 2048 May 18 00:05 cups 74 drwxr-xr-x. 4 root root 2048 May 18 00:05 dbus-1 75 drwxr-xr-x. 2 root root 2048 May 18 00:05 default 76 drwxr-xr-x. 2 root root 2048 May 18 00:05 depmod.d 77 drwxr-x---. 3 root root 2048 May 18 00:05 dhcp 78 -rw-r--r--. 1 root root 4439 May 18 00:05 DIR_COLORS 79 -rw-r--r--. 1 root root 5139 May 18 00:05 DIR_COLORS.256color 80 -rw-r--r--. 1 root root 4113 May 18 00:05 DIR_COLORS.lightbgcolor 81 -rw-r--r--. 1 root root 21214 May 18 00:05 dnsmasq.conf 82 drwxr-xr-x. 2 root root 2048 May 18 00:05 dnsmasq.d 83 -rw-r--r--. 1 root root 519 May 18 00:05 dracut.conf 84 drwxr-xr-x. 2 root root 2048 May 18 00:05 dracut.conf.d 85 -rw-r--r--. 1 root root 3095 May 18 00:05 drirc 86 -rw-r--r--. 1 root root 4843 May 18 00:05 enscript.cfg 87 -rw-r--r--. 1 root root 0 May 18 00:05 environment 88 -rw-r--r--. 1 root root 28 May 18 00:05 ethers 89 drwxr-xr-x. 2 root root 2048 May 18 00:05 event.d 90 -rw-r--r--. 1 root root 0 May 18 00:05 exports 91 lrwxrwxrwx. 1 root root 56 May 18 00:05 favicon.png -> /usr/share/icons/hicolor/16x16/apps/system-logo-icon.png 92 drwxr-xr-x. 2 root root 2048 May 18 00:05 festival 93 -rw-r--r--. 1 root root 64 May 18 00:05 filesystems 94 drwxr-xr-x. 4 root root 2048 May 18 00:05 fonts 95 drwxr-xr-x. 2 root root 2048 May 18 00:05 foomatic 96 -rw-r--r--. 1 root root 20 May 18 00:05 fprintd.conf 97 -rw-r--r--. 1 root root 805 May 18 00:05 fstab 98 -rw-r--r--. 1 root root 0 May 18 00:05 gai.conf 99 drwxr-xr-x. 7 root root 2048 May 18 00:05 gconf 100 drwxr-xr-x. 2 root root 2048 May 18 00:05 gcrypt 101 drwxr-xr-x. 6 root root 2048 May 18 00:05 gdm 102 drwxr-xr-x. 3 root root 2048 May 18 00:05 ghostscript 103 drwxr-xr-x. 3 root root 2048 May 18 00:05 gnome-vfs-2.0 104 drwxr-xr-x. 2 root root 2048 May 18 00:05 gnupg 105 -rw-r--r--. 1 root root 767 May 18 00:05 group 106 -rw-------. 1 root root 748 May 18 00:05 group- 107 lrwxrwxrwx. 1 root root 22 May 18 00:05 grub.conf -> ../boot/grub/grub.conf 108 ----------. 1 root root 630 May 18 00:05 gshadow 109 -rw-------. 1 root root 614 May 18 00:05 gshadow- 110 drwxr-xr-x. 2 root root 2048 May 18 00:05 gtk-2.0 111 drwxr-xr-x. 3 root root 2048 May 18 00:05 hal 112 -rw-r--r--. 1 root root 9 May 18 00:05 host.conf 113 -rw-r--r--. 1 root root 158 May 18 00:05 hosts 114 -rw-r--r--. 1 root root 370 May 18 00:05 hosts.allow 115 -rw-r--r--. 1 root root 460 May 18 00:05 hosts.deny 116 drwxr-xr-x. 2 root root 2048 May 18 00:05 hp 117 drwxr-xr-x. 4 root root 2048 May 18 00:05 httpd 118 drwxr-xr-x. 2 root root 2048 May 18 00:05 init 119 lrwxrwxrwx. 1 root root 11 May 18 00:05 init.d -> rc.d/init.d 120 -rw-r--r--. 1 root root 884 May 18 00:05 inittab 121 -rw-r--r--. 1 root root 942 May 18 00:05 inputrc 122 drwxr-xr-x. 2 root root 2048 May 18 00:05 iproute2 123 -rw-r--r--. 1 root root 47 May 18 00:05 issue 124 -rw-r--r--. 1 root root 46 May 18 00:05 issue.net 125 drwxr-xr-x. 3 root root 2048 May 18 00:05 java 126 drwxr-xr-x. 2 root root 2048 May 18 00:05 jvm 127 drwxr-xr-x. 2 root root 2048 May 18 00:05 jvm-commmon 128 drwxr-xr-x. 4 root root 2048 May 18 00:05 kdump-adv-conf 129 -rw-r--r--. 1 root root 8195 May 18 00:05 kdump.conf 130 -rw-r--r--. 1 root root 449 May 18 00:05 krb5.conf 131 -rw-r--r--. 1 root root 51385 May 18 00:05 ld.so.cache 132 -rw-r--r--. 1 root root 28 May 18 00:05 ld.so.conf 133 drwxr-xr-x. 2 root root 2048 May 18 00:05 ld.so.conf.d 134 -rw-r-----. 1 root root 191 May 18 00:05 libaudit.conf 135 drwxr-xr-x. 5 root root 2048 May 18 00:05 libreport 136 -rw-r--r--. 1 root root 2290 May 18 00:05 libuser.conf 137 -rw-r--r--. 1 root root 2819 May 18 00:05 localtime 138 -rw-r--r--. 1 root root 1831 May 18 00:05 login.defs 139 -rw-r--r--. 1 root root 662 May 18 00:05 logrotate.conf 140 drwxr-xr-x. 2 root root 2048 May 18 00:05 logrotate.d 141 drwx------. 2 root root 16384 May 18 00:03 lost+found 142 drwxr-xr-x. 6 root root 2048 May 18 00:05 lvm 143 -rw-r--r--. 1 root root 111 May 18 00:05 magic 144 -rw-r--r--. 1 root root 272 May 18 00:05 mailcap 145 -rw-r--r--. 1 root root 1909 May 18 00:05 mail.rc 146 drwxr-xr-x. 2 root root 2048 May 18 00:05 makedev.d 147 -rw-r--r--. 1 root root 4940 May 18 00:05 man.config 148 drwxr-xr-x. 3 root root 2048 May 18 00:05 maven 149 -rw-r--r--. 1 root root 43591 May 18 00:05 mime.types 150 -rw-r--r--. 1 root root 827 May 18 00:05 mke2fs.conf 151 drwxr-xr-x. 2 root root 2048 May 18 00:05 modprobe.d 152 -rw-r--r--. 1 root root 0 May 18 00:05 motd 153 -rw-r--r--. 1 root root 517 May 18 00:05 mtab 154 -rw-r--r--. 1 root root 2620 May 18 00:05 mtools.conf 155 -rw-r--r--. 1 root root 251 May 18 00:05 my.cnf 156 -rw-r--r--. 1 root root 7846 May 18 00:05 nanorc 157 drwxr-xr-x. 5 root root 2048 May 18 00:05 NetworkManager 158 -rw-r--r--. 1 root root 58 May 18 00:05 networks 159 -rw-r--r--. 1 root root 1688 May 18 00:05 nsswitch.conf 160 drwxr-xr-x. 3 root root 2048 May 18 00:05 ntp 161 -rw-r--r--. 1 root root 1778 May 18 00:05 ntp.conf 162 drwxr-xr-x. 2 root root 2048 May 18 00:05 obex-data-server 163 drwxr-xr-x. 3 root root 2048 May 18 00:05 openldap 164 drwxr-xr-x. 2 root root 2048 May 18 00:05 opt 165 drwxr-xr-x. 2 root root 2048 May 18 00:05 PackageKit 166 drwxr-xr-x. 2 root root 2048 May 18 00:05 pam.d 167 drwxr-xr-x. 3 root root 2048 May 18 00:05 pango 168 -rw-r--r--. 1 root root 1448 May 18 00:05 passwd 169 -rw-r--r--. 1 root root 1437 May 18 00:05 passwd- 170 -rw-r--r--. 1 root root 1437 May 18 00:05 passwd.OLD 171 -rw-r--r--. 1 root root 1362 May 18 00:05 pbm2ppa.conf 172 drwxr-xr-x. 2 root root 2048 May 18 00:05 pcmcia 173 -rw-r--r--. 1 root root 2872 May 18 00:05 pinforc 174 drwxr-xr-x. 3 root root 2048 May 18 00:05 pkcs11 175 drwxr-xr-x. 10 root root 2048 May 18 00:05 pki 176 drwxr-xr-x. 2 root root 2048 May 18 00:05 plymouth 177 drwxr-xr-x. 5 root root 2048 May 18 00:05 pm 178 -rw-r--r--. 1 root root 370 May 18 00:05 pm-utils-hd-apm-restore.conf 179 -rw-r--r--. 1 root root 6300 May 18 00:05 pnm2ppa.conf 180 drwxr-xr-x. 5 root root 2048 May 18 00:05 polkit-1 181 drwxr-xr-x. 2 root root 2048 May 18 00:05 popt.d 182 drwxr-xr-x. 2 root root 2048 May 18 00:05 portreserve 183 drwxr-xr-x. 2 root root 2048 May 18 00:05 postfix 184 drwxr-xr-x. 3 root root 2048 May 18 00:05 ppp 185 -rw-r--r--. 1 root root 258828 May 18 00:05 prelink.cache 186 -rw-r--r--. 1 root root 789 May 18 00:05 prelink.conf 187 drwxr-xr-x. 2 root root 2048 May 18 00:05 prelink.conf.d 188 -rw-r--r--. 1 root root 233 May 18 00:05 printcap 189 -rw-r--r--. 1 root root 2110 May 18 00:05 profile 190 drwxr-xr-x. 2 root root 2048 May 18 00:05 profile.d 191 -rw-r--r--. 1 root root 6455 May 18 00:05 protocols 192 drwxr-xr-x. 2 root root 2048 May 18 00:05 pulse 193 -rw-r--r--. 1 root root 220 May 18 00:05 quotagrpadmins 194 -rw-r--r--. 1 root root 259 May 18 00:05 quotatab 195 lrwxrwxrwx. 1 root root 7 May 18 00:05 rc -> rc.d/rc 196 lrwxrwxrwx. 1 root root 10 May 18 00:05 rc0.d -> rc.d/rc0.d 197 lrwxrwxrwx. 1 root root 10 May 18 00:05 rc1.d -> rc.d/rc1.d 198 lrwxrwxrwx. 1 root root 10 May 18 00:05 rc2.d -> rc.d/rc2.d 199 lrwxrwxrwx. 1 root root 10 May 18 00:05 rc3.d -> rc.d/rc3.d 200 lrwxrwxrwx. 1 root root 10 May 18 00:05 rc4.d -> rc.d/rc4.d 201 lrwxrwxrwx. 1 root root 10 May 18 00:05 rc5.d -> rc.d/rc5.d 202 lrwxrwxrwx. 1 root root 10 May 18 00:05 rc6.d -> rc.d/rc6.d 203 drwxr-xr-x. 10 root root 2048 May 18 00:05 rc.d 204 lrwxrwxrwx. 1 root root 13 May 18 00:05 rc.local -> rc.d/rc.local 205 lrwxrwxrwx. 1 root root 15 May 18 00:05 rc.sysinit -> rc.d/rc.sysinit 206 -rw-r--r--. 1 root root 966 May 18 00:05 readahead.conf 207 lrwxrwxrwx. 1 root root 14 May 18 00:05 redhat-release -> centos-release 208 -rw-r--r--. 1 root root 82 May 18 00:05 resolv.conf 209 -rw-r--r--. 1 root root 1615 May 18 00:05 rpc 210 drwxr-xr-x. 2 root root 2048 May 18 00:05 rpm 211 -rw-r--r--. 1 root root 3167 May 18 00:05 rsyslog.conf 212 drwxr-xr-x. 2 root root 2048 May 18 00:05 rsyslog.d 213 -rw-r--r--. 1 root root 930 May 18 00:05 rwtab 214 drwxr-xr-x. 2 root root 2048 May 18 00:05 rwtab.d 215 drwxr-xr-x. 2 root root 2048 May 18 00:05 samba 216 drwxr-xr-x. 3 root root 2048 May 18 00:05 sane.d 217 drwxr-xr-x. 2 root root 2048 May 18 00:05 sasl2 218 drwxr-xr-x. 3 root root 2048 May 18 00:05 scl 219 -rw-------. 1 root root 122 May 18 00:05 securetty 220 drwxr-xr-x. 6 root root 2048 May 18 00:05 security 221 drwxr-xr-x. 3 root root 2048 May 18 00:05 selinux 222 -rw-r--r--. 1 root root 641020 May 18 00:06 services 223 -rw-r--r--. 1 root root 216 May 18 00:06 sestatus.conf 224 drwxr-xr-x. 2 root root 2048 May 18 00:06 setuptool.d 225 drwxr-xr-x. 3 root root 2048 May 18 00:06 sgml 226 ----------. 1 root root 828 May 18 00:06 shadow 227 ----------. 1 root root 796 May 18 00:06 shadow- 228 -rw-r--r--. 1 root root 61 May 18 00:06 shells 229 drwxr-xr-x. 4 root root 2048 May 18 00:06 skel 230 -rw-r--r--. 1 root root 6717 May 18 00:06 smartd.conf 231 drwxr-xr-x. 2 root root 2048 May 18 00:06 snmp 232 -rw-r--r--. 1 root root 260 May 18 00:06 sos.conf 233 drwxr-xr-x. 3 root root 2048 May 18 00:06 sound 234 drwxr-xr-x. 2 root root 2048 May 18 00:06 ssh 235 drwxr-xr-x. 2 root root 2048 May 18 00:06 ssl 236 -rw-r--r--. 1 root root 212 May 18 00:06 statetab 237 drwxr-xr-x. 2 root root 2048 May 18 00:06 statetab.d 238 -rw-r-----. 1 root root 1786 May 18 00:06 sudo.conf 239 -r--r-----. 1 root root 4002 May 18 00:06 sudoers 240 drwxr-x---. 2 root root 2048 May 18 00:06 sudoers.d 241 -rw-r-----. 1 root root 3181 May 18 00:06 sudo-ldap.conf 242 drwxr-xr-x. 7 root root 2048 May 18 00:06 sysconfig 243 -rw-r--r--. 1 root root 1174 May 18 00:06 sysctl.conf 244 -rw-r--r--. 1 root root 1150 May 18 00:06 sysctl.conf.bak 245 lrwxrwxrwx. 1 root root 14 May 18 00:06 system-release -> centos-release 246 -rw-r--r--. 1 root root 25 May 18 00:06 system-release-cpe 247 drwxr-xr-x. 2 root root 2048 May 18 00:06 terminfo 248 -rw-r--r--. 1 root root 1309 May 18 00:06 tpvmlp.conf 249 drwxr-xr-x. 4 root root 2048 May 18 00:06 udev 250 -rw-r--r--. 1 root root 480 May 18 00:06 updatedb.conf 251 -rw-r--r--. 1 root root 1962 May 18 00:06 vimrc 252 -rw-r--r--. 1 root root 1962 May 18 00:06 virc 253 drwxr-xr-x. 3 root root 2048 May 18 00:06 vmware-caf 254 drwxr-xr-x. 6 root root 2048 May 18 00:06 vmware-tools 255 -rw-r--r--. 1 root root 3008 May 18 00:06 warnquota.conf 256 -rw-r--r--. 1 root root 4479 May 18 00:06 wgetrc 257 drwxr-xr-x. 2 root root 2048 May 18 00:06 wpa_supplicant 258 drwxr-xr-x. 6 root root 2048 May 18 00:06 X11 259 drwxr-xr-x. 4 root root 2048 May 18 00:06 xdg 260 drwxr-xr-x. 2 root root 2048 May 18 00:06 xinetd.d 261 drwxr-xr-x. 2 root root 2048 May 18 00:06 xml 262 drwxr-xr-x. 5 root root 2048 May 18 00:06 yum 263 -rw-r--r--. 1 root root 969 May 18 00:06 yum.conf 264 drwxr-xr-x. 2 root root 2048 May 18 00:06 yum.repos.d 265 [root@yinzhengjie ~]# 266 '''
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 [root@yinzhengjie ~]# lvs #查看当前逻辑卷分区情况 9 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert 10 yinzhengjie_lv1 yinzhengjie_vgs -wi-ao---- 3.00g #目前该逻辑卷空间大小为3G 11 [root@yinzhengjie ~]# 12 [root@yinzhengjie ~]# vgs #在扩展之前要查看其卷组所对应的空闲空间是多少。 13 VG #PV #LV #SN Attr VSize VFree 14 yinzhengjie_vgs 2 1 0 wz--n- 12.02g 9.02g #目前还有9.02G剩余,也就是说,有9.02G是可以供你自己支配的 15 [root@yinzhengjie ~]# 16 [root@yinzhengjie ~]# lvextend -L 5G /dev/yinzhengjie_vgs/yinzhengjie_lv1 #将该逻辑卷扩展到5G,其实你也可以这样写“lvextend -L +2G /dev/yinzhengjie_vgs/yinzhengjie_lv1”效果是等同的, 17 Size of logical volume yinzhengjie_vgs/yinzhengjie_lv1 changed from 3.00 GiB (384 extents) to 5.00 GiB (640 extents). 18 Logical volume yinzhengjie_lv1 successfully resized 19 [root@yinzhengjie ~]# lvs 20 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert 21 yinzhengjie_lv1 yinzhengjie_vgs -wi-ao---- 5.00g #发现以及成功扩展2G空间,到5G的空间了 22 [root@yinzhengjie ~]# 23 [root@yinzhengjie ~]# lvextend -L +2G /dev/yinzhengjie_vgs/yinzhengjie_lv1 #将该逻辑卷再一次扩展2G空间,其等价于“lvextend -L 7G /dev/yinzhengjie_vgs/yinzhengjie_lv1 ” 24 Size of logical volume yinzhengjie_vgs/yinzhengjie_lv1 changed from 5.00 GiB (640 extents) to 7.00 GiB (896 extents). 25 Logical volume yinzhengjie_lv1 successfully resized 26 [root@yinzhengjie ~]# 27 [root@yinzhengjie ~]# lvs #再次查看信息 28 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert 29 yinzhengjie_lv1 yinzhengjie_vgs -wi-ao---- 7.00g #果真又扩展了2G的空间,变为了7G 30 [root@yinzhengjie ~]# 31 [root@yinzhengjie ~]# df -h #那么问题来了,这个正在使用的设备文件大小是否会跟着扩大呢? 32 Filesystem Size Used Avail Use% Mounted on 33 /dev/sda2 18G 2.7G 14G 17% / 34 tmpfs 1.9G 80K 1.9G 1% /dev/shm 35 /dev/sda1 283M 33M 236M 13% /boot 36 /dev/mapper/yinzhengjie_vgs-yinzhengjie_lv1 37 2.9G 47M 2.7G 2% /yinzhengjie/lvm #显然是没有!因为我们只是扩展了物理边界,没有扩展逻辑边界,如何处理呢? 38 [root@yinzhengjie ~]# 39 [root@yinzhengjie ~]# resize2fs /dev/yinzhengjie_vgs/yinzhengjie_lv1 #扩展到物理边界刚好的大小。 40 resize2fs 1.41.12 (17-May-2010) 41 Filesystem at /dev/yinzhengjie_vgs/yinzhengjie_lv1 is mounted on /yinzhengjie/lvm; on-line resizing required 42 old desc_blocks = 2, new_desc_blocks = 4 43 Performing an on-line resize of /dev/yinzhengjie_vgs/yinzhengjie_lv1 to 3670016 (2k) blocks. 44 The filesystem on /dev/yinzhengjie_vgs/yinzhengjie_lv1 is now 3670016 blocks long. 45 46 [root@yinzhengjie ~]# df -h #再次查看设备使用情况 47 Filesystem Size Used Avail Use% Mounted on 48 /dev/sda2 18G 2.7G 14G 17% / 49 tmpfs 1.9G 80K 1.9G 1% /dev/shm 50 /dev/sda1 283M 33M 236M 13% /boot 51 /dev/mapper/yinzhengjie_vgs-yinzhengjie_lv1 52 6.9G 48M 6.5G 1% /yinzhengjie/lvm #Duang~发现这个大小扩展到了6.9G的大小,说明你已经扩展 成功了,然后不会影响到生产使用。照样是可以进行存取。 53 [root@yinzhengjie ~]# 54 '''
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 [root@yinzhengjie ~]# df -h #那么问题来了,如何将设备的容量缩减呢? 9 Filesystem Size Used Avail Use% Mounted on 10 /dev/sda2 18G 2.7G 14G 17% / 11 tmpfs 1.9G 80K 1.9G 1% /dev/shm 12 /dev/sda1 283M 33M 236M 13% /boot 13 /dev/mapper/yinzhengjie_vgs-yinzhengjie_lv1 14 6.9G 48M 6.5G 1% /yinzhengjie/lvm #Duang~发现这个大小扩展到了6.9G的大小,说明你已经扩展 成功了,然后不会影响到生产使用。照样是可以进行存取。 15 [root@yinzhengjie ~]# 16 [root@yinzhengjie ~]# ls /yinzhengjie/lvm/ 17 abrt cron.deny ethers hal libaudit.conf NetworkManager polkit-1 rc.d shadow udev 18 acpi cron.hourly event.d host.conf libreport networks popt.d rc.local shadow- updatedb.conf 19 adjtime cron.monthly exports hosts libuser.conf nsswitch.conf portreserve rc.sysinit shells vimrc 20 aliases crontab favicon.png hosts.allow localtime ntp postfix readahead.conf skel virc 21 aliases.db cron.weekly festival hosts.deny login.defs ntp.conf ppp redhat-release smartd.conf vmware-caf 22 alsa crypttab filesystems hp logrotate.conf obex-data-server prelink.cache resolv.conf snmp vmware-tools 23 alternatives csh.cshrc fonts httpd logrotate.d openldap prelink.conf rpc sos.conf warnquota.conf 24 anacrontab csh.login foomatic init lost+found opt prelink.conf.d rpm sound wgetrc 25 asound.conf cups fprintd.conf init.d lvm PackageKit printcap rsyslog.conf ssh wpa_supplicant 26 at.deny dbus-1 fstab inittab magic pam.d profile rsyslog.d ssl X11 27 audisp default gai.conf inputrc mailcap pango profile.d rwtab statetab xdg 28 audit depmod.d gconf iproute2 mail.rc passwd protocols rwtab.d statetab.d xinetd.d 29 avahi dhcp gcrypt issue makedev.d passwd- pulse samba sudo.conf xml 30 bash_completion.d DIR_COLORS gdm issue.net man.config passwd.OLD quotagrpadmins sane.d sudoers yum 31 bashrc DIR_COLORS.256color ghostscript java maven pbm2ppa.conf quotatab sasl2 sudoers.d yum.conf 32 blkid DIR_COLORS.lightbgcolor gnome-vfs-2.0 jvm mime.types pcmcia rc scl sudo-ldap.conf yum.repos.d 33 bluetooth dnsmasq.conf gnupg jvm-commmon mke2fs.conf pinforc rc0.d securetty sysconfig 34 bonobo-activation dnsmasq.d group kdump-adv-conf modprobe.d pkcs11 rc1.d security sysctl.conf 35 centos-release dracut.conf group- kdump.conf motd pki rc2.d selinux sysctl.conf.bak 36 chkconfig.d dracut.conf.d grub.conf krb5.conf mtab plymouth rc3.d services system-release 37 ConsoleKit drirc gshadow ld.so.cache mtools.conf pm rc4.d sestatus.conf system-release-cpe 38 cron.d enscript.cfg gshadow- ld.so.conf my.cnf pm-utils-hd-apm-restore.conf rc5.d setuptool.d terminfo 39 cron.daily environment gtk-2.0 ld.so.conf.d nanorc pnm2ppa.conf rc6.d sgml tpvmlp.conf 40 [root@yinzhengjie ~]# umount /dev/yinzhengjie_vgs/yinzhengjie_lv1 #为了不要让数据不断的网磁盘写东西,需要先卸载卷。 41 [root@yinzhengjie ~]# ls /yinzhengjie/lvm/ 42 [root@yinzhengjie ~]# 43 [root@yinzhengjie ~]# e2fsck -f /dev/yinzhengjie_vgs/yinzhengjie_lv1 #并强行执行文件系统检测,确保文件修复是OK的,没有损坏的。 44 e2fsck 1.41.12 (17-May-2010) 45 Pass 1: Checking inodes, blocks, and sizes 46 Pass 2: Checking directory structure 47 Pass 3: Checking directory connectivity 48 Pass 4: Checking reference counts 49 Pass 5: Checking group summary information 50 /dev/yinzhengjie_vgs/yinzhengjie_lv1: 2318/458752 files (0.1% non-contiguous), 114910/3670016 blocks 51 [root@yinzhengjie ~]# 52 [root@yinzhengjie ~]# resize2fs /dev/yinzhengjie_vgs/yinzhengjie_lv1 2G #缩减逻辑边界到2G 53 resize2fs 1.41.12 (17-May-2010) 54 Resizing the filesystem on /dev/yinzhengjie_vgs/yinzhengjie_lv1 to 1048576 (2k) blocks. 55 The filesystem on /dev/yinzhengjie_vgs/yinzhengjie_lv1 is now 1048576 blocks long. 56 57 [root@yinzhengjie ~]# 58 [root@yinzhengjie ~]# lvs #查看当前逻辑卷信息 59 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert 60 yinzhengjie_lv1 yinzhengjie_vgs -wi-a----- 7.00g #我们只是缩减了逻辑边界,想要修改这个大小,想要修改这个物理边界还需要用lvreduce来实现。 61 [root@yinzhengjie ~]# 62 [root@yinzhengjie ~]# lvreduce -L 2G /dev/yinzhengjie_vgs/yinzhengjie_lv1 #缩减物理边界到2G 63 WARNING: Reducing active logical volume to 2.00 GiB 64 THIS MAY DESTROY YOUR DATA (filesystem etc.) 65 Do you really want to reduce yinzhengjie_lv1? [y/n]: y 66 Size of logical volume yinzhengjie_vgs/yinzhengjie_lv1 changed from 7.00 GiB (896 extents) to 2.00 GiB (256 extents). 67 Logical volume yinzhengjie_lv1 successfully resized 68 [root@yinzhengjie ~]# 69 [root@yinzhengjie ~]# lvs #查看当前逻辑卷信息 70 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert 71 yinzhengjie_lv1 yinzhengjie_vgs -wi-a----- 2.00g #果真从7G变成了2G的大小 72 73 [root@yinzhengjie ~]# mount /dev/yinzhengjie_vgs/yinzhengjie_lv1 /yinzhengjie/lvm/ #挂载一下 74 [root@yinzhengjie ~]# ls /yinzhengjie/lvm/ #测试文件是否还能被正常访问 75 abrt cron.deny ethers hal libaudit.conf NetworkManager polkit-1 rc.d shadow udev 76 acpi cron.hourly event.d host.conf libreport networks popt.d rc.local shadow- updatedb.conf 77 adjtime cron.monthly exports hosts libuser.conf nsswitch.conf portreserve rc.sysinit shells vimrc 78 aliases crontab favicon.png hosts.allow localtime ntp postfix readahead.conf skel virc 79 aliases.db cron.weekly festival hosts.deny login.defs ntp.conf ppp redhat-release smartd.conf vmware-caf 80 alsa crypttab filesystems hp logrotate.conf obex-data-server prelink.cache resolv.conf snmp vmware-tools 81 alternatives csh.cshrc fonts httpd logrotate.d openldap prelink.conf rpc sos.conf warnquota.conf 82 anacrontab csh.login foomatic init lost+found opt prelink.conf.d rpm sound wgetrc 83 asound.conf cups fprintd.conf init.d lvm PackageKit printcap rsyslog.conf ssh wpa_supplicant 84 at.deny dbus-1 fstab inittab magic pam.d profile rsyslog.d ssl X11 85 audisp default gai.conf inputrc mailcap pango profile.d rwtab statetab xdg 86 audit depmod.d gconf iproute2 mail.rc passwd protocols rwtab.d statetab.d xinetd.d 87 avahi dhcp gcrypt issue makedev.d passwd- pulse samba sudo.conf xml 88 bash_completion.d DIR_COLORS gdm issue.net man.config passwd.OLD quotagrpadmins sane.d sudoers yum 89 bashrc DIR_COLORS.256color ghostscript java maven pbm2ppa.conf quotatab sasl2 sudoers.d yum.conf 90 blkid DIR_COLORS.lightbgcolor gnome-vfs-2.0 jvm mime.types pcmcia rc scl sudo-ldap.conf yum.repos.d 91 bluetooth dnsmasq.conf gnupg jvm-commmon mke2fs.conf pinforc rc0.d securetty sysconfig 92 bonobo-activation dnsmasq.d group kdump-adv-conf modprobe.d pkcs11 rc1.d security sysctl.conf 93 centos-release dracut.conf group- kdump.conf motd pki rc2.d selinux sysctl.conf.bak 94 chkconfig.d dracut.conf.d grub.conf krb5.conf mtab plymouth rc3.d services system-release 95 ConsoleKit drirc gshadow ld.so.cache mtools.conf pm rc4.d sestatus.conf system-release-cpe 96 cron.d enscript.cfg gshadow- ld.so.conf my.cnf pm-utils-hd-apm-restore.conf rc5.d setuptool.d terminfo 97 cron.daily environment gtk-2.0 ld.so.conf.d nanorc pnm2ppa.conf rc6.d sgml tpvmlp.conf 98 [root@yinzhengjie ~]# 99 [root@yinzhengjie ~]# df -h #在查看挂载信息 100 Filesystem Size Used Avail Use% Mounted on 101 /dev/sda2 18G 2.8G 14G 17% / 102 tmpfs 1.9G 80K 1.9G 1% /dev/shm 103 /dev/sda1 283M 33M 236M 13% /boot 104 /dev/mapper/yinzhengjie_vgs-yinzhengjie_lv1 105 2.0G 46M 1.8G 3% /yinzhengjie/lvm #Duang~发现容量大小的确变为2G啦 106 [root@yinzhengjie ~]# 107 '''
在我们创建的正在使用的逻辑卷中,如果要从中拷贝数据,里面的数据很有可能是非一致性的(inconsistent),换句话说我们获得的数据的前后时间戳是不一致的,因此我们可以理解为其就是损坏的数据。如果没有内生的恢复机制,这些数据是无法使用的,那因此我们不能使用简单的copy命令从这些正在使用的逻辑卷中将数据复制出来,但是为了备份又不能把数据拷贝出来,怎么办呢?那快照就显得极为重要了。
所谓快照卷,它的主要功能是能够保存创建快照时原卷的状态,其实快照卷就是我们为真实的逻辑卷添加了一个访问路径。快照卷大小不要求非要跟原卷一样大(当然你要弄成一样大也不会报错,个人觉得是没有那个必要),虽然快照卷在刚刚创建的时候里面没有任何数据,但是你通过快照卷访问原卷的数据都是可以访问到的(因为快照是提供一个访问通路)。随着时间的推移,原卷的数据被修改,但是快照卷还依旧保留着之前的数据,这个时候访问原卷的数据和访问快照卷的数据是不一样的了,此时的快照卷还是保留着之前的状态,而原卷才是最新的数据。(因为一旦给原卷创建了快照卷的时候,当原卷需要修改数据的时候,会主动将需要修改的数据主动拷贝一份到快照卷上去,这样就对原卷修改之前的数据做了一个备份。但是要注意的是,一旦在原卷修改的数据大于了快照卷自身的大小,那么快照卷就会自动失效了。因此创建多大的快照得自己考虑清楚。)
我们创建快照的目的不是为了提供一个访问路径的,而是为了做备份,这才是我们真正的目的。快照的空间大小取决于原卷数据修改大小的变化幅度,因此快照卷设置空间大小时一定要大于原卷修改的数据大小哟。在备份完毕之后,最好将快照卷移除。快照卷是不允许修改数据的,其属性应该定义为只读模式。快照卷一般来说不会用来做数据修改,创建快照卷应该制定其模式为只读模式且快照卷和原卷应该是在同一个卷组内(因此在创建快照逻辑卷的时候也要注意其卷组是否有空闲空间)
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 [root@yinzhengjie ~]# mke2fs -t ext4 -b 2048 /dev/yinzhengjie_vgs/yinzhengjie_lv1 #格式化逻辑卷 9 mke2fs 1.41.12 (17-May-2010) 10 Filesystem label= 11 OS type: Linux 12 Block size=2048 (log=1) 13 Fragment size=2048 (log=1) 14 Stride=0 blocks, Stripe width=0 blocks 15 196608 inodes, 1572864 blocks 16 78643 blocks (5.00%) reserved for the super user 17 First data block=0 18 Maximum filesystem blocks=538968064 19 96 block groups 20 16384 blocks per group, 16384 fragments per group 21 2048 inodes per group 22 Superblock backups stored on blocks: 23 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104 24 25 Writing inode tables: done 26 Creating journal (32768 blocks): done 27 Writing superblocks and filesystem accounting information: done 28 29 This filesystem will be automatically checked every 29 mounts or 30 180 days, whichever comes first. Use tune2fs -c or -i to override. 31 [root@yinzhengjie ~]# 32 [root@yinzhengjie ~]# mkdir /yinzhengjie/lvm #创建挂载点 33 [root@yinzhengjie ~]# 34 [root@yinzhengjie ~]# mount /dev/yinzhengjie_vgs/yinzhengjie_lv1 /yinzhengjie/lvm/ #进行挂载 35 [root@yinzhengjie ~]# ls /yinzhengjie/lvm/ #验证是否已经挂载成功 36 lost+found 37 [root@yinzhengjie ~]# 38 [root@yinzhengjie ~]# cp /yinzhengjie/shell/* /yinzhengjie/lvm/ #拷贝一些数据进去。 39 [root@yinzhengjie ~]# ll /yinzhengjie/lvm/ 40 total 20 41 -rw-r--r--. 1 root root 120 May 17 09:07 double.sh 42 drwx------. 2 root root 16384 May 17 09:05 lost+found 43 -rw-r--r--. 1 root root 108 May 17 09:07 sum.sh 44 [root@yinzhengjie ~]# 45 '''
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 [root@yinzhengjie ~]# lvs #查看当前逻辑卷组信息 9 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert 10 yinzhengjie_lv1 yinzhengjie_vgs -wi-ao---- 3.00g 11 [root@yinzhengjie ~]# 12 [root@yinzhengjie ~]# lvcreate -s -L 100M -n yinzhengjie-snap -p r /dev/yinzhengjie_vgs/yinzhengjie_lv1 #假如数据变化量不会超过80M,我这个给100M就已经是绰绰有余了。这就是基于“dev/yinzhengjie_vgs/yinzhengjie_lv1”逻辑卷所创建一个名字叫“yinzhengjie-snap”的快照。 13 Logical volume "yinzhengjie-snap" created 14 [root@yinzhengjie ~]# 15 [root@yinzhengjie ~]# mkdir /yinzhengjie/snap #创建挂载点 16 [root@yinzhengjie ~]# mount /dev/yinzhengjie_vgs/yinzhengjie-snap /yinzhengjie/snap/ #将快照直接挂载,不需要格式化哟 17 mount: block device /dev/mapper/yinzhengjie_vgs-yinzhengjie--snap is write-protected, mounting read-only 18 [root@yinzhengjie ~]# ll /yinzhengjie/snap/ #查看快照卷挂载点的数据竟然和原卷“/dev/yinzhengjie_vgs/yinzhengjie_lv1”信息一致 19 total 20 20 -rw-r--r--. 1 root root 120 May 17 09:07 double.sh 21 drwx------. 2 root root 16384 May 17 09:05 lost+found 22 -rw-r--r--. 1 root root 108 May 17 09:07 sum.sh 23 [root@yinzhengjie ~]# ll /yinzhengjie/lvm/ #查看原卷信息 24 total 20 25 -rw-r--r--. 1 root root 120 May 17 09:07 double.sh 26 drwx------. 2 root root 16384 May 17 09:05 lost+found 27 -rw-r--r--. 1 root root 108 May 17 09:07 sum.sh 28 [root@yinzhengjie ~]# 29 [root@yinzhengjie ~]# 30 [root@yinzhengjie ~]# mv //yinzhengjie/lvm/sum.sh /yinzhengjie/ #修改原卷内容 31 [root@yinzhengjie ~]# ll /yinzhengjie/lvm/ #验证是否修改成功,发现sum.sh文件被移动了。 32 total 18 33 -rw-r--r--. 1 root root 120 May 17 09:07 double.sh 34 drwx------. 2 root root 16384 May 17 09:05 lost+found 35 [root@yinzhengjie ~]# 36 [root@yinzhengjie ~]# 37 [root@yinzhengjie ~]# ll /yinzhengjie/snap/ #发现快照的内容并没有修改 38 total 20 39 -rw-r--r--. 1 root root 120 May 17 09:07 double.sh 40 drwx------. 2 root root 16384 May 17 09:05 lost+found 41 -rw-r--r--. 1 root root 108 May 17 09:07 sum.sh #我在这呢,没有被移动 42 [root@yinzhengjie ~]# 43 [root@yinzhengjie ~]# tar -Jcf /yinzhengjie/lvs-snap.tar.xz /yinzhengjie/snap/* #用快照来备份一致性数据。 44 tar: Removing leading `/' from member names 45 [root@yinzhengjie ~]# 46 [root@yinzhengjie ~]# 47 [root@yinzhengjie ~]# umount /yinzhengjie/snap/ #已经备份完毕可以卸载掉挂载点 48 [root@yinzhengjie ~]# lvremove /dev/yinzhengjie_vgs/yinzhengjie-snap #既然备份完毕了,这个快照也就无用了,直接删除即可。 49 Do you really want to remove active logical volume yinzhengjie-snap? [y/n]: y 50 Logical volume "yinzhengjie-snap" successfully removed 51 [root@yinzhengjie ~]# 52 [root@yinzhengjie ~]# mkdir /yinzhengjie/backuo 53 [root@yinzhengjie ~]# tar -Jxf /yinzhengjie/lvs-snap.tar.xz -C /yinzhengjie/backuo/ #将该数据放在其他的服务器上备份,或者解压来看看里面的内容 54 [root@yinzhengjie ~]# ll /yinzhengjie/backuo/yinzhengjie/snap/ #这就是备份的数据。 55 total 12 56 -rw-r--r--. 1 root root 120 May 17 09:07 double.sh 57 drwx------. 2 root root 4096 May 17 09:05 lost+found 58 -rw-r--r--. 1 root root 108 May 17 09:07 sum.sh 59 [root@yinzhengjie ~]# 60 '''
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 #@author :yinzhengjie 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/ 5 #EMAIL:y1053419035@qq.com 6 7 ''' 8 总结: 9 根据上面的实验可以看到,LVM具有很好的可伸缩性,使用起来非常方便。可以方便地对卷组、逻辑卷的大小进行调整,更进一步 10 调整文件系统的大小。这个时候无论你在原卷逻辑卷上做什么变化都不用担心数据丢失了,从备份的快照文件里面可以恢复之前的文件, 11 这就是快照卷的强大之处了……通过使用lvm的快照我们可以轻松的备份数据,由于snapshot和源lvm的关系,snapshot只能够临时使用, 12 不能脱离源lvm而存在;因此做到数据的万无一失,我们可以在snapshot的基础上进行dd命令备份或其tar命令备份操作,这样既不会影 13 响原始数据也能够达到备份的需求。 14 '''
本文来自博客园,作者:尹正杰,转载请注明原文链接:https://www.cnblogs.com/yinzhengjie/p/6862933.html,个人微信: "JasonYin2020"(添加时请备注来源及意图备注,有偿付费)
当你的才华还撑不起你的野心的时候,你就应该静下心来学习。当你的能力还驾驭不了你的目标的时候,你就应该沉下心来历练。问问自己,想要怎样的人生。