Пример настройки LVM.
###########################
# Architecture:
###########################
###########################
# Install LVM:
############################
$ yum install -y lvm2
# Add disk at VM level
# Re-scan scsi
$ ls -ltr /sys/class/scsi_host/host*/scan
{
echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scan
}
$ fdisk /dev/sdb
+++++
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xa36aca64
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): t
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/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xa36aca64
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20971519 10484736 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
+++++
############################
# Create PV:
############################
$ pvcreate /dev/sdb1
+++++
Physical volume "/dev/sdb1" successfully created.
+++++
$ pvscan
+++++
PV /dev/sdb1 lvm2 [<10.00 GiB]
Total: 1 [<10.00 GiB] / in use: 0 [0 ] / in no VG: 1 [<10.00 GiB]
+++++
############################
# Create VG:
############################
$ vgcreate vg01 /dev/sdb1
+++++
Volume group "vg01" successfully created
+++++
$ vgscan
+++++
Reading volume groups from cache.
Found volume group "vg01" using metadata type lvm2
+++++
$ vgdisplay vg01
+++++
--- Volume group ---
VG Name vg01
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size <10.00 GiB
PE Size 4.00 MiB
Total PE 2559
Alloc PE / Size 0 / 0
Free PE / Size 2559 / <10.00 GiB
VG UUID nXkbFj-ZFhX-tE4A-mpCp-MoDt-mwfB-amftVx
+++++
$ vgs
+++++
VG #PV #LV #SN Attr VSize VFree
vg01 1 0 0 wz--n- <10.00g <10.00g
+++++
############################
# Create LV's:
############################
$ lvcreate --size 1G --name lv01 vg01
+++++
Logical volume "lv01" created.
+++++
$ lvcreate --size 1G --name lv02 vg01
+++++
Logical volume "lv02" created.
+++++
$ lsblk
+++++
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 10G 0 disk
└─sdb1 8:17 0 10G 0 part
├─vg01-lv01 253:0 0 1G 0 lvm
└─vg01-lv02 253:1 0 1G 0 lvm
+++++
$ lvscan
+++++
ACTIVE '/dev/vg01/lv01' [1.00 GiB] inherit
ACTIVE '/dev/vg01/lv02' [1.00 GiB] inherit
+++++
$ lvs
+++++
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv01 vg01 -wi-a----- 1.00g
lv02 vg01 -wi-a----- 1.00g
+++++
$ lvdisplay vg01/lv01
+++++
--- Logical volume ---
LV Path /dev/vg01/lv01
LV Name lv01
VG Name vg01
LV UUID v0ixBU-c5qE-1PhW-ghyF-U4UU-js2b-9FSu1q
LV Write Access read/write
LV Creation host, time srv-centos-devops.gg.com, 2020-02-14 11:21:56 -0800
LV Status available
# open 0
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
+++++
##################################
# Create File System and Mount:
##################################
$ mkfs.ext4 /dev/vg01/lv01
$ mkfs.xfs -d su=32k,sw=6 /dev/vg01/lv02
$ mkdir /u01 /u02
$ mount /dev/vg01/lv01 /u01
$ mount /dev/vg01/lv02 /u02
$ df -hT /u0*
+++++
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg01-lv01 ext4 976M 2.6M 907M 1% /u01
/dev/mapper/vg01-lv02 xfs 1014M 33M 982M 4% /u02
+++++
$ lsblk
+++++
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 10G 0 disk
└─sdb1 8:17 0 10G 0 part
├─vg01-lv01 253:0 0 1G 0 lvm /u01
└─vg01-lv02 253:1 0 1G 0 lvm /u02
+++++
############################
# Resize File System:
############################
$ vgdisplay vg01
+++++
--- Volume group ---
VG Name vg01
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <10.00 GiB
PE Size 4.00 MiB
Total PE 2559
Alloc PE / Size 512 / 2.00 GiB
Free PE / Size 2047 / <8.00 GiB <<<<<<<<======== 8 GB is Free
VG UUID nXkbFj-ZFhX-tE4A-mpCp-MoDt-mwfB-amftVx
+++++
$ lvextend -L +4G /dev/vg01/lv01
+++++
Size of logical volume vg01/lv01 changed from 1.00 GiB (256 extents) to 5.00 GiB (1280 extents).
Logical volume vg01/lv01 successfully resized.
+++++
$ df -h /u01
+++++
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg01-lv01 976M 2.6M 907M 1% /u01
+++++
$ resize2fs /dev/vg01/lv01
+++++
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg01/lv01 is mounted on /u01; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vg01/lv01 is now 1310720 blocks long.
+++++
$ df -h /u01
+++++
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg01-lv01 4.9G 4.0M 4.7G 1% /u01
+++++
############################
# Add new PV to VG:
############################
# Add new physical disk on VM level
# Rescan scsi bus on server
$ lsblk
+++++
...
...
...
sdc 8:32 0 5G 0 disk
...
...
...
+++
$ fdisk /dev/sdc
$ pvcreate /dev/sdc1
$ vgs
+++++
VG #PV #LV #SN Attr VSize VFree
vg01 1 2 0 wz--n- <10.00g <4.00g
+++++
$ vgextend vg01 /dev/sdc1
+++++
Volume group "vg01" successfully extended
+++++
$ vgs
+++++
VG #PV #LV #SN Attr VSize VFree
vg01 2 2 0 wz--n- 14.99g 8.99g
+++++
############################
# Useful commands:
############################
http://landoflinux.com/linux_lvm_command_examples.html
https://opensource.com/business/16/9/linux-users-guide-lvm