Dynamically adjust linux partition size-lvm

Source: Internet
Author: User
Dynamic Adjustment of linux partition size & mdash; lvm Summary: LVM is short for LogicalVolumeManager (logical volume management). It is a mechanism for managing disk partitions in Linux. It is mainly used to help us solve the problem of partition expansion and resizing flexibly. This article describes how to dynamically adjust the linux partition size-lvm Summary: LVM is short for Logical Volume Manager (Logical Volume management, it is a mechanism for managing disk partitions in Linux. It is mainly used to help us solve the problem of partition expansion and resizing flexibly. This article describes the general principles, usage, and solutions of lvm. I. general principle lvm is the middle layer of disks and file systems. We use the middle layer to flexibly manage disk space. The logical layers from top to bottom are as follows: creating a file system on a logical volume is equivalent to creating a file system on a partition: A volume group can be divided into multiple logical volume groups: multiple physical volumes form a volume Group, which is equivalent to a disk with multiple partitions ----------------------------------------------------- ------------------------------- PV physical volume = is the logical partition of the disk or the entire disk region 2. to create an LVM system, follow these steps: 1. create a partition and use the partitioning tool (for example: fdisk, etc.) to create an LVM partition. the method is the same as that for creating other general partitions. The difference is that the LVM partition type is 8e. 2. run the "pvcreate" command to create a physical volume and create all partitions or disks to be added to the volume group as physical volumes. Run the following command to create the entire disk as a physical volume: # pvcreate/dev/hdb to create a single partition as a physical volume: # pvcreate/dev/hda53. run the vgcreate command to create a volume group. create a physical volume created using pvcreate as a complete volume group: # The first parameter of the vgcreate web_document/dev/hda5/dev/hdbvgcreate command is to specify 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. In addition to creating a volume group web_document, vgcreate also sets a PE with a size of 4 MB (4 MB by default ), this indicates that all logical volumes created on the volume group are expanded or reduced in 4 MB increments. Because of the kernel, the PE size determines the maximum size of the logical volume. the 4 mb pe determines that the maximum size of a single logical volume is 256 GB, if you want to use a logical volume larger than GB, specify a larger PE when creating the volume group. The PE size ranges from 8 kB to 512 MB, and must always be a multiple of 2 (use-s to specify. for details, see manvgcreate ). 4. to activate a volume group immediately, instead of restarting the system, you can use vgchange to activate the volume group: # vgchange-ay web_document5. add a new physical volume to the volume group. when the system installs a new disk and creates a new physical volume, to add it to an existing volume Group, run the vgextend command: # vgextend web_document/dev/hdc1. here/dev/hdc1 is the new physical volume. 6. to delete a physical volume from a volume group, you must first confirm that the physical volume to be deleted is not in use by any logical volume, you need to run the pvdisplay command to check the information of a physical volume. if a physical volume is being used by a logical volume, you need to back up the data of the physical volume to another place and then delete it. The command to delete a physical volume is vgreduce: # vgreduce web_document/dev/hda17, and the command to create a logical volume is lvcreate: # lvcreate-L1500-n www1 web_document this command creates a logical volume named www1 and the size is mb on the volume group web_document, 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 must first check the number of PES in the volume group, and then specify: # vgdisplay web_document | grep "TotalPE" TotalPE45230 # lvcreate-l45230 web_document-n www18. create a file system. I recommend using the reiserfs file system to replace ext2 and ext3: after the file system is created, you can load and use it: # mkdir/data/wwwroot # mount/dev/web_document/www1/data/wwwroot if you want the system to automatically load the file system at startup, you also need to add/dev/web_document/www1/data/wwwrootreiserfsdefaults129 to/etc/fstab. before deleting a logical volume, you must first uninstall it and then delete it: # umount/dev/web_docum Ent/www1 # lvremove/dev/web_document/www1lvremove -- doyoureallywanttoremove "/dev/web_document/www1 "? [Y/n]: ylvremove -- plugin "web_document" lvremove -- logicalvolume "/dev/web_document/www1" successfullyremoved10. expanding the logical volume size LVM allows you to easily adjust the logical volume size, the command to expand the logical volume size is lvextend: # lvextend-L12G/dev/web_document/www1lvextend -- examples "/dev/web_document/www1" to12GBlvextend -- examples "web_document" lvextend -- logicalvolume "/dev/web_document/www1" examples The command above ed expands the size of the logical volume www1 to 12 GB. # Lvextend-L + 1G/dev/web_document/www1lvextend -- plugin "/dev/web_document/www1" to13GBlvextend -- plugin "web_document" lvextend -- logicalvolume "/dev/web_document/www1" the command above successfullyextended increases the size of the logical volume www1 by 1 GB. After the capacity of the logical volume is increased, you need to modify the file system size to use the expanded space. We recommend that you use the reiserfs file system to replace ext2 or ext3. Therefore, only reiserfs is discussed here. The Reiserfs file tool provides the file system size adjustment tool: resize_reiserfs. To adjust the size of the file system to be loaded: # resize_reiserfs-f/dev/web_document/www1 it is recommended that you uninstall the file system, adjust the size, and then load the file: # umount/dev/web_document/www1 # resize_reiserfs/dev/web_document/www1 # mount-treiserfs/dev/web_document/www1/data/wwwroot can be used by users who use ext2 or ext3 file systems consider using the ext2resize tool. 11. to reduce the logical volume size, use lvreduce to achieve the logical volume capacity. you also need to first uninstall the file system: # 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 3. problem resolved disk partition expansion: generally, when a partition space is used up, we call in a blank partition, but then adjust the layout of the entire disk partition. this is very inconvenient, the partition size cannot be effectively adjusted. With lvm, we can directly unmount the logical volume and dynamically adjust the size of the logical volume (the above file will not be lost when it is adjusted (increased ), this allows you to dynamically adjust partitions.

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.