Linux practice engineer study Note 8: Lvm Logical Volume Manager

Source: Internet
Author: User
Linux practice engineer study Note 8: Lvm Logical Volume Manager if the system is using sdb, restart the system to re-read the partition table information of sdb

Physical volume of PV (physical volume)
VG (Volume Group) Volume Group
LV (Logical Volume) Logical Volume
 
1. fdisk/dev/sdb
Partition sdb1, sdb2, sdb3
Partition type 8e (Linux LVM)
If the system is using sdb, restart the system to re-read the partition table information of the sdb.
2. # pvcreate/dev/sdb [1-3] initialize the physical volume
3. # vgscan scans physical volumes and creates a volume group Database. you must run this command to create an lvm for the first time.
4. # vgcreate vg0/dev/sdb1/dev/sdb2 use sdb1 and sdb2 to create a volume group vg0
# Vgdisplay vg0
5. # lvcreate-n data-L 10 M vg0 create a new logical volume named data with a size of 10 M from vg0
6. # format mkfs. ext3/dev/vg0/data
7. # mount/dev/vg0/data/mnt
# Lvdisplay/dev/vg0/data View partition of logical volume data
# Lvcreate-n test-l 5 vg0: Use-l to specify the number of logical volumes. the default block size is 4 MB, that is, 20 MB is allocated to logical volumes, the default physical expansion block SIZE can be determined by running the command vgdispaly vg0 to view the pe size value.
You must format mkfs. ext3 before using the created logical volume.
# Lvscan scan logical volumes to view their activity

# Umount/mnt
# Lvextend-L + 20 M/dev/vg0/data to expand the logical volume by 20 M, umount partition before expanding
# E2fsck-f/dev/vg0/data forcibly check the data logical volume
# Resize2fs/dev/vg0/data redefinition of partition size
The preceding three steps must be performed in sequence. the following command can achieve the same effect as the preceding three commands:
# E2fsadm-L + 20 M/dev/vg0/data
 
# View the current physical volume of the system using pvscan
# Vgextend vg0/dev/sdb3 expand the volume group vg0 and add the partition sdb3 to the volume Group
# Pvmove/dev/sdb1 remove a physical volume
# Vgreduce vg0/dev/sdb1 delete sdb1 from the volume Group
Pvmove removes data, but sdb1 is still in vg0 and belongs to the volume group area. vgreduce deletes sdb1 from vg0.
When creating a volume group, the default PE size is 4 MB, and the maximum LV size is 256 GB.
# Vgcreate-s 8 M vg1/dev/sdb1
-S specifies the PE block size
You can change the maximum logical volume capacity allowed by the volume group by changing the PE block size.

Tips:
# Clear screen
# Df-lh shows the current partition mounting status of the system
 
Create Snapshot (back up data)
# Lvcreate-s-L 52 M-n snap/dev/vg0/data
-S indicates a snapshot.
-L the snapshot size must be greater than or equal to the logical volume data
-N snapshot name
Snapshots can be used without formatting
 
Procedure for deleting a logical volume
1. umount all LV
2. lvremove/dev/vg0/data (viewed through lvscan) if there is a snapshot, remove the snapshot before removing the logical volume.
3. # vgchange-an/dev/vg0 sleep vg for deletion. vgchange-ay/dev/vg0 can activate vg.
4. # vgremove vg0
If any errors occur during use, you can view the system logs.
# Tail/var/log/message

To use the LVM device in the root partition, you must first create an LVM device, use the lvmcreate-initrd command to create a virtual disk image file that supports the lvm function in the boot partition, and modify grub. the conf file can be loaded.

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.