Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the basic characteristics and daily management of LVM

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to understand the basic features of LVM and day-to-day management. The content is concise and easy to understand. It will definitely make your eyes shine. I hope you can learn something from the detailed introduction of this article.

Basic features of LVM: (cluster logical volume management can be implemented through plug-in CLVM)

PV Physical Volume

LV logical volumes (logical volume management: an abstraction layer is generated on top of physical storage to create logical storage volumes for easy device naming)(the following is the classification of logical volumes) Linear Linear volume (this is the default lvm form, i.e. occupying disks sequentially, writing one disk after another)Stripe Striped logical volume RAID raid logical volume Mirror Mirror Volume Thinly-Provision Thin provisioning logical volumes Snapshot Snapshot Volume Thinly-Provisioned Snapshot Thin Provisioning Snapshot Volume Cache When a cache volume is created (along with) 1: Close to the beginning of the device, place a label, including uuid, the location #of metadata (this label is kept one copy per disk by default)2: lvm metadata, containing the configuration details of the lvm volume group 3: Remaining space for storing data

The concept of lvm logical volume and the steps to create lvm

#Composition of LVM PE: (physical extension, is the basic unit of VG volume group) PV: (Physical Volume) VG: (Volume Group) LV: (logical volume)#Steps to create lvm 1: Create the disk as PV (physical volume). In fact, the physical disk is striped into PV and divided into PE. The default size of each PE is 4MB. 2: Create a VG (Volume Group), which is actually a space pool, with different PVs joining the same VG 3: Create LV (logical volume), the PE that makes up LV may come from different physical disks 4: Format LV, mount it

lvm related command tools

pv operation command pvchange Change the properties of a physical volume pvck Check physical volume metadata pvcreate Initialize disks or partitions for lvm use pvdisplay Display properties of physical volumes pvmove Mobile Physics Exent pvremove Delete physical volumes pvresize Resize disks or partitions used by lvm2 pvs Reports information about physical volumes pvscan Scan all disks of physical volume vg operation command vgcfgbackup backup volume group descriptor area vgcfgrestore Recovery Volume Group Descriptor Area vgchange Change the properties of a volume group vgck Examining Volume Group Metadata vgconvert Convert Volume Group Metadata Format vgcreate create a volume group vgdisplay Show properties of volume groups vgexport Make the volume group unaware of the system (what is this) vgextend Add physical volumes to volume groups vgimportclone Import and rename duplicate volume groups (e.g. hardware snapshots) vgmerge Merge two volume groups vgmknodes Recreate volume group directories and logical volume special files vgreduce Reduce volume groups by deleting one or more physical volumes (kick physical volumes out of VG) vgremove Delete Volume Group vgrename Rename a volume group vgs Report information about volume groups vgscan Scan all disks of a volume group and rebuild cache vgsplit Split a volume group into two, moving any logical volume from one volume group to another by moving the entire physical volume lv action command lvchange Change logical volume properties lvconvert Convert logical volumes from linear to mirror or snapshot lvcreate Create logical volumes from existing volume groups lvdisplay Display logical volume properties lvextend Expand the size of logical volumes lvmconfig Display configuration information after loading lvm.conf and any other configuration files lvmdiskscan Scan all devices visible to lvm2 lvmdump Create lvm2 information dump for diagnostic purposes lvreduce Reduce the size of logical volumes lvremove Delete logical volume lvrename Rename logical volume lvresize Resize logical volumes lvs Reports information about logical volumes lvscan Scan all logical volumes

PV management

Create PVpvcreate /dev/sdb1 Delete pv Undo PV (need to kick out vg first) pvremove /dev/sdb1

VG Management

Make VGvgcreate datavg /dev/sdb1vgcreate datavg /dev/sdb1 /dev/sdb2#Explain: vgcreate vg name partition vgcreate -s 16M datavg2 /dev/sdb3#Explain: -s Specify pe size as 16M, default not specify 4M Remove missing disks from volume group vgrereduce--removingdatavg vgrereduce--removingdatavg--force #forcibly remove extended VG space vgextend datavg /dev/sdb3pvs kick out a member of vg vgrereduce datavg /dev/sdb3vgs

LV Management

Create LVlvcreate -n lvdata1 -L 1.5G datavg#Explanation: -n lv name, -L specifies lv size, datavg is the name of vg, indicating that vg activates the repaired logical volume lvchange -ay /dev/datavg/lvdata1lvchange -ay /dev/datavg/lvdata1 -K #Forced Activation

Snapshot of LVM

Purpose: Note: The purpose is data consistency backup. First, make a snapshot and freeze the current system. In this way, the contents of the snapshot can be temporarily unchanged. The system itself continues to run. By remounting the backup snapshot volume, it can realize uninterrupted service backup.

lvcreate -s -n kuaizhao01 -L 100M /dev/datavg/lvdata1

View, delete Usage

1: View physical volume information pvs,pvdisplay2: View volume group information vgs,vgdisplay3: View logical volume information lvs,lvdisplay4: Delete LVlvremove /dev/mapper/VG-mylv 5: Delete VGvgremove VG6: Delete PV (note that the deletion order is LV, VG, PV) pvremove /dev/sdb

vg volume group renaming

vgrename xxxx-vgid-xxxx-xxxx xinname

Stretch a logical volume LV

1: Use vgdisplay to see how much free space is left in vg 2: Expand the logical volume lvextend -L +1G /dev/VG/LV01 lvextend -L +1G/dev/VG/LV01-r #This command means that the file system is updated while expanding, but not all distributions support it, except for some file systems that do not support online extension 3: After the expansion operation, df -h You will find that the size does not change 4: Update the file system (competing for different file systems, the update command is different) e2fsck -f /dev/datavg/lvdata1 #ext4 file system, check the lv file system resize 2dev/fs/VG/LV01 #ext4 file system command followed by lv device name xfs_growfs /nas #xfs file system, this command is directly followed by the mount point When you update the file system, you will find that df -h is normal

Shrink logical volume LV (must be offline, umount)

1: Unmount 2: Shrink File System resize2fs /dev/VG/LV01 2G3: shrink LV lvreduce -L -1G /dev/VG/LV014: view lvs, mount use

Stretch a volume group VG

1: Insert a new hard disk. If it is not a hot-pluggable disk, you can try this. Force refresh the hard disk interface on the system for i in /sys/class/scsi_host/*; do echo "---" > $i/scan; done2: Stripe/dev/sdd and format it as PEpvcreate /dev/sdd3: Add a new PV to the existing VG vgextend VG /dev/sdd4: View the size vgs

Reduce the volume group VG (be careful not to have PE occupied)

1: Remove a PV from a given volume vgrereduce VG /dev/sdd2: View reduced volume group size

Adding and kicking disks into VG

Kick sdd1 out of datavg vgreduce datavg /dev/sdd1 Add sdb1 to datavg vgextend datavg /dev/sdb1

lvm disaster recovery scenario case

#Scene reproduction: Three disks do lvm. Now one of them is physically broken. Put the remaining two disks on other linux servers #Recovery Step 1: Check the disk information, lvm information, confirm that you can find lvm related information, and find the name of VG group.(pvs,lvs,vgs,fidsk,blkid) Second: Delete the damaged disk role in the lvm information,(Forcing a failed disk)"vgrereduce--removing VG_name " Third: Forcing VG group "vgchange -ay" Fourth: Forcing LVM "lvchange -ay /dev/VG_name" Fifth: Mounting The above is how to understand the basic features of LVM and daily management. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report