PE(physical extend) 物理扩展
PV(physcial volume) 物理卷
VG(volume group) 卷组
LV(logical volume) 逻辑卷
创建LVM
1 [root@zq ~]# fdisk -l #查看磁盘信息 共有三个磁盘sdb sdc sda 2 3 磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区 4 Units = 扇区 of 1 * 512 = 512 bytes 5 扇区大小(逻辑/物理):512 字节 / 512 字节 6 I/O 大小(最小/最佳):512 字节 / 512 字节 7 8 9 磁盘 /dev/sdc:10.7 GB, 10737418240 字节,20971520 个扇区 10 Units = 扇区 of 1 * 512 = 512 bytes 11 扇区大小(逻辑/物理):512 字节 / 512 字节 12 I/O 大小(最小/最佳):512 字节 / 512 字节 13 14 15 磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区 16 Units = 扇区 of 1 * 512 = 512 bytes 17 扇区大小(逻辑/物理):512 字节 / 512 字节 18 I/O 大小(最小/最佳):512 字节 / 512 字节 19 磁盘标签类型:dos 20 磁盘标识符:0x000c73ce 21 22 设备 Boot Start End Blocks Id System 23 /dev/sda1 * 2048 1026047 512000 83 Linux 24 /dev/sda2 1026048 5122047 2048000 82 Linux swap / Solaris 25 /dev/sda3 5122048 47065087 20971520 83 Linux 26 [root@zq ~]# pvcreate /dev/sdb /dev/sdc #将物理磁盘设备初始化为物理卷 27 Physical volume "/dev/sdb" successfully created 28 Physical volume "/dev/sdc" successfully created 29 [root@zq ~]# pvs #查看物理卷信息 30 PV VG Fmt Attr PSize PFree 31 /dev/sdb lvm2 --- 10.00g 10.00g 32 /dev/sdc lvm2 --- 10.00g 10.00g 33 [root@zq ~]# pvdisplay #查看物理卷详细信息 34 "/dev/sdc" is a new physical volume of "10.00 GiB" 35 --- NEW Physical volume --- 36 PV Name /dev/sdc 37 VG Name 38 PV Size 10.00 GiB 39 Allocatable NO 40 PE Size 0 41 Total PE 0 42 Free PE 0 43 Allocated PE 0 44 PV UUID KP4AoJ-LAHP-RQTx-QOeL-6VPy-14Ji-sGQI0Q 45 46 "/dev/sdb" is a new physical volume of "10.00 GiB" 47 --- NEW Physical volume --- 48 PV Name /dev/sdb 49 VG Name 50 PV Size 10.00 GiB 51 Allocatable NO 52 PE Size 0 53 Total PE 0 54 Free PE 0 55 Allocated PE 0 56 PV UUID ef6lqL-1rQZ-Zl3p-79RS-myKg-kS2f-Z2FkNZ 57 58 [root@zq ~]# vgcreate zq /dev/sdb /dev/sdc #创建卷组zq 并将pv加入卷组中 59 Volume group "zq" successfully created 60 [root@zq ~]# vgs #查看卷组信息 61 VG #PV #LV #SN Attr VSize VFree 62 zq 2 0 0 wz--n- 19.99g 19.99g 63 [root@zq ~]# vgdisplay #查看卷组详细信息 64 --- Volume group --- 65 VG Name zq 66 System ID 67 Format lvm2 68 Metadata Areas 2 69 Metadata Sequence No 1 70 VG Access read/write 71 VG Status resizable 72 MAX LV 0 73 Cur LV 0 74 Open LV 0 75 Max PV 0 76 Cur PV 2 77 Act PV 2 78 VG Size 19.99 GiB #总共大小 79 PE Size 4.00 MiB #以pe为单位 80 Total PE 5118 81 Alloc PE / Size 0 / 0 82 Free PE / Size 5118 / 19.99 GiB 83 VG UUID vtJbuL-XjMj-vlX5-9dZd-A9dW-P24Z-wTmpG3 84 85 [root@zq ~]# lvcreate -n mylv -L 2G zq #基于卷组创建逻辑卷 -n 逻辑卷名字mylv -L 指定逻辑卷大小为2g 来自zq卷组 86 Logical volume "mylv" created. 87 [root@zq ~]# lvs #查看卷组信息 88 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert 89 mylv zq -wi-a----- 2.00g #有一个名为mylv的逻辑卷,来自zq卷组,大小为2g 90 [root@zq ~]# lvdisplay #查看卷组详细信息 91 --- Logical volume --- 92 LV Path /dev/zq/mylv #逻辑卷的路径 93 LV Name mylv 94 VG Name zq 95 LV UUID 4MQIJs-hoTw-495Z-PVCN-NehI-LBZz-S93LEf 96 LV Write Access read/write 97 LV Creation host, time zq, 2017-05-15 23:26:41 +0800 98 LV Status available 99 # open 0 100 LV Size 2.00 GiB #逻辑卷的大小为2g 101 Current LE 512 102 Segments 1 103 Allocation inherit 104 Read ahead sectors auto 105 - currently set to 8192 106 Block device 253:0
[root@zq ~]# ls /dev/zq #在这个目录下可以查看到创建的lv mylv [root@zq ~]# ls /dev/zq/mylv /dev/zq/mylv [root@zq ~]# cd /dev/zq [root@zq zq]# ls mylv [root@zq zq]# lvcreate -n mylv1 -L 2G zq #可以再次创建 Logical volume "mylv1" created. [root@zq zq]# ls mylv mylv1 [root@zq zq]# ll 总用量 0 lrwxrwxrwx 1 root root 7 5月 15 23:26 mylv -> ../dm-0 lrwxrwxrwx 1 root root 7 5月 15 23:38 mylv1 -> ../dm-1
[root@zq zq]# mkfs.ext4 /dev/zq/mylv #为创建好的逻辑卷格式化创建文件系统 mke2fs 1.42.9 (28-Dec-2013) 文件系统标签= OS type: Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 131072 inodes, 524288 blocks 26214 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=536870912 16 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: 完成 正在写入inode表: 完成 Creating journal (16384 blocks): 完成 Writing superblocks and filesystem accounting information: 完成
[root@zq zq]# mount /dev/zq/mylv /mnt/ #将格式化好的逻辑卷挂载使用 [root@zq zq]# cd /mnt/ [root@zq mnt]# ls lost+found [root@zq mnt]# touch zq.net [root@zq mnt]# ls lost+found zq.net [root@zq mnt]# mount #这里可以看到挂载成功/dev/mapper/zq-mylv on /mnt type ext4 (rw,relatime,data=ordered) #发现路径跟我们上面的不一样/dev/mapper [root@zq mnt]# ll 总用量 16 drwx------ 2 root root 16384 5月 15 23:41 lost+found -rw-r--r-- 1 root root 0 5月 15 23:43 zq.net [root@zq mnt]# cd /dev/mapper/ #实际路径是这样的 [root@zq mapper]# ls control zq-mylv zq-mylv1
[root@zq mapper]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert mylv zq -wi-ao---- 2.00g mylv1 zq -wi-a----- 2.00g #这里有两个逻辑卷,只要空间够可以随意创建
删除LVM
[root@zq ~]# ls /mnt/ #查看挂载目录 lost+found zq.net [root@zq ~]# umount /mnt/ #卸载挂载目录 [root@zq ~]# ls /mnt/ #没有了发现zq.net addons images Packages RPM-GPG-KEY-redhat-release EFI isolinux release-notes TRANS.TBL EULA LiveOS repodata GPL media.repo RPM-GPG-KEY-redhat-beta [root@zq ~]# lvremove /dev/zq/mylv mylv1 #删除逻辑卷 Do you really want to remove active logical volume mylv? [y/n]: y Logical volume "mylv" successfully removed Volume group "mylv1" not found Cannot process volume group mylv1 [root@zq ~]# lvremove /dev/zq/mylv1 Do you really want to remove active logical volume mylv1? [y/n]: y Logical volume "mylv1" successfully removed [root@zq ~]# lvs [root@zq ~]# vgremove /dev/zq #删除卷组 Volume group "zq" successfully removed [root@zq ~]# vgs [root@zq ~]# ls /dev/zq ls: 无法访问/dev/zq: 没有那个文件或目录 [root@zq ~]# vgremove zq Volume group "zq" not found Cannot process volume group zq [root@zq ~]# pvremove /dev/sdc #删除物理卷 Labels on physical volume "/dev/sdc" successfully wiped [root@zq ~]# pvremove /dev/sdb Labels on physical volume "/dev/sdb" successfully wiped [root@zq ~]# pvs
注意:必须按顺序来