LVM for Linux file systems

Source: Internet
Author: User

LVM is the Logical Volume Manager Logical Volume management shorthand, the main function of the volume can be easily expanded and reduced dynamically, greatly improving the flexibility of disk management, the principle of the following points
1. The physical disk is formatted as a PV (physical Volume) physical volume, and the space is divided into a PE (physical Extend) Physical extension
2. Add PV to the VG (Volume Group) volume group and display it in PE form in VG
3.LV is based on PE, the size is an integer multiple of PE, the PE composed of LV may come from different physical disks, but all are the same VG in PE
4.LV now directly can be formatted after the Mount uses the
The 5.LV expansion reduction is actually increasing or decreasing the number of PE components that make up the LV, and the process does not lose the original data

Specific implementation

CENTOS7 does not have LVM tools by default and needs to be installed LVM2

yum install -y lvm2

Prepare 2 blocks of 8e format

   Device Boot      Start         End      Blocks   Id  System/dev/sdb9         8400896    10498047     1048576   8e  Linux LVM/dev/sdb10       10500096    14694399     2097152   8e  Linux LVM

1. Create PV

[[email protected] mnt]# pvcreate /dev/sdb9[[email protected] mnt]# pvcreate /dev/sdb10[[email protected] mnt]# pvs  PV         VG Fmt  Attr PSize PFree  /dev/sdb10    lvm2 ---  2.00g 2.00g  /dev/sdb9     lvm2 ---  1.00g 1.00g#详细查看    [[email protected] mnt]# pvdisplay

2. Create VG and expand

[[email protected] mnt]# vgcreate myvg /dev/sdb9[[email protected] mnt]# vgextend myvg /dev/sdb10[[email protected] mnt]# vgs  VG   #PV #LV #SN Attr   VSize VFree  myvg   2   0   0 wz--n- 2.99g 2.99g#详细查看[[email protected] mnt]# vgdisplay myvg

3. LV Creation

[[email protected] mnt]# lvcreate -L 1G -n mylv myvg#查看[[email protected] mnt]# lvs  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert  mylv myvg -wi-a----- 1.00g

4. Create file system and mount it

[[email protected] mnt]# mkfs.ext4 -L mylv /dev/myvg/mylv[[email protected] mnt]# mount /dev/myvg/mylv /mnt/t3[[email protected] mnt]# df -h|grep mapp/dev/mapper/myvg-mylv  976M  2.6M  907M    1% /mnt/t3

5, extension LV first to see the current LV group VG How much space

[[email protected] mnt]# lvs  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert  mylv myvg -wi-ao---- 1.00g[[email protected] mnt]# vgs myvg  VG   #PV #LV #SN Attr   VSize VFree  myvg   2   1   0 wz--n- 2.99g 1.99g[[email protected] mnt]# lvextend -L 2G /dev/myvg/mylv#扩展文件系统[[email protected] mnt]# resize2fs /dev/myvg/mylv#检查[[email protected] mnt]# df -h|grep mapp/dev/mapper/myvg-mylv  2.0G  3.0M  1.9G    1% /mnt/t3

6, reduce LV is to free up PE

[[email protected] mnt]# umount /dev/mapper/myvg-mylv[[email protected] mnt]# e2fsck -f /dev/mapper/myvg-mylv[[email protected] mnt]# resize2fs /dev/myvg/mylv 512M#这步之前必须确定1G是否能装下源文件[[email protected] mnt]# lvreduce -L 512M /dev/myvg/mylv

7. See if Vfree is larger than the partition to be removed below

[[email protected] mnt]# vgs  VG   #PV #LV #SN Attr   VSize VFree  myvg   2   1   0 wz--n- 2.99g 2.49g[[email protected] mnt]# pvs  PV         VG   Fmt  Attr PSize    PFree  /dev/sdb10 myvg lvm2 a--    <2.00g   <1.50g  /dev/sdb9  myvg lvm2 a--  1020.00m 1020.00m

8, first escape PE data, in the reduction of VG, the removal of PV

[[email protected] mnt]# pvmove /dev/sdb10  /dev/sdb10: Moved: 10.94%  /dev/sdb10: Moved: 100.00%[[email protected] mnt]# vgreduce myvg /dev/sdb10  Removed "/dev/sdb10" from volume group "myvg"[[email protected] mnt]# pvremove /dev/sdb10  Labels on physical volume "/dev/sdb10" successfully wiped.

9, if the VG also omitted here eliminates the removal of the LV operation [Lvremove MYVG/MYLV]

[[email protected] mnt]# vgremove myvgDo you really want to remove volume group "myvg" containing 1 logical volumes? [y/n]: yDo you really want to remove active logical volume myvg/mylv? [y/n]: y  Logical volume "mylv" successfully removed  Volume group "myvg" successfully removed[[email protected] mnt]# pvremove /dev/sdb9  Labels on physical volume "/dev/sdb9" successfully wiped.
Snapshot introduction

Principle: Snapshot is a backup of the source volume, is based on the implementation of the same LV volume.
Snapshot Volume Features:
1. Another access entry for the source volume
2. After a snapshot, the source file is copied to the snapshot volume when the existing file of the source volume changes
3. New files are not copied to the snapshot volume

Snapshot: Snapshot
Lvcreate-l #[mmggtt]-p r-s-N snapshot_lv_name original_lv_name
-L Size
-R Onlyread
-S Snapshot
Snapshot_lv_name Snapshot volume name
Original_lv_name Source Volume name

1. Create snapshot Snapshot volume source volumes are based on MYLV logical volumes

[[email protected] ~]# lvcreate -s -L 500m -n mylv-snap -p r /dev/myvg/mylv  Using default stripesize 64.00 KiB.  Logical volume "mylv-snap" created.

2. Mount a Snapshot

[[email protected] ~]# mount /dev/myvg/mylv-snap  /mnt/t2/mount: /dev/mapper/myvg-mylv--snap 写保护,将以只读方式挂载[[email protected] ~]# cp /etc/passwd /mnt/t3/   #源卷中文件,之后修改这个文件跟快对比

3. Edit the source volume file

[[email protected] t3]# echo 999999  >> passwd[[email protected] t3]# tail -1 passwd999999

3.1. View the snapshot volume

[[email protected] t2]# tail -1 passwdmarvin:x:1001:1001::/home/marvin:/bin/bash

4. Adding files to the source volume

[[email protected] t3]# cp /root/anaconda-ks.cfg  /mnt/t2/cp: 无法创建普通文件"/mnt/t2/anaconda-ks.cfg": 只读文件系统[[email protected] t3]# cp /root/anaconda-ks.cfg  /mnt/t3

4.1. Viewing the snapshot volume does not

[[email protected] t2]# lsissue  lost+found  passwd

5. Deleting a snapshot volume

[[email protected] mnt]# umount /mnt/t2[[email protected] mnt]# lvremove /dev/myvg/mylv-snapDo you really want to remove active logical volume myvg/mylv-snap? [y/n]: y  Logical volume "mylv-snap" successfully removed

LVM for Linux file systems

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.