邏輯卷的創建
1、查看分區和未使用的分區
1 [root@server0 test]# lsblk 2 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT 3 sda 8:0 0 40G 0 disk 4 ├─sda1 8:1 0 3.9G 0 part [SWAP] 5 └─sda2 8:2 0 36.1G 0 part / 6 sdb 8:16 0 20G 0 disk 7 ├─sdb1 8:17 0 3G 0 part /mnt/mypart 8 ├─sdb2 8:18 0 3G 0 part 9 │ └─datastore-database 253:1 0 50M 0 lvm /mnt/database 10 ├─sdb3 8:19 0 4G 0 part 11 ├─sdb4 8:20 0 1K 0 part 12 └─sdb5 8:21 0 5G 0 part 13 └─systemvg-vo 253:0 0 3G 0 lvm /vo 14 sr0 11:0 1 3.5G 0 rom
上述命令lsblk可以看出。只有sdb4分區是為被使用的。未掛載的。可以用於創建物理卷。
2、創建物理卷
創建物理卷
命令:pvcreate /dev/sdb6
1 [root@server0 test]# pvcreate /dev/sdb6 2 WARNING: ext4 signature detected on /dev/sdb6 at offset 1080. Wipe it? [y/n] y 3 Wiping ext4 signature on /dev/sdb6. 4 Physical volume "/dev/sdb6" successfully created 5 [root@server0 test]#
查看物理卷
命令:pvs或者pvdisplay
1 [root@server0 test]# pvs 2 PV VG Fmt Attr PSize PFree 3 /dev/sdb2 datastore lvm2 a-- 3.00g 2.95g 4 /dev/sdb3 datastore lvm2 a-- 4.00g 4.00g 5 /dev/sdb5 systemvg lvm2 a-- 5.00g 2.00g 6 /dev/sdb6 lvm2 a-- 3.00g 3.00g 7 [root@server0 test]# pvdisplay 8 --- Physical volume --- 9 PV Name /dev/sdb2 10 VG Name datastore 11 PV Size 3.00 GiB / not usable 4.00 MiB 12 Allocatable yes 13 PE Size 1.00 MiB 14 Total PE 3068 15 Free PE 3018 16 Allocated PE 50 17 PV UUID PdklER-NnmF-aVNj-BM6e-g4Lr-4fwD-3PnkfN 18 19 --- Physical volume --- 20 PV Name /dev/sdb3 21 VG Name datastore 22 PV Size 4.00 GiB / not usable 4.00 MiB 23 Allocatable yes 24 PE Size 1.00 MiB 25 Total PE 4092 26 Free PE 4092 27 Allocated PE 0 28 PV UUID GWB0qa-GOc1-GjoY-n2ms-P6XC-wo3a-wVhtnS 29 30 --- Physical volume --- 31 PV Name /dev/sdb5 32 VG Name systemvg 33 PV Size 5.00 GiB / not usable 4.00 MiB 34 Allocatable yes 35 PE Size 4.00 MiB 36 Total PE 1279 37 Free PE 511 38 Allocated PE 768 39 PV UUID 8h8YCG-bic8-f0lT-RAYx-MG0L-dr0b-WZu6Mj 40 41 "/dev/sdb6" is a new physical volume of "3.00 GiB" 42 --- NEW Physical volume --- 43 PV Name /dev/sdb6 44 VG Name 45 PV Size 3.00 GiB 46 Allocatable NO 47 PE Size 0 48 Total PE 0 49 Free PE 0 50 Allocated PE 0 51 PV UUID TUwqlG-v5mn-KYgR-Js6U-e8Vv-0oOP-kXBx0l 52 53 [root@server0 test]#
3、創建卷組
創建卷組
命令:vgcreate 卷組名 物理卷路徑
1 [root@server0 test]# vgcreate yck-vg /dev/sdb6 2 Volume group "yck-vg" successfully created 3 [root@server0 test]# 4 [root@server0 test]#
查看卷組
命令:vgs或者vgdisplay
1 [root@server0 test]# 2 [root@server0 test]# vgs 3 VG #PV #LV #SN Attr VSize VFree 4 datastore 2 1 0 wz--n- 6.99g 6.94g 5 systemvg 1 1 0 wz--n- 5.00g 2.00g 6 yck-vg 1 0 0 wz--n- 3.00g 3.00g 7 [root@server0 test]# 8 [root@server0 test]# vgdisplay 9 --- Volume group --- 10 VG Name datastore 11 System ID 12 Format lvm2 13 Metadata Areas 2 14 Metadata Sequence No 3 15 VG Access read/write 16 VG Status resizable 17 MAX LV 0 18 Cur LV 1 19 Open LV 1 20 Max PV 0 21 Cur PV 2 22 Act PV 2 23 VG Size 6.99 GiB 24 PE Size 1.00 MiB 25 Total PE 7160 26 Alloc PE / Size 50 / 50.00 MiB 27 Free PE / Size 7110 / 6.94 GiB 28 VG UUID AiuBQp-0adW-yxIA-tUK3-66vp-P1TR-fHlnhf 29 30 --- Volume group --- 31 VG Name systemvg 32 System ID 33 Format lvm2 34 Metadata Areas 1 35 Metadata Sequence No 2 36 VG Access read/write 37 VG Status resizable 38 MAX LV 0 39 Cur LV 1 40 Open LV 1 41 Max PV 0 42 Cur PV 1 43 Act PV 1 44 VG Size 5.00 GiB 45 PE Size 4.00 MiB 46 Total PE 1279 47 Alloc PE / Size 768 / 3.00 GiB 48 Free PE / Size 511 / 2.00 GiB 49 VG UUID pDh2Ip-vLM2-Q8A3-bpy2-CYBM-kq1c-ppZVhu 50 51 --- Volume group --- 52 VG Name yck-vg 53 System ID 54 Format lvm2 55 Metadata Areas 1 56 Metadata Sequence No 1 57 VG Access read/write 58 VG Status resizable 59 MAX LV 0 60 Cur LV 0 61 Open LV 0 62 Max PV 0 63 Cur PV 1 64 Act PV 1 65 VG Size 3.00 GiB 66 PE Size 4.00 MiB 67 Total PE 767 68 Alloc PE / Size 0 / 0 69 Free PE / Size 767 / 3.00 GiB 70 VG UUID 67nE5O-mWoH-qFKI-0FmI-wAxf-UxRA-eufi12 71 72 [root@server0 test]#
4、創建邏輯卷
創建邏輯卷
命令:lvcreate -n 邏輯卷名 -L 邏輯卷大小 /-l PE數量 卷組名
1 [root@server0 test]# 2 [root@server0 test]# lvcreate -n yck -L 2G yck-vg 3 Logical volume "yck" created 4 [root@server0 test]#
查看邏輯卷
命令:lvs或者lvdisplay
1 [root@server0 test]# lvs 2 LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert 3 database datastore -wi-ao---- 50.00m 4 vo systemvg -wi-ao---- 3.00g 5 yck yck-vg -wi-a----- 2.00g 6 [root@server0 test]#
1 [root@server0 test]# lvdisplay 2 --- Logical volume --- 3 LV Path /dev/datastore/database 4 LV Name database 5 VG Name datastore 6 LV UUID E0XokF-Vc3R-wzhC-8Bv0-6Svj-FifU-9UcbfA 7 LV Write Access read/write 8 LV Creation host, time server0.example.com, 2019-04-10 14:25:38 +0800 9 LV Status available 10 # open 1 11 LV Size 50.00 MiB 12 Current LE 50 13 Segments 1 14 Allocation inherit 15 Read ahead sectors auto 16 - currently set to 8192 17 Block device 253:1 18 19 --- Logical volume --- 20 LV Path /dev/systemvg/vo 21 LV Name vo 22 VG Name systemvg 23 LV UUID NEZs7g-hlWw-Qfel-EbkO-8Pq6-dTx3-QEREXx 24 LV Write Access read/write 25 LV Creation host, time server0.example.com, 2019-04-10 14:13:28 +0800 26 LV Status available 27 # open 1 28 LV Size 3.00 GiB 29 Current LE 768 30 Segments 1 31 Allocation inherit 32 Read ahead sectors auto 33 - currently set to 8192 34 Block device 253:0 35 36 --- Logical volume --- 37 LV Path /dev/yck-vg/yck 38 LV Name yck 39 VG Name yck-vg 40 LV UUID a5xWyy-xRwe-Jso3-UC3S-nHvX-ocze-ypmrmX 41 LV Write Access read/write 42 LV Creation host, time server0.example.com, 2019-04-10 17:06:31 +0800 43 LV Status available 44 # open 0 45 LV Size 2.00 GiB 46 Current LE 512 47 Segments 1 48 Allocation inherit 49 Read ahead sectors auto 50 - currently set to 8192 51 Block device 253:2 52 53 [root@server0 test]#
邏輯卷也需要格式化,創建文件系統,掛在后才能使用。
1 [root@server0 test]# mkfs.ext4 /dev/yck-vg/yck 2 mke2fs 1.42.9 (28-Dec-2013) 3 Filesystem label= 4 OS type: Linux 5 Block size=4096 (log=2) 6 Fragment size=4096 (log=2) 7 Stride=0 blocks, Stripe width=0 blocks 8 131072 inodes, 524288 blocks 9 26214 blocks (5.00%) reserved for the super user 10 First data block=0 11 Maximum filesystem blocks=536870912 12 16 block groups 13 32768 blocks per group, 32768 fragments per group 14 8192 inodes per group 15 Superblock backups stored on blocks: 16 32768, 98304, 163840, 229376, 294912 17 18 Allocating group tables: done 19 Writing inode tables: done 20 Creating journal (16384 blocks): done 21 Writing superblocks and filesystem accounting information: done