LVM Overview (reference Baidu encyclopedia ):
LVM is short for logical volume manager. It is a mechanism for managing disk partitions in Linux, LVM is a logical layer built on the hard disk and partition to increase the disk score.
LVM
LVM zone management flexibility. As mentioned above, LVM is a logical layer added between the disk partition and the file system to shield the file system from the underlying disk partition layout and provide an abstract disk volume, create a file system on the disk. A physical volume (physical volume) refers to a hardware Partition or a device (such as RAID) with the same functions as a disk partition logically. It is the basic storage Logical Block of LVM, however, compared with basic physical storage media (such as partitions and disks), it contains management parameters related to LVM.
The most common hard-to-decide problem that Linux users encounter when installing the Linux operating system is how to correctly evaluate the size of each partition to allocate suitable hard disk space. When a partition space is exhausted, the solution is usually to use a symbolic link or a tool to adjust the partition size (such as patitionmagic), but this is only a temporary solution, the problem is not fundamentally solved. With the appearance of the Logical Disk volume management function in Linux, these problems have been solved, and users can easily adjust the size of each partition without downtime.
Demo environment: centos6.4. Three hard disks, two of which are created and one is extended.
Overview: PE | PV | VG | LV
- PE (physical extend): Physical expansion
- PV (physical volume): physical volume --- what is at the bottom of LVM. It can be a hard disk such as SDA, SDB, or SDC. It can also be a partition such as sda1 or sdb1 in a hard disk.
- VG (volume group): volume group-a volume group consists of multiple LV, which is an abstract directory rather than a device, such as/dev/testvg.
- LV (logic volume): logical volume --- LV exists in PE
- Figure:
PV:/dev/sdb/dev/SDC
-- PV --
VG: -- PV --
LV: -- LV --
LVM command parameters:
PVS, vgs, and LVS: the information is displayed briefly.
Pvdisplay, vgdisplay, and lvdisplay: displays detailed information.
LVM creation process:
PV> VG> LV> formatting> mounting
LVM usage --- create and view PV
[Root @ localhost ~] # Pvcreate/dev/SD [B, c] // you can use a partition or hard disk .. pvcreate/dev/SD [B, c] 1 is the first partition of the two hard disks to create PV physical volume "/dev/SDB" successfully created physical volume "/dev/SDC" successfully created [root @ localhost ~] # Pvs pv vg fmt attr psize pfree/dev/SDB lvm2 A -- 20.00g 20.00g/dev/SDC lvm2 A -- 20.00g 20.00G [root @ localhost ~] # Pvsdisplay-Bash: pvsdisplay: Command not found [root @ localhost ~] # Clear [root @ localhost ~] # Pvs pv vg fmt attr psize pfree/dev/SDB lvm2 A -- 20.00g 20.00g/dev/SDC lvm2 A -- 20.00g 20.00G [root @ localhost ~] # Pvdisplay "/dev/SDB" is a new physical volume of "20.00 gib" --- new physical volume --- PV name/dev/sdb vg name PV size 20.00 gib allocatable no pe size 0 total pe 0 free pe 0 allocated pe 0 pv uuid U71gX3-EtNA-tVPL-8WYL-99Do-PY3c-LUsfeE "/dev/SDC" is a new physical volume of "20.00 gib" --- new physical volume --- PV name/dev/SDC VG name PV size 20.00 gib allocatable no pe size 0 total pe 0 free pe 0 allocated pe 0 pv uuid TqI9uD-vvG1-2eD2-kyTM-cEtj-ZpXc-ctLi91
LVM usage --- create and view VG
[Root @ localhost ~] # Vgcreate testvg/dev/SD [B, c] volume group "testvg" successfully created // disk or partition where the vgcreate volume group name falls into the volume group [root @ localhost ~] # Vgs VG # PV # LV # Sn ATTR vsize vfree testvg 2 0 0 WZ -- n-39.99g 39.99G [root @ localhost ~] # Vgdisplay --- volume group --- VG name testvg System ID format lvm2 metadata areas 2 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 2 act pv 2 VG size 39.99 gib PE size 4.00 MIB total PE 10238 alloc PE/size 0/0 free PE/size 10238/39 .99 gib vg uuid fSkmZR-8WiE-COe8-n4QO-rmAz-2PgJ-BRuity
LVM usage --- create and view LV
[Root @ localhost ~] # Lvcreate-N testlv1-L 10g testvg //-N is the name of the LV volume, -l: Set the LV size [g or M] logical volume "testlv1" created [root @ localhost ~] # Lvs lv vg attr lsize pool ORIGIN data % Move log CPY % sync convert testlv1 testvg-wi-a ---- 10.00g [root @ localhost ~] # Lvdisplay --- logical volume --- LV path/dev/testvg/testlv1 LV name testlv1 VG name testvg lv uuid bPyUwj-twOD-flGj-x266-mXCl-rcfa-FBUykW LV write access read/write LV creation host, time localhost. localdomain, 17:32:23-0700 LV status available # Open 0 LV size 10.00 gib current le 2560 segments 1 Allocation inherit read ahead sectors auto-currently set to 256 block device 253: 0
LVM usage --- LV formatting and mounting
[Root @ localhost ~] # Mkfs. ext4/dev/testvg/testlv1 // here, my format is ext4mke2fs 1.41.12 (17-may-2010) filesystem label = OS type: linuxblock size = 4096 (log = 2) fragment size = 4096 (log = 2) stride = 0 blocks, stripe width = 0 blocks655360 inodes, 2621440 blocks131072 blocks (5.00%) reserved for the super userfirst data block = 0 maximum filesystem blocks = 268435456080 block groups32768 blocks per group, 32768 fragments per group8192 inodes PE R groupsuperblock backups stored on blocks: 32768,983 04, 163840,229 376, 294912,819 200, 884736,160 5632 writing inode tables: donecreating Journal (32768 blocks): donewriting superblocks and filesystem accounting information: donethis filesystem will be automatically checked every 37 mounts or180 days, whichever comes first. use tune2fs-C or-I to override. [root @ localhost ~] # Mount/dev/testvg/testlv1/mnt [root @ localhost ~] # Mount/dev/sda2 on/type ext4 (RW) proc on/proc type proc (RW) sysfs on/sys type sysfs (RW) devpts on/dev/PTS type devpts (RW, gid = 5, mode = 620) tmpfs on/dev/SHM type tmpfs (RW, rootcontext = "system_u: object_r: tmpfs_t: s0 ")/dev/sda1 on/boot type ext4 (RW) None on/proc/sys/fs/binfmt_misc type binfmt_misc (RW) /dev/mapper/testVG-testLV1 on/mnt type ext4 (RW)
Advanced LVM usage: stretch and zoom out
[Root @ localhost ~] # Lvextend-L + 5g/dev/testvg/testlv1 // increase the size of 5 GB to testlv1 extending logical volume testlv1 to 15.00 gib logical volume testlv1 successfully resized [root @ localhost ~] # Resize2fs/dev/testvg/testlv1 // update the file system and redefine the disk size. resize2fs 1.41.12 (17-may-2010) filesystem at/dev/testvg/testlv1 is mounted on/MNT; on-line resizing requiredold desc_blocks = 1, new_desc_blocks = 1 mongoming an on-line resize of/dev/testvg/testlv1 to 3932160 (4 K) blocks. the filesystem on/dev/testvg/testlv1 is now 3932160 blocks long. [root @ localhost ~] # DF-hfilesystem size used avail use % mounted on/dev/sda2 28g 3.4g 23g 13%/tmpfs 935 m 84 k 935 m 1%/dev/SHM/dev/sda1 291 M 58 m 218 M 22%/boot/dev/mapper/testVG-testLV1 15g 153 m 14g 2%/mnt
This example shows how to add a new hard disk to an existing volume group to increase the available PV.
[Root @ localhost ~] # Pvcreate/dev/SDD physical volume "/dev/SDD" successfully created [root @ localhost ~] # Vgextend testvg/dev/SDD volume group "testvg" successfully extended [root @ localhost ~] # Vgs VG # PV # LV # Sn ATTR vsize vfree testvg 3 1 0 WZ -- n-59.99g 44.99g // Why not remaining 60g, it is because we created a LV1 10g and expanded 5g to it. so the remaining 45 GB
Before performing this operation, you must re-define the volume size of the LV mounted by umount and then shrink the volume. --- if you do not follow this step, the data is very likely to be lost (irrecoverable, remember)
[Root @ localhost ~] # Umount/mnt // unmount the mounted LV volume. For details, refer to your mount point [root @ localhost ~]. # E2fsck-F/dev/testvg/testlv1 // check the file system [root @ localhost ~] # Resize2fs/dev/testvg/testlv1 5g // adjust the size of your file system online resize2fs 1.41.12 (17-may-2010) the filesystem is already 3932160 blocks long. nothing to do! [Root @ localhost ~] # Lvreduce-L-10g/dev/testvg/testlv1 // use lvreduce to reduce your disk size warning: switching active logical volume to 5.00 gib this may destroy your data (filesystem etc .) do you really want to reduce testlv1? [Y/n]: Y cing logical volume testlv1 to 5.00 gib logical volume testlv1 successfully resized [root @ localhost ~] # Lvdisplay // view detailed information about LV --- logical volume --- LV path/dev/testvg/testlv1 LV name testlv1 VG name testvg lv uuid bPyUwj-twOD-flGj-x266-mXCl-rcfa-FBUykW LV write access read/write LV creation host, time localhost. localdomain, 17:32:23-0700 LV status available # Open 0 LV size 5.00 gib // after 10 Gb removal, remaining 5g current le 1280 segments 1 Allocation inherit read ahead sectors auto-currently set to 256 block device 253: 0
[Root @ localhost ~] # Vgs // It is worth noting that the hard disk or partition removed from the volume group must be smaller than the remaining space. otherwise, the VG # PV # LV # Sn ATTR vsize vfree testvg 3 1 0 WZ -- n-59.99g 54.99G [root @ localhost ~] will fail to be saved. # Vgreduce testvg/dev/SDD removed "/dev/SDD" from volume group "testvg" [root @ localhost ~] # Vgs VG # PV # LV # Sn ATTR vsize vfree testvg 2 1 0 WZ -- n-39.99g 34.99g
Delete LVM:
Bottom-up: LV> VG> PV
[root@localhost ~]# lvremove /dev/testVG/testLV1Do you really want to remove active logical volume testLV1? [y/n]: y Logical volume "testLV1" successfully removed[root@localhost ~]# vgremove testVG Volume group "testVG" successfully removed[root@localhost ~]# pvremove /dev/sd[b,c] Labels on physical volume "/dev/sdb" successfully wiped Labels on physical volume "/dev/sdc" successfully wiped[root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sdd lvm2 a-- 20.00g 20.00g[root@localhost ~]# pvremove /dev/sdd Labels on physical volume "/dev/sdd" successfully wiped[root@localhost ~]# pvs[root@localhost ~]# vgs No volume groups found
Recommended command: e2fsadm
Equivalent to e2fsadm-L + 10g/dev/testvg/testlv1
# Lvextend-L + 10g/dev/testvg/testlv1
# Resize2fs/dev/testvg/testlv1
Equivalent to e2fsadm-L-10g/dev/testvg/testlv1 (equivalent only after umount)
# Resize2fs/dev/testvg/testlv1 5g
# Lvreduce-L-10g/dev/testvg/testlv1