LVM (Logical Volume Manager) Logical Volume management

Source: Internet
Author: User
Tags disk usage

01 Creating a Partition
02 Identify this partition as PV (physical volume)
03 Adding a physical volume to a VG (volume group)
04 Dividing the LV (logical volume) from the volume group
05 File system for LV
06 Mounting Use
==========
Create a whole process of LV
#fdisk/dev/sdb
--->/DEV/SDB3----> 5G//Partitioning a 5G partition
#pvcreate/DEV/SDB5//convert SDB5 to PV
#pvs or #pvdisplay//view PV information
#vgcreate VG0/DEV/SDB5//Create a volume group vg0 and add SDB5 to this volume group
#vgs or #vgdisplay//view Volume group information
#lvcreate-L 1g-n lv01 vg0//Create a 1G-size logical volume from the VG0 volume group
#lvs or #lvdisplay//view information for a logical volume
#mkfs. ext4/dev/vg0/lv01
#mkdir/MNT/LV01
#mount/DEV/VG0/LV01/MNT/LV01
#vi/etc/fstab
==================
Stretch a logical volume
#vgs//View the remaining space of the volume group where the logical volume resides
#lvextend-L +1G/DEV/VG0/LV01//increases the size of 1G
Or
#lvextend-L 2G/DEV/VG0/LV01//increase to 2G space
#lvs//View Logical Volume Information
#df-H//View mount status (partition size)
This time did not see the file system become larger,
We need to stretch the file system.
#resize2fs/DEV/VG0/LV01//Stretched file system
#df-H
==================
If there is not enough space in the volume group,
then expand volume Group space
Need to add a new physical volume
#fdisk/DEV/SDC
---->/DEV/SDC3 5G
#pvcrate/DEV/SDC5//Turn SDC5 into PV
#vgextend VG0/DEV/SDC5//stretched volume group space, adding new physical volumes
#vgs//See if the volume group's space size changes
---command---

Pvcreate,pvdisplay,pvs
Vgcreate,vgdisplay,vgs,vgextend
Lvcreate,lvdisplay,lvs,lvextend
Resize2fs
--------------


LV Retraction process **************** offline
01 Uninstalling a Logical Volume
E2fsck
03 Retraction file System size *******
04 Retraction Partition Size
05 Mounting use

---stretching---
# VGS
# LVS
# lvextend-l +500m/dev/vg1/lv11
# resize2fs/dev/vg1/lv11
# df-h
# LVS

---retraction---
# echo lv11 >/mnt/lv11/testfile
# Cat/mnt/lv11/testfile
# umount/dev/vg1/lv11
# df-h
# resize2fs/dev/vg1/lv11 500M
# e2fsck-f/DEV/VG1/LV11//Check disk usage
# resize2fs/dev/vg1/lv11 500M//Retraction file system
# lvreduce-l 500M/DEV/VG1/LV11//retraction to partition
# mount/dev/vg1/lv11/mnt/lv11/
# df-h
# echo 3 >/proc/sys/vm/drop_caches//Empty cache
# Cat/mnt/lv11/testfile

= = = Snapshot = =
Snapshots are images that are based on a logical volume
To set the size when you create a snapshot,
Once you use a snapshot that exceeds the snapshot size,
Then this snapshot is corrupted.

While using snapshots, it is best not to use the source device
Because when the contents of the snapshot and the source device change,
The snapshot size will change.
If the source device also changes, then the snapshot will also change
(only space is changed, not file content)

Snapshot corruption When snapshot usage is at 100%

#lvs
#lvcreate-L 100m-n slv11-s/dev/vg1/lv11
#lvremove/dev/vg1/slv11

Snapshots can not span a volume group
======================
Deletion of logical volumes
Lvremove Deleting a logical volume
Vgremove Deleting a volume group
Pvremove Deleting physical volumes


01 Uninstalling a Logical Volume
#umount/dev/vg0/data

02 Deleting a logical Volume
#lvs
#lvremove/dev/vg0/data

03 Deleting a volume group
#vgs
#vgremove/dev/vg0

04 Deleting a physical volume
#pvs
#pvremove/dev/sda5/dev/sda6

05 Checksum
#pvs
#vgs
#lvs

=============================

01 Installing the Web service httpd
#yum Install Httpd-y
02 Starting the Web service
#service httpd Start
03 Writing a Web test page index.html
#vi/var/www/html/index.html
04 Dividing a 2G physical volume
#fdisk/DEV/SDA
----->/dev/sda7 (2G)
#partx-A/DEV/SDA
#pvcreate/DEV/SDA7
#pvs

05 Add to VG00 Volume group
#vgcreate VG00/DEV/SDA7
#vgs

06 Create a logical volume called httpd, size 1G
#lvcreate-L 1g-n httpd vg00
#lvs

07 Mount this logical volume to the default home directory of the Web service
(/var/www/html)
And make sure you still see the contents of the test page.
#mkfs. ext4/dev/vg00/httpd
#mkdir/mnt/tmp
#mount/dev/vg00/httpd/mnt/tmp
#cp/var/www/html/index.html/mnt/tmp
#umount/mnt/tmp
#mount/dev/vg00/httpd/var/www/html

08 Stretch This logical volume to 4G
#vgs
#fdisk/DEV/SDA
--->/dev/sda8 (5G)
#partx-A/DEV/SDA
#pvcreate/dev/sda8
#vgextend vg00/dev/sda8
#vgs
#lvextend-L 4G/DEV/VG00/HTTPD
#resize2fs/dev/vg00/httpd
#df-H

09 Shrink This logical volume back to 3G
#umount/dev/vg00/httpd
#e2fsck-F/DEV/VG00/HTTPD
#resize2fs/dev/vg00/httpd 3G
#lvreduce-L 3G/DEV/VG00/HTTPD
#mount/dev/vg00/httpd/var/www/html
#df-H

10 based on the current LV state, make a snapshot of size 500M
#umount/dev/vg00/httpd
#lvs
#lvcreate-L 500m-n httpd-snap-s/dev/vg00/httpd
#lvs

11 Unload a logical volume, mount the snapshot as read-only to the Web default home directory
---------------------------------
#mount-O ro/dev/vg00/httpd-snap/var/www/html
#echo Hello >/var/www/html/testfile (Cannot write)

Refresh page can still see Web test page

LVM (Logical Volume Manager) Logical Volume management

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.