LVM logical volume resizing

Source: Internet
Author: User

LVM logical volume resizing

[1] creating logical volumes
[Root @ hyperStor ~] # Vgs // view the current volume group
VG # PV # LV # SN Attr VSize VFree
Vg0 2 2 0 wz -- n-698.38g 98.29g
[Root @ hyperStor ~] # Lvcreate-L 2 GB-n lv1 vg0 // create a 2 GB logical volume lv1 on the vg0 of the volume group
Logical volume "lv1" created
[Root @ hyperStor ~] # Lvs | grep lv1
Lv1 vg0-wi-a-2.00g
[Root @ hyperStor ~] # Mkfs. ext4/dev/vg0/lv1>/dev/null 2> & 1 // format lv1
[Root @ hyperStor ~] # Mkdir/lv1
[Root @ hyperStor ~] # Mount/dev/vg0/lv1/lv1 // mount lv1 to the/lv1 directory
[Root @ hyperStor ~] # Df-H | grep lv1 // view the Mount status
/Dev/mapper/vg0-lv12.2G 71 M 2.0G 4%/lv1
[Root @ hyperStor ~] # Mount | grep lv1
/Dev/mapper/vg0-lv1on/lv1typeext4 (rw)
[Root @ hyperStor ~] # Dd if =/dev/zero of =/lv1/test1 bs = 100 M count = 5 // you can write M data to lv1
5 + 0 records in
5 + 0 records out
524288000 bytes (524 MB) copied, 1.92862 s, 272 MB/s
[Root @ hyperStor ~] # Du-sh/lv1/* // view the File status
16 K/lv1/lost + found
500 M/lv1/test1

[2] lvextend command resizing lv1 to 3 GB
// Expand lv1 to 3 GB. If it is from 2 GB to 5 GB, It is lvextend-L + 3 GB.
[Root @ hyperStor ~] # Lvextend-L 3 GB-n/dev/vg0/lv1
Extending logical volume lv1 to 3.00 GiB
Logical volume lv1 successfully resized
[Root @ hyperStor ~] # Lvs | grep lv1 // check the current logical volume size, which is 3 GB
Lv1 vg0-wi-ao 3.00g
[Root @ hyperStor ~] # Df-H | grep lv1 // check the file system status and find that the file system has not been resized.
/Dev/mapper/vg0-lv1 2.2G 595 M 1.5G 30%/lv1
[Root @ hyperStor ~] # Resize2fs/dev/vg0/lv1 // adjust the file system size
Resize2fs 1.41.12 (17-May-2010)
Filesystem at/dev/vg0/lv1 is mounted on/lv1; on-line resizing required
Old desc_blocks = 1, new_desc_blocks = 1
Ming an on-line resize of/dev/vg0/lv1 to 786432 (4 k) blocks.
The filesystem on/dev/vg0/lv1 is now 786432 blocks long.
[Root @ hyperStor ~] # Df-H | grep lv1 // re-view the file system size. The file system is successfully resized to 3 GB online.
/Dev/mapper/vg0-lv1 3.2G 595 M 2.5G 20%/lv1
[Root @ hyperStor ~] # Lvs | grep lv1
Lv1 vg0-wi-ao 3.00g
[Root @ hyperStor ~] # Du-sh/lv1/* // check whether the data is complete
16 K/lv1/lost + found
501 M/lv1/test1

