This is article 62 of the Stick to technical Writing Project (including translation). Set a small goal of 999, at least 2 articles per week.
This article mainly explains how to configure LVM physical volumes, logical volumes, logical volume groups, and common capacity expansion and reduction operations based on Ubuntu.
The physical media
Hard disks, such as /dev/hda and /dev/sda, are the lowest storage units of the storage system.
physicalvolume
A physical volume is a disk partition or a device (such as RAID) that has the same logical function as a disk partition. It is the basic storage logical block of the LVM. However, compared with basic physical storage media (such as partitions and disks), a physical volume contains management parameters related to the LVM.
Volume Groups
An LVM volume group is similar to a physical disk in a non-LVM system and consists of physical volumes. You can create one or more “LVM partitions” (logical volumes) on a volume group, which consists of one or more physical volumes.
logicalvolume
An LVM logical volume is similar to a hard disk partition in a non-LVM system, on which file systems (such as /home or /usr, etc.) can be built.
PE (Physical extent)
Each Physical volume is divided into basic units called Physical Extents (PE). A PE with a unique number is the smallest unit that can be addressed by LVM. The PE size is configurable and is 4MB by default.
LE (Logical extent)
Logical volumes are also divided into basic addressable units called Logical Extents (LE). Within the same volume group, the size of LE and PE are the same and correspond one to one.
This reference is from Linx volume management details VG LV PV
steps
Note If a disk is added from esxi/vmware, fdisk -l is used to delete the disk. You can restart the disk or echo “SCSI add-single-device 32 0 2 0”>/proc/scsi/scsi and run fdisk -l
See vm VMware Added hard disk Unrecognized
fdisk -l
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 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 /dev/sdc: 50 GiB, 53687091200 bytes, 104857600 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
#... Omit useless
Copy the code
Two disks are available. Perform the following operations
Create physical volumes, logical volume groups, and logical volumes
Create physical volumes based on disks
> pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created
# Check existing physical volumes> pvdisplay -- Physical volume -- PV Name /dev/sda5 VG Name rancher-252- VG PV Size 49.28 GiB/not usable 2.00 MiB Allocatable Yes PE Size 4.00 MiB Total PE 12616 Free PE 4 Allocated PE 12612 PV UUID 9FdgPm-P5Ao-zK2Q-FEiA-aYOi-QBcM-PRVjIn"/dev/sdc" is a new physical volume of "50.00 GiB"-- NEW Physical volume -- PV Name /dev/sDC VG Name PV Size 50.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID FGkHWb-y0d8-iq4D-OeFd-JAh4-Dx2K-vp46W0Create a logical volume group
> vgcreate vg_data /dev/sdc
Volume group "vg_data" successfully created
# Check the logical volume group
> vgdisplay
--- Volume group ---
VG Name vg_data
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 50.00 GiB PE Size 4.00 MiB Total PE 12799 Alloc PE/Size 0/0 Free PE/Size 12799/50.00 GiB VG UUID 8vGOL0-H0fu-ATx1-e9Cf-NO2D-xFFh-iduqod -- Volume group --- VG Name rancher-252-vg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Accessread/write VG Status Resizable MAX LV 0 Cur LV 2 Open LV 2 MAX PV 0 Cur PV 1 Act PV 1 VG Size 49.28 GiB PE Size 4.00 MiB Total PE 12616 Alloc PE/Size 12612/49.27 GiB Free PE/Size 4/16.00 MiB VG UUID MWvlQB-lTEX-Svxu-wcTA-R6EC-wniE-RKpzGHCreate logical volume and allocate all space
> lvcreate -l 100%VG -n lv_data vg_data
Logical volume "lv_data" created.
Format and mount the disk
# format
mkfs.ext4 /dev/mapper/vg_data-lv_data
Create folder
mkdir -p /data
# backup
cp /etc/fstab /etc/fstab.bak
# Make it automatically mount after startup
echo `blkid /dev/mapper/vg_data-lv_data | awk '{print $2}' | sed 's/\"//g'` /data ext4 defaults 0 0 >> /etc/fstab
# Mount nowMount /dev/mapper/vg_data-lv_data /data/ df -h Filesystem Size Used Avail Use% Mounted on udev 7.9g 0 7.9g 0% /dev TMPFS 1.6G 8.8m 1.6g 1% /run /dev/mapper/rancher--252--vg-root 48G 2.0g 44G 5% / TMPFS 7.9g 0 7.9g 0% /dev/shm TMPFS 5.0m 0 5.0m 0% /run/lock TMPFS 7.9g 0 7.9g 0% /sys/fs/cgroup /dev/sda1 720M 58M 626M 9% /boot TMPFS 1.6g 0 1.6g 0% /run/user/1000 /dev/mapper/vg_data-lv_data 50G 52M 47G 1% /dataA 50GB volume has been mounted to the /data directory
Copy the code
Volume increase
Add a 100 GB disk (/dev/sdb) to the 50 GB /dev/mapper/vg_data-lv_data logical volume to expand the disk space to 150 GB
# uninstall
umount /data/
Create a physical volume
pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
Add disks to vG_data logical group
vgextend vg_data /dev/sdb
Vg_data = 150G
vgdisplay vg_data
--- Volume group ---
VG Name vg_data
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write VG Status Resizable MAX LV 0 Cur LV 1 Open LV 1 MAX PV 0 Cur PV 2 Act PV 2 VG Size 149.99 GiB PE Size 4.00 MiB Total PE 38398 Alloc PE/Size 12799/50.00 GiB Free PE/Size 25599/100.00 GiB VG UUID 8VgOL0-H0FU-ATx1-e9cF-NO2D-xffH-iDUqoD# Expand the logical volumeLvextend -l +100%FREE /dev/mapper/vg_data-lv_data Size of logical volume vg_data/lv_data changed from 50.00 GiB (12799) Extents) to 149.99 GiB (38398 extents). Logical volume lv_data successfully resized.# Check the logical volume capacity
lvdisplay /dev/mapper/vg_data-lv_data
--- Logical volume ---
LV Path /dev/vg_data/lv_data
LV Name lv_data
VG Name vg_data
LV UUID 02Xd3v-05hl-ZH2v-l3Qp-BkXE-ndbB-wbhdRu
LV Write Access read/write
LV Creation host, time rancher-252, 2021-04-27 15:15:49 +0800
LV Status available
# open 1LV Size 149.99 GiB Current LE 38398 Segments 2 Allocation Inherit Read ahead sectors auto-currentlyset to 256
Block device 252:2
Recalculate the logical volume sizeFilesystem at /dev/mapper/vg_data-lv_data resize2fs 1.42.13 (17-may-2015) Filesystem at /dev/mapper/vg_data-lv_data is mounted on /data; on-line resizing required old_desc_blocks = 4, new_desc_blocks = 10 The filesystem on /dev/mapper/vg_data-lv_data is now 39319552 (4k) blocks long. df -h Filesystem Size Used Avail Use% Mounted on udev 7.9g 0 7.9g 0% /dev TMPFS 1.2g 8.8m 1.6g 1% /run /dev/mapper/rancher--252--vg-root 48G 2.0g 44G 5% / TMPFS 7.1g 0 7.1g 0% /dev/shm TMPFS 5.0m 0 5.0m 0% /run/lock TMPFS 7.9g 0 7.9g 0% /sys/fs/cgroup /dev/sda1 720M 58M 626M 9% /boot TMPFS 1.6g 0 1.6g 0% /run/user/1000 /dev/mapper/vg_data-lv_data 148G 60M 141G 1% /dataCheck file integrityE2fsck -f /dev/mapper/vg_data-lv_data e2fsck 1.42.13 (17-may-2015) step 1: check inodes, blocks, and sizes /dev/mapper/vg_data-lv_data Checking Reference counts /dev/mapper/vg_data-lv_data 11/9830400 files (0.0% non-contiguous), 66499/39319552 blocks# mount
mount /dev/mapper/vg_data-lv_data /data/
Copy the code
Huddle up capacity
Generally, the capacity will not be reduced, unless there is no free space, and the other folder needs disk more, the space saved by reducing the capacity of A to B.
# uninstall
umount /data/
Check file integrityE2fsck -f /dev/mapper/vg_data-lv_data e2fsck 1.42.13 (17-may-2015) step 1: check inodes, blocks, and sizes /dev/mapper/vg_data-lv_data Checking Reference counts /dev/mapper/vg_data-lv_data 11/9830400 files (0.0% non-contiguous), 66499/39319552 blocks# Shrink to 50GResize2fs /dev/mapper/vg_data-lv_data 49G resize2fs 1.42.13 (17-may-2015) Resizing the filesystem on /dev/mapper/vg_data-lv_data to 12845056 (4k) blocks. The filesystem on /dev/mapper/vg_data-lv_data is now 12845056 (4k) blocks long.Logical scaling down to 49G
lvreduce -L 50G /dev/mapper/vg_data-lv_data
WARNING: Reducing active logical volume to 50.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_data? [y/n]: y
Size of logical volume vg_data/lv_data changed from 149.99 GiB (38398 extents) to 49.00 GiB (12544 extents).
Logical volume lv_data successfully resized.
# Query logical volume information
lvdisplay /dev/mapper/vg_data-lv_data
--- Logical volume ---
LV Path /dev/vg_data/lv_data
LV Name lv_data
VG Name vg_data
LV UUID 02Xd3v-05hl-ZH2v-l3Qp-BkXE-ndbB-wbhdRu
LV Write Access read/write
LV Creation host, time rancher-252, 2021-04-27 15:15:49 +0800
LV Status available
# open 0LV Size 50.00 GiB Current LE 12544 Segments 1 Allocation inherit Read ahead sectors auto-currentlyset to 256
Block device 252:2
# Remove disk /dev/sdb from the logical volume group
vgreduce vg_data /dev/sdb
Removed "/dev/sdb" from volume group "vg_data"
# View information
vgdisplay vg_data
--- Volume group ---
VG Name vg_data
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access read/write VG Status Resizable MAX LV 0 Cur LV 1 Open LV 0 MAX PV 0 Cur PV 1 Act PV 1 VG Size 50.00 GiB PE Size 4.00 MiB Total PE 12799 Alloc PE/Size 12544/49.00 GiB Free PE/Size 255/1020.00 MiB VG UUID 8VgOL0-H0FU-ATx1-e9cF-NO2D-xffH-iDUqoD# mountMount /dev/mapper/vg_data-lv_data /data/ df -h Filesystem Size Used Avail Use% Mounted on udev 7.9g 0 7.9g 0% /dev TMPFS 1.6G 8.8m 1.6g 1% /run /dev/mapper/rancher--252--vg-root 48G 2.0g 44G 5% / TMPFS 7.9g 0 7.9g 0% /dev/shm TMPFS 5.0m 0 5.0m 0% /run/lock TMPFS 7.9g 0 7.9g 0% /sys/fs/cgroup /dev/sda1 720M 58M 626M 9% /boot TMPFS 1.6g 0 1.6g 0% /run/user/1000 /dev/mapper/vg_data-lv_data 50G 52M 47G 1% /dataCopy the code
Want ads
Friends in Jinan, Shandong, welcome to join us and do things together. Long-term recruitment, Java programmer, big data engineer, operation and maintenance engineer, front-end engineer.
The resources
- My blog
- I’m the nuggets
- Linx Volume management details VG LV PV
- The VMware vm disk cannot be identified