Linux LVM (logical volume manage, logical volume management)

1. Noun explanation:

pv: physical volume, physical volume, can be a physical hard disk, hard disk partition or RAID disk array
vg: volume group, volume group, multiple physical volumes form a volume group, which is equivalent to forming a large hard disk or large partition
lv: logical volume , Logical volume, the partition formed after re-partitioning from the volume group is called logical volume
PE: physical extent, basic unit, 4M, each logical volume must be a multiple of 4M

A few knowledge:
1). A volume group (vg) can contain multiple physical volumes (pv), and after the volume group is created, you can continue to add new physical volumes.
2). The logical volume (lv) is created by cutting out part of the free capacity from the volume group, and the capacity can be adjusted (increase or decrease) after creation

2. Steps to deploy logical volume:

Suppose there are two hard disks /dev/sdb, /dev/sdc for LVM

1. Make the physical volume support LVM, and view the status of the physical volume through pvdisplay

pvcreate  /dev/sdb  /dev/sdc
pvdisplay

2. Add two hard disks to the volume group named myvg and check the status of the volume group

vgcreate  myvg  /dev/sdb  /dev/sdc
vgdisplay

3. Cut part of the space from the myvg volume group to create a logical volume named mylv, and make its capacity 400M (a multiple of 4M and less than the capacity of myvg)

lvcreate  -n  mylv  -l  100  myvg

-n mylv means that the logical volume is named mylv; -l 100 means to create a logical volume with 100*4M=400M space
can also be used -L 400 to mean to create a logical volume with 400M space

4. Format the logical volume and mount it for use (the partition uses four steps: create partition, format partition, mount partition, configure permanent mount)

The linux system can access the logical volume device in LVM through "/dev/volume group name/logical volume name"

mkfs.ext4  /dev/myvg/mylv
mkdir /lv0
mount /dev/myvg/mylv  /lv0
echo "/dev/myvg/mylv  /lv0  ext4  defaults  0   0 "  >>  /etc/fstab

Three, expand the logical volume

1. Before expansion, you need to cancel the mount point

umount  /lv0

2. Expand the logical volume to 600M (originally 400M), pay attention to the difference in usage of -L and -l

lvextend  -L  600  /dev/myvg/mylv

3. Check the integrity of the logical volume, and reset the logical volume capacity (without checking the integrity of the logical volume, the logical volume capacity cannot be reset)

e2fsck  -f  /dev/myvg/mylv
resize2fs  /dev/myvg/mylv

4. Re-mount and check the hard disk status

mount  -a
df  -h

Four, cut the logical volume

Cut the logical volume, there is a greater risk of data loss, data backup if necessary

1. Similar to expansion, first cancel the mount point

umount  /lv0

2. Before cutting, you need to check the integrity of the file system (to ensure maximum data security)

e2fsck  -f  /dev/myvg/mylv

3. Cut the capacity to 400M

resize2fs  /dev/myvg/mylv  400M

4. Re-mount and check the hard disk status

mount  -a
df  -h

Five, LVM delete operation (note that the data is backed up first)

1. Cancel the mount point

umount /lv0

2. Remove the mount point configuration information

vim  /etc/fstab

3. Delete the logical volume

lvremove /dev/myvg/mylv

4. Delete the volume group (only the volume group name is used, the absolute path of the device is not required)

vgremove myvg

5. Delete the LVM attribute of the physical volume

pvremove  /dev/sd[b-c]

Guess you like

Origin blog.csdn.net/ymz641/article/details/111472630