[3] lvreduce scale-down, cannot be "online" lv1: 3 GB --> 1 GB
[Root @ hyperStor ~] # Umount/lv1 // uninstall the File System
[Root @ hyperStor ~] # Mount | grep lv1 | wc-l // check whether unmount is successful
0
[Root @ hyperStor ~] # Lvs | grep lv1 // view the current lv1 status
Lv1 vg0-wi-a-3.00g
[Root @ hyperStor ~] # E2fsck-f/dev/vg0/lv1 // check the disk
E2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/Dev/vg0/lv1: 12/196608 files (0.0% non-contiguous), 157501/786432 blocks
[Root @ hyperStor ~] # Resize2fs/dev/vg0/lv1 1G // adjust the File System
Resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on/dev/vg0/lv1 to 262144 (4 k) blocks.
The filesystem on/dev/vg0/lv1 is now 262144 blocks long.
[Root @ hyperStor ~] # Lvs | grep lv1 // check the lv1 size, not changed
Lv1 vg0-wi-a-3.00g
[Root @ hyperStor ~] # Lvreduce-L 1 GB/dev/vg0/lv1 // use the lvduce command to scale down
WARNING: switching active logical volume to 1.00 GiB
This may destroy your data (filesystem etc .)
Do you really want to reduce lv1? [Y/n]: y
Cing logical volume lv1 to 1.00 GiB
Logical volume lv1 successfully resized
[Root @ hyperStor ~] # Lvs | grep lv1 // check the lv1 size again to reduce
Lv1 vg0-wi-a-1.00g
[Root @ hyperStor ~] # Mount/dev/vg0/lv1/lv1 // re-mount
[Root @ hyperStor ~] # Df-H | grep lv1 // view the current status
/Dev/mapper/vg0-lv1 1.1G 595 M 410 M 60%/lv1
[Root @ hyperStor ~] # Du-sh/lv1/* // View data
16 K/lv1/lost + found
501 M/lv1/test1

Note: During expansion and contraction, when performing integrity verification on the original file, it is best to compare the md5 value of the file to determine whether the operation has no impact on the original file.
For example:
[1] expansion: the md5 values of Two/lv1/test1 are d8b61b2c0025919d5321461045c8226f
[Root @ hyperStor ~] # Md5sum/lv1/test1
D8b61b2c0025919d5321461045c8226f/lv1/test1
[Root @ hyperStor ~] # Lvextend-L 2 GB/dev/vg0/lv1
Extending logical volume lv1 to 2.00 GiB
Logical volume lv1 successfully resized
R [root @ hyperStor ~] # Resize2fs/dev/vg0/lv1
Resize2fs 1.41.12 (17-May-2010)
Filesystem at/dev/vg0/lv1 is mounted on/lv1; on-line resizing required
Old desc_blocks = 1, new_desc_blocks = 1
Ming an on-line resize of/dev/vg0/lv1 to 524288 (4 k) blocks.
The filesystem on/dev/vg0/lv1 is now 524288 blocks long.
[Root @ hyperStor ~] # Df-H | grep lv1
/Dev/mapper/vg0-lv1 2.2G 595 M 1.5G 30%/lv1
[Root @ hyperStor ~] # Md5sum/lv1/test1
D8b61b2c0025919d5321461045c8226f/lv1/test1

[2] scale down
[Root @ hyperStor ~] # Md5sum/lv1/test1
D8b61b2c0025919d5321461045c8226f/lv1/test1
[Root @ hyperStor ~] # Umount/lv1/
[Root @ hyperStor ~] # E2fsck-f/dev/vg0/lv1
E2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/Dev/vg0/lv1: 12/131072 files (0.0% non-contiguous), 153389/524288 blocks
[Root @ hyperStor ~] # Resize2fs/dev/vg0/lv1 800 M
Resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on/dev/vg0/lv1 to 204800 (4 k) blocks.
The filesystem on/dev/vg0/lv1 is now 204800 blocks long.
[Root @ hyperStor ~] # Lvreduce-L 800 M/dev/vg0/lv1
WARNING: Rolling cing active logical volume to 800.00 MiB
This may destroy your data (filesystem etc .)
Do you really want to reduce lv1? [Y/n]: y
Indexing cing logical volume lv1 to 800.00 MiB
Logical volume lv1 successfully resized
[Root @ hyperStor ~] # Mount/dev/vg0/lv1/lv1
[Root @ hyperStor ~] # Md5sum/lv1/test1
D8b61b2c0025919d5321461045c8226f/lv1/test1

Expansion: "Resizing" for the LVM volume group"
The above section describes how to scale up or down the logical volume of the LVM. We all know that the volume group is composed of physical volumes, the physical volume is the smallest unit of the volume group. the resizing and contraction of the volume group is nothing more than the process of adding the physical volume to the volume group and removing the volume group.
Vgextend vg0 new_pv // Add a new pv device to vg0
Vgreduce vg0 old_pv // Delete pv from vg0. Note: vgreduce is not vgremove

Mysqldump and LVM logical volume Snapshot

Comprehensive Introduction and implementation of LVM

MySQL high-performance backup solution for uninterrupted Data Access (LVM Snapshot Backup)

Implement ASM on LVM

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.