LVM is the short name of the Logical Disk volume management (Logical Volume Manager), which is a mechanism for managing disk partitions in a Linux environment, and LVM is a logical layer on top of hard disks and partitions to improve the flexibility of disk partition management. As mentioned earlier, LVM is a logical layer that is added between the disk partition and the file system to mask the underlying disk partition layout for the file system, providing an abstract disk volume, and creating a file system on the disk volume. Physical volume (physical volume) physical volume refers to a hard disk partition or a device that logically shares the same functionality as a disk partition (such as RAID), which is the basic storage logic block of LVM, but is compared to the basic physical storage media (such as partitions, disks, etc.) and contains management parameters related to LVM. One of the most common and difficult questions that Linux users encounter when installing Linux operating systems is how to properly evaluate the size of each partition to allocate the appropriate hard disk space. When a partition is exhausted, the solution is usually to use symbolic links, or to use tools that resize the partition (such as patitionmagic, etc.), but this is only a temporary workaround and does not solve the problem at all. With the advent of Linux Logical Disk volume management functions, these problems are solved, this article discusses the LVM technology, so that users can easily adjust the size of each partition without the need for downtime. [Url=http://www.itshantou.com/d/file/sys/redhat-linux/2007-12-04/673f477eae4858995e5adffaaf9f1c0a.jpg] [img]http://www.itshantou.com/d/file/sys/redhat-linux/2007-12-04/673f477eae4858995e5adffaaf9f1c0a.jpg[/img][/ Url
First, preface Each Linux consumer will encounter this dilemma when installing Linux: How to accurately evaluate and allocate the capacity of each hard disk partition when partitioning the system, as the system administrator takes into account not only the capacity required for a current partition, but also the maximum capacity that may be required for that partition. Because if the estimate is inaccurate, the administrator may even want to back up the entire system, clear the hard disk, re-partition the hard disk, and then restore the data to the new partition when a partition is not sufficient. While there are a lot of dynamic disk-tuning tools available, such as partationmagic and so on, it does not solve the problem completely, because one partition may be exhausted again, another is the need to reboot the system to achieve, for many critical servers, downtime is unacceptable, And for adding a new hard disk, if you want a file system that spans multiple hard drives, the partition tuning program does not solve the problem. Therefore, the perfect solution should be in the 0 downtime under the premise of the size of the file system can be easily adjusted to facilitate the implementation of the file system across different disks and partitions. Fortunately, the Logical Disk volume management (lvm,logicalvolumemanager) mechanism provided by Linux is a perfect solution. LVM is the abbreviation for Logical Disk volume management (logicalvolumemanager), which is a mechanism for managing disk partitions in a Linux environment, and LVM is a logical layer built on hard disks and partitions to improve the flexibility of disk partition management. The LVM system administrator makes it easy to manage disk partitions, such as connecting several disk partitions to a single block of volume group (volumegroup), forming a storage pool. Administrators can create logical volume groups (logicalvolumes) at will on a volume group and further create file systems on logical volume groups. The administrator can easily adjust the size of the storage volume group through LVM, and the disk storage can be named, managed and assigned as a group, for example, "development" and "sales", instead of using the physical disk name "SDA" and "SDB". And when a new disk is added to the system, the LVM administrator does not have to move the disk's files to the new disk to take full advantage of the new storage space, but instead directly extend the file system across the disk. Ii. Basic terminology of LVM As mentioned earlier, LVM is a logical layer that is added between the disk partition and the file system to mask the underlying disk partition layout for the file system, providing an abstract disk volume, and creating a file system on the disk volume. First we discuss the following LVM terminology: * Physical storage media (Thephysicalmedia) This refers to the storage device of the system: the hard disk, such as:/DEV/HDA1,/DEV/SDA, etc., is the lowest layer of storage system storage unit. * Physical Volume (Physicalvolume) A physical volume is a partition of a hard disk or a device that logically has the same function as a disk partition (for example, RAID), which is the basic storage logic block of LVM, but is compared to basic physical storage media (such as partitions, disks, etc.) and contains management parameters related to LVM. * Volume Group (volumegroup) LVM volume groups are similar to physical hard disks in non-LVM systems, which consist of physical volumes. You can create one or more LVM partitions (logical volumes) on a volume group, and an LVM volume group consists of one or more physical volumes. * Logical Volume (Logicalvolume) LVM logical volumes are similar to hard disk partitions in non-LVM systems, and file systems (such as/home or/usr) can be created on top of logical volumes. *pe (physicalextent) Each physical volume is divided into a basic unit called PE (physicalextents), and a uniquely numbered PE is the smallest unit that can be addressed by LVM. The size of the PE is configurable and defaults to 4MB. *le (logicalextent) Logical volumes are also divided into addressable basic units called LE (logicalextents). In the same volume group, the size of Le is the same as the PE, and one by one corresponds. The first thing you can see is that the physical volume (PV) is made up of basic unit PE of equal size. A volume group consists of one or more physical volumes. As you can see, PE and Le have one by one corresponding relationships. The logical volume is built on the volume group. A logical volume is equivalent to a non-LVM system disk partition on which a file system can be created. and non-LVM systems The metadata that contains the partition information is saved in the partition table at the beginning of the partition, and the metadata related to the logical volume and volume group is also stored in the Vgda (Volume Group descriptor area) at the beginning of the physical volume. Vgda includes the following: PV descriptors, VG descriptors, LV descriptors, and some PE descriptors. When the system initiates LVM, the VG is activated and the Vgda is loaded into memory to identify the actual physical storage location of the LV. When the system does an I/O operation, the actual physical location is accessed based on the mapping mechanism established by VGDA. Iii. installation of LVM First determine if the LVM tool is installed in the system: [[email protected]] #rpm –QA|GREPLVM Lvm-1.0.3-4 If the command result input is similar to the example above, then the LVM management tool is already installed, and if the command does not have an output then the LVM management tool is not installed, you need to download it from the network or install the LVMRPM Toolkit from the CD. With the LVM RPM package installed, the kernel support LVM is also required to use LVM. Redhat The default kernel is LVM supported, if you need to recompile the kernel, you need to configure the kernel, enter the Multi-devicesupport (RAIDANDLVM) submenu, select the following two options: [*] Multipledevicesdriversupport (RAIDANDLVM) Logicalvolumemanager (LVM) support Then recompile the kernel to add support for LVM to the new kernel. In order to use LVM, to ensure that LVM is activated at system startup, fortunately in later versions of RedHat7.0, the system startup script already has support for active LVM, and in/etc/rc.d/rc.sysinit the following: #LVMinitialization If[-e/proc/lvm-a-x/sbin/vgchange-a-f/etc/lvmtab];then action$ "Settinguplogicalvolumemanagement:"/sbin/vgscan&&/sbin /vgchange-ayfi The key is two commands, the Vgscan command implements scanning all disks to get volume group information, and creates a file volume group data file/etc/lvmtab and/etc/lvmtab.d/*;vgchange-ay command to activate all volume groups of the system. Iv. Creating and Managing LVM To create an LVM system, you typically need to go through the following steps: 1. Create a partition Using the partitioning tool (such as FDISK, etc.) to create an LVM partition is the same way as creating other general partitions, except that the partition type of LVM is only 8e. 2. Create a physical volume The command to create the physical volume is pvcreate, which uses this command to create all partitions or disks that you want to add to the volume group as physical volumes. The command to create an entire disk as a physical volume is: #pvcreate/dev/hdb The command to create a single partition as a physical volume is: #pvcreate/dev/hda5 3. Create a volume group The command to create a volume group is vgcreate, and the physical volume established with Pvcreate is created as a complete volume group: #vgcreateweb_document/dev/hda5/dev/hdb The vgcreate command first parameter specifies the logical name of the volume group: web_document. The following parameter specifies all partitions and disks that you want to add to the volume group. Vgcreate in addition to creating volume group Web_document, a PE with a size of 4MB is also set (default is 4MB), which means that all logical volumes created on the volume group are expanded or scaled in 4MB increments. Due to kernel reasons, the PE size determines the maximum size of a logical volume, and a 4MB PE determines the maximum capacity of a single logical volume to 256GB, specifying a larger PE if you want to use a logical volume larger than 256G to create a volume group. The PE size range is 8KB to 512MB and must always be multiples of 2 (specified with-S, refer to Manvgcreate for details). 4. Activate Volume group In order to use the volume group immediately instead of restarting the system, you can use Vgchange to activate the volume group: #vgchange-ayweb_document 5. Add a new physical volume to the volume group When a new disk is installed and a new physical volume is created, and you want to add it to an existing volume group, you need to use the Vgextend command: #vgextendweb_document/DEV/HDC1 Here/DEV/HDC1 is the new physical volume. 6. Remove a physical volume from the volume group To remove a physical volume from a volume group, first verify that the physical volume to be deleted is not being used by any logical volume, use the Pvdisplay command to view the physical volume information: If a physical volume is being used by a logical volume, you need to back up the data for that physical volume elsewhere and then delete it. The command to delete the physical volume is vgreduce: #vgreduceweb_document/dev/hda1 7. Create a logical volume The command to create the logical volume is lvcreate: #lvcreate-l1500–nwww1web_document The command creates a logical volume named WWW1 with a size of 1500M on the volume group Web_document, and the device entry is/DEV/WEB_DOCUMENT/WWW1 (Web_document is the volume group name, and WWW1 is the logical volume name). If you want to create a logical volume that uses all volume groups, you need to first look at the number of PE for that volume group, and then specify when you create the logical volume: #vgdisplayweb_document |grep "Totalpe" TotalPE45230 #lvcreate-L45230WEB_DOCUMENT-NWWW1 8. Create File system I recommend using the ReiserFS file system to replace ext2 and ext3: Once you have created the file system, you can load and use it: #mkdir/data/wwwroot #mount/dev/web_document/www1/data/wwwroot If you want the file system to load automatically when the system starts, you also need to add content to the/etc/fstab: /dev/web_document/www1/data/wwwrootreiserfsdefaults12 9. Delete a logical volume Before deleting a logical volume, you first need to uninstall it and then delete it: #umount/DEV/WEB_DOCUMENT/WWW1 #lvremove/DEV/WEB_DOCUMENT/WWW1 Lvremove--doyoureallywanttoremove "/DEV/WEB_DOCUMENT/WWW1"? [Y/n]:y Lvremove--doingautomaticbackupofvolumegroup "Web_document" Lvremove--logicalvolume "/DEV/WEB_DOCUMENT/WWW1" successfullyremoved 10. Extending the logical volume size LVM provides the ability to easily resize logical volumes, and the command to extend the size of a logical volume is lvcreate: #lvextend-L12G/DEV/WEB_DOCUMENT/WWW1 Lvextend--extendinglogicalvolume "/DEV/WEB_DOCUMENT/WWW1" TO12GB Lvextend--doingautomaticbackupofvolumegroup "Web_document" Lvextend--logicalvolume "/DEV/WEB_DOCUMENT/WWW1" successfullyextended The above command is implemented to expand the size of the logical volume WWW1 to 12G. #lvextend-L+1G/DEV/WEB_DOCUMENT/WWW1 Lvextend--extendinglogicalvolume "/DEV/WEB_DOCUMENT/WWW1" TO13GB Lvextend--doingautomaticbackupofvolumegroup "Web_document" Lvextend--logicalvolume "/DEV/WEB_DOCUMENT/WWW1" successfullyextended The above command will increase the size of the logical volume WWW1 by 1G. After you increase the capacity of the logical volume, you need to modify the file system size to make use of the expanded space. I recommend using the ReiserFS file system instead of ext2 or ext3. So here's just a discussion of the reiserfs situation. The ReiserFS file tool provides a file system sizing tool: Resize_reiserfs. For the size of the file system that you want to adjust is loaded: #resize_reiserfs-F/DEV/WEB_DOCUMENT/WWW1 It is generally advisable to uninstall, resize, and then load the file system: #umount/DEV/WEB_DOCUMENT/WWW1 #resize_reiserfs/DEV/WEB_DOCUMENT/WWW1 #mount-treiserfs/dev/web_document/www1/data/wwwroot For users who use the ext2 or ext3 file system, you can consider using tools Ext2resize. [Url]http://sourceforge.net/projects/ext2resize[/url] 11. Reduce the logical volume size The capacity of the logical volume can be achieved with lvreduce, and the file system must be uninstalled first: #umount/data/wwwroot #resize_reiserfs-S-2G/DEV/WEB_DOCUMENT/WWW1 #lvreduce-L-2G/DEV/WEB_DOCUMENT/WWW1 #mount-treiserfs/dev/web_document/www1/data/wwwroot V. Summary As you can see from the above discussion, LVM is very scalable and easy to use. You can easily adjust the size of the volume group, the logical volume, and further adjust the size of the file system. |