Linux LVM Tools (VG And LV)

Source: Internet
Author: User
Keywords linux linux lvm linux lvm commands
First, install LVM
  First determine whether the lvm tool is installed in the system:
  [root@www root]# rpm –qa|grep lvm
  lvm-1.0.3-4
  If the command result input is similar to the above example, it means that the system has installed the LVM management tool; if the command does not output, it means that the LVM management tool is not installed, and you need to download it from the network or install the LVM rpm toolkit from the CD.


Second, create and manage LVM
 To create an LVM system, generally need to go through the following steps:
 1. Create a partition
  Use partition tools (such as: fdisk, etc.) to create LVM partitions. The method is the same as that of other general partitions. The only difference is that the partition type of LVM is 8e.
 2. Create a physical volume
  The command to create a physical volume is pvcreate. Use this command to create all partitions or disks that you want to add to the volume group as physical volumes. The command to create the 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. The physical volume created by pvcreate is created as a complete volume group:
      # vgcreate web_document /dev/hda5 /dev/hdb
The first parameter of the vgcreate command is to specify the logical name of the volume group: web_document. The following parameters are to specify all partitions and disks that you want to add to the volume group. In addition to creating the volume group web_document, vgcreate also sets the use of a PE with a size of 4 MB (the default is 4 MB), which means that all logical volumes created on the volume group are expanded or reduced in increments of 4 MB. Due to the kernel, the PE size determines the maximum size of the logical volume. A PE of 4 MB determines the maximum capacity of a single logical volume to 256GB. If you want to use a logical volume larger than 256G, specify a larger PE when creating a volume group. The PE size ranges from 8 KB to 512 MB, and must always be a multiple of 2 (specified with -s, please refer to man vgcreate for details).
 4. Activate the 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 -a y web_document
 5. Add a new physical volume to the volume group
  When the system installs a new disk and creates a new physical volume, and to add it to an existing volume group, you need to use the vgextend command:
      # vgextend web_document /dev/hdc1
  Here /dev/hdc1 is the new physical volume.
 6. Delete a physical volume from the volume group
  To delete a physical volume from a volume group, first confirm that the physical volume to be deleted is not in use by any logical volume, and use the pvdisplay command to view the information of the physical volume:
  If a physical volume is being used by a logical volume, the data of the physical volume needs to be backed up to other places and then deleted. The command to delete a physical volume is vgreduce:
      # vgreduce web_document /dev/hda1
 7, create a logical volume
  The command to create a logical volume is lvcreate:
 # lvcreate -L1500 –nwww1 web_document
This command creates a logical volume named www1 and 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, www1 is the logical volume name). If you want to create a logical volume that uses all volume groups, you need to check the number of PEs in the volume group first, and then specify when creating the logical volume:
 # vgdisplay web_document| grep “Total PE”
 Total PE 45230
 # lvcreate -l 45230 web_document -n www1
 8. Create a file system
Recommend to use reiserfs file system instead of ext2 and ext3
After creating 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 be automatically loaded when the system starts, you also need to add content in /etc/fstab:
 /dev/web_document/www1 /data/wwwroot reiserfs defaults 1 2
9, delete a logical volume
 Before deleting a logical volume, you need to unmount it first, and then delete it:
 # umount /dev/web_document/www1
 # lvremove /dev/web_document/www1
 lvremove—do you really want to remove “/dev/web_document/www1”? [y/n]: y
 lvremove—doing automatic backup of volume group “web_document”
 lvremove—logical volume “/dev/web_document/www1” successfully removed
 10. Expand the logical volume size
 LVM provides the ability to easily adjust the size of the logical volume. The command to extend the size of the logical volume is lvextend, and lvresize can also be used to modify the LV size:
 # lvextend -L12G/dev/web_document/www1
 lvextend—extending logical volume “/dev/web_document/www1” to 12 GB
 lvextend—doing automatic backup of volume group “web_document”
 lvextend—logical volume “/dev/web_document/www1” successfully extended
 The above command will expand the size of the logical volume www1 to 12G.
 # lvextend -L+1G/dev/web_document/www1
 lvextend—extending logical volume “/dev/web_document/www1” to 13 GB
 lvextend—doing automatic backup of volume group “web_document”
 lvextend—logical volume “/dev/web_document/www1” successfully extended
 The above command will increase the size of the logical volume www1 by 1G.
 After increasing the capacity of the logical volume, you need to modify the file system size to realize the use of the expanded space. I recommend using reiserfs file system instead of ext2 or ext3. Therefore, only the case of reiserfs is discussed here. The Reiserfs file tool provides a file system size adjustment tool: resize_reiserfs. For the file system you want to adjust to be loaded:
  # resize_reiserfs -f /dev/web_document/www1
  It is generally recommended that the file system be unloaded, resized, and then loaded:
 # umount /dev/web_document/www1
 # resize_reiserfs /dev/web_document/www1
 # mount -treiserfs /dev/web_document/www1 /data/wwwroot
 For users who use ext2 or ext3 file systems, consider using tools
Extension of ext2/ext3 file system: resize2fs -p /dev/mapper/VolGroup01-ora11(LV)
   ext2resize.
http://sourceforge.net/projects/ext2resize
The e2fsck command checks whether the file system has errors. Need umount file system
 11. Reduce the size of the logical volume
 The capacity of the logical volume can be realized by using lvreduce, and lvresize can also be used to modify the LV size, and the file system needs to be unmounted 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

 Third, summary
  As can be seen from the above discussion, LVM has good scalability and is very convenient to use. You can easily adjust the size of volume groups and logical volumes, and further adjust the size of the file system. If you want more information, please refer to LVM-HOWTO.
Related Article

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.