"My Linux, I am the boss!" "The principle and implementation of logical volume management LVM

Source: Internet
Author: User
Tags bz2

Today we'll look at the concept, role, and use of LVM to help you understand LVM and be able to use LVM to flexibly configure and manage your disk system.
One, what is LVM
LVM is the short name for logical volume management (Logical Volume Manager), a mechanism for managing disk partitions, a logical layer of resumes on disk and partitions, to increase the flexibility of disk Management. With LVM, several disk partitions can be connected to a whole block of volume groups (Volume group), forming a storage pool. You can create logical volumes (Logical Volume) at will on a volume group, and further create file systems on logical volumes, providing greater flexibility than direct physical storage management.
LVM is essentially a virtual device driver that maintains a mapping between the physical device and the file system layer, maintaining this logical and physical disk area. LVM is mainly realized through DM technology, i.e. device mapper equipment mapping technology.

Device Mapper Kernel Architecture is the kernel architecture of DM device mapping, in which DM supports a wide range of technologies, including linear linear link, similar to JBOD technology, can be used to organize multiple disks into a disk, and mirror mirroring technology, The data can be backed up; snapshot is the snapshot volume technology, you can save the system a moment ago, and so on if the system error, need to recover, you can use the snapshot to recover; Multipath Multipath allows the server to have multiple lines to transmit data, and when a problem occurs on a line, The system can still transmit data smoothly through other lines.
two, the advantages of LVM
LVM will store virtualization, use logical volumes, you will not be limited to the size of the physical disk, additional hardware-related storage settings will be hidden, you can not stop the application or unmount the file system can directly adjust volume size and data migration, reduce operating costs. LVM has the following advantages over the direct use of physical storage:
(1) Flexible capacity
When using logical volumes, the file system can be extended to multiple disks, and you can aggregate multiple disks or partitions into a single logical volume.
(2) Scalable Storage pool
You can use simple commands to enlarge or reduce the size of the logical volume without reformatting or partitioning the disk device.
(3) on-line data distribution
You can move the data online, and the data can be redistributed when the disk is online.
(4) Convenient naming of equipment
The logical volume can be any name in a way that you feel convenient.
(5) Mirrored volume
LVM logical volumes provide a convenient way to mirror your data.
(6) Snapshot volume
With logical volumes, you can get device snapshots for consistent backups or test data updates without impacting real data.
Three, the basic concept

1, physical Volume: PV (physical Volume)
The physical volume is at the bottom of the logical management, which can be a partition on the actual physical disk, or an entire physical disk, or even a RAID disk array.
2, Volume Group: VG (Volume Group)
A volume group is built on top of a physical volume, and a volume group includes at least one physical volume, which can be expanded or reduced dynamically after the volume group resumes.
3, Logical Volume: LV (Logical Volume)
The logical volume is built on top of the volume group, and unallocated space in the volume group can be used to create new logical volumes that can be dynamically scaled or scaled down after the logical volume is established. Multiple logical volumes in a system can belong to the same volume group, or they can belong to different volume groups.
4, Physical Disk area: PE (physical Extent)
The physical extents are the smallest storage units available for allocation in physical volumes, and the size of the physical extents can be specified when a physical volume is established, depending on the actual situation. Physical disk size Once determined, it cannot be changed, and all physical physical extents in the same volume group are the same size.
5, Logic Panel: LE (Logical Extent)
The logical extents are the smallest storage units that can be allocated in a logical volume, and the size of the logical extents depends on the size of the physical extents of the volume group that the logical volume shrinks.
Four, common commands
PV
Pvcreat,pvremove,pvscan,pvdisplay,pvmove
Vg
Vgvreat,vgremove,vgextend,vgreduce,vgs,vgdisplay,vgscan
Lv
Lvcreat,lvremove,lvextend,lvreduce,lvs,lvdisplay
Five, LVM logical volume management operation detailed
first create three PV partitions
#fdisk/DEV/SDA
N (new partition)
+7g
N
+3g
N
+5g
T (adjust partition type)
10
8e (adjusted to LVM type)
T
11
8e
T
12
8e
W (Save exit)
#partprobe/DEV/SDA
Explanation: Reread the/DEV/SDA partition information
#cat/proc/partitions
Explanation: Check if you have reread the partition information after the update succeeds
#pvcreat/dev/sda{10,11}
Explanation: Creating physical volumes sda10 and SDA11
#pvs
Explanation: View PV information for the current system
#pvdisplay/dev/sda10
Explanation: View the details of a sda10 physical volume
#pvscan
Explanation: Scans the current system for how many physical volumes there are
Create a VG volume group
#vgs
Explanation: View Volume group information for the current system
#vgcreat myvg/dev/sda{10,11}
Explanation: Creating a volume group, placing sda10 and Sda11 in a MYVG volume group
#vgs
Explanation: Check out the information for the volume group you created
#vgdisplay MYVG
Explanation: Displays the details of volume group creation, and you can see that the PE size is 4M
#pvdisplay/dev/sda10
Explanation: You can see that the values for PE size and total PE are displayed.
#vgremove MYVG
Explanation: Remove MYVG
#vgcreat-S 8M myvg/dev/sda{10,11}
Explanation: The unit size of the re-specified PE physical disk area is 8M
#vgdisplay MYVG
Explanation: Displays the details of the volume group and can see the size of the PE physical disk area is 8M
perform reduced VG volume group Operations
#pvs
Explanation: You can view the corresponding entries for the volume group for each disk
#pvmove/DEV/SDA11
Explanation: First move the data from the physical disk area on the SDA11 to a different panel.
#vgreduce MYVG/DEV/SDA11
Explanation: Removing the sda11 from the MYVG
#pvremove/DEV/SDA11
Explanation: The last action to remove physical volume SDA11 can be performed
to extend a new volume group VG operation
#pvcreat/dev/sda12
Explanation: Creating a physical volume Sda12
#vgextend Myvg/dev/sda12
Explanation: Adding a physical volume to a MYVG volume group Sda12
#pvdisplay/dev/sda12
Explanation: You can find that when Sda12 joins MYVG's volume group, the default physical area size of Sda12 is automatically updated to 8M
creating a logical volume
#lvcreat-L 50m-n TESTLV MYVG
Explanation: Create an LV logical volume with a size of 50M named TESTLV for volume group MYVG
#lvdisplay/DEV/MYVG/TESTLV
Explanation: Displaying the details of a logical volume under/MYVG/TESTLV
#mke2fs-j/DEV/MYVG/TESTLV
Explanation: Advanced format to EXT3 file system for Logical volume TESTLV
#mount/dev/myvg/testlv/mnt
Explanation: Mount the file system TESTLV to the/MNT directory
#ls/mnt
Explanation: You can see the Lost+found file in the/mnt directory. Description mounted successfully, the file system is available
#mount
Explanation: You can see that the/DEV/MAPPER/MYVG-TESTLV file is mounted under/MNT
#ls-L/dev/mapper
Explanation: You can see that this is part of the B device file
#ls-L/DEV/MYVG
Explanation: You can see that the TESTLV under/DEV/MYVG is a linked file that points to/DEV/MAPPER/MYVG-TESTLV
remove a logical volume
#umount/mnt
Explanation: If a logical volume is mounted in a state that is in an open state, it cannot be removed directly and needs to be uninstalled first
#lvremove/DEV/MYVG/TESTLV
Explanation: The logical volume can be removed successfully
Extending logical Volumes
#lvcreat-L 2g-n TESTLV MYVG
Explanation: Because of the previous deletion, re-use volume group MYVG to create a 2G logical volume TESTLV
#mke2fs-j/DEV/MYVG/TESTLV
Explanation: TESTLV The re-created logical volume to the ext3 file system
#mkdir/users
Explanation: Create a user's directory to mount the logical volume's file system
#vim/etc/fstab
Explanation: Enter the/etc/fstab configuration file
/dev/myvg/testlv/users ext3 defaults,acl 0 0
Explanation: Add the above line of information in the/etc/fstab configuration file
#mount-A
Explanation: The-a option means that all file systems defined in the/etc/fstab file are mounted
#df-LH
Explanation: The size of the/DEV/MAPPER/MYVG-TESTLV found at this time is 2G
#lvextend-L 5G/DEV/MYVG/TESTLV
Explanation: Extending the physical boundaries of a logical volume TESTLV to a 5G size
#lvs
Explanation: The size of the TESTLV was found to be extended to 5G, but now only extends the physical boundary, without extending the logical boundary
#resize2fs-P/DEV/MYVG/TESTLV
Explanation: Logical boundaries of logical volumes TESTLV also extend to the same size as physical boundaries 5G
#df-LH
Explanation: found that the DEV/MAPPER/MYVG-TESTLV also showed 5G
#cd/users
#ls
Explanation: The file can still be viewed normally inittab
Reducing logical volumes
Attention:
1, cannot be reduced online, must first uninstall
2, ensure that the reduced space size still can store all the original data
3, you should forcibly check the file before shrinking to ensure that the file system is in a consistent state
#df-LH
Explanation: Check the size of the logical volume first
#umount/users
Explanation: Uninstalling the/users mounted directory
#e2fsck-F/DEV/MYVG/TESTLV
Explanation: Forcing checks for consistency within the logical volume file system
#resize2fs/DEV/MYVG/TESTLV 3G
Explanation: First reduce logical boundary of TESTLV logical volume to 3G size
#lvreduce-L 3G/DEV/MYVG/TESTLV
Explanation: Then reduce the physical boundaries of the TESTLV logical volume
#mount-A
Explanation: Re-mount the reduced TESTLV logical volume by rereading all file systems defined in the/etc/fstab
To create a snapshot volume
Attention:
1, the life cycle is the entire data length, in this time period, the data growth cannot exceed the snapshot volume size
2, the snapshot volume should be read-only
3, in the same volume group as the original volume
#cp/ect/inittab./
Explanation: Copy the/ect/inittab to the current directory
#cp/etc/issue./
#lvcreat-L 20m-n test-snap-s-P R/DEV/MYVG/TESTLV
Explanation: The size of the-l snapshot volume is 20m,-n the snapshot volume has the name test-snap,-s the snapshot volume is created, and the-p permission is read-only
#mount/dev/myvg/tsetlv-snap/mnt
Explanation: After mounting a snapshot volume, it is found that the data content is stored at the time of the backup data, and later if modified or new will not be displayed
#tar jcf/tmp/users.tar.bz2 Inittab Issue
Explanation: Compressing a file under a snapshot volume to a/tmp/users.tar.bz2 file
#umount/mnt
Explanation: When the snapshot volume ends, you can unmount the snapshot volume
#lvremove/dev/myvg/testlv-snap
Explanation: Removing a snapshot volume Testlv-snap
#cd/users
#rm Inittab Issue Messages
Explanation: The simulation inadvertently deleted the information in the/users directory
#tar xf/tmp/users.tar.bz2
Explanation: Expanded the package compressed file of the snapshot volume just saved to the/users directory, thus completing the role of restoring the snapshot volume to a specific time in the past

"My Linux, I am the boss!" "The principle and implementation of logical volume management LVM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.