Linux commands: RESIZE2FS, LVM Logical Volume LV expansion and reduction

Source: Internet
Author: User

RESIZE2FS: Adjust the size of the Ext file system

With logical volume LV usage: Resize2fs/path/to/lv_name 3G adjusts the logical boundary size of the LV to 3G


I. Extending the logical Volume LV:(the physical boundary of the logical volume must be extended before the logical boundary is extended)

lvextend physical boundaries of an extended logical volume

-L [+]#/path/to/lv_name specifies the expanded capacity, + indicates a direct increase of # capacity on the current capacity

No + indicates that the expanded capacity is #

Usag:lvextend-l +5g/path/to/lv_name means that the LV increases again the 5G capacity on the existing capacity

Lvextend-l 5G /path/to/lv_name indicates an extended LV total size of 5G capacity

resize2fs logical boundaries of an extended logical volume

resize2fs/path/to/lv 5G extends logical boundary to 5G, the value cannot exceed the physical boundary

Resize2fs-p/path/to/lv:-P indicates that the extended logical boundary is as large as the physical boundary.

second, reduce the logical volume LV: (the logical boundary of the logical volume must be reduced before the physical boundary is reduced)

Note: 1, can not be reduced online, you have to uninstall first;

2, to ensure that the size of the reduced space can still store all the original data;

3, before the reduction should be forced to check the file to ensure that the file system is in a consistent state.

Reduction steps:

1. First look at the LV size that has been used to ensure that the reduced capacity size can accommodate the existing data.

DF-LH View capacity Size

[Email protected] ~]# DF-LH

Filesystem Size used Avail use% mounted on

/dev/sda2 4.9G 1.5G 3.1G 33%/

Tmpfs 947M 0 947M 0%/dev/shm

/DEV/SDA1 2.0G 61M 1.8G 4%/boot

/dev/sda3 3.9G 73M 3.6G 2%/Home

/dev/sda7 2.0G 35M 1.8G 2%/tmp

/dev/sda5 2.9G 1.7G 1.2G 59%/usr

/DEV/MAPPER/MYVG-TESTLV 3.0G 4.5M 2.8G 1%/mnt This option means that the LV is currently using only 4.5M

2, must first unload the mount, cannot reduce online.

Umount/mnt unloading mounted LV

[[email protected] ~]# umount/mnt unmount the mounted LV

[[email protected] ~]# mount to see if the mounted LV was uninstalled successfully

/dev/sda2 on/type ext4 (rw)

Proc On/proc type proc (rw)

Sysfs On/sys type SYSFS (rw)

Devpts on/dev/pts type devpts (rw,gid=5,mode=620)

Tmpfs on/dev/shm type Tmpfs (rw,rootcontext= "System_u:object_r:tmpfs_t:s0")

/DEV/SDA1 on/boot type EXT4 (rw)

/dev/sda3 on/home type EXT4 (rw)

/DEV/SDA7 on/tmp type EXT4 (rw)

/dev/sda5 on/usr type EXT4 (rw)

None On/proc/sys/fs/binfmt_misc type Binfmt_misc (rw)

3, force the implementation of the LV file system detection

E2fsck-f/DEV/MYVG/TESTLV File system detection for LV enforcement

[[email protected] ~]# e2fsck-f/DEV/MYVG/TESTLV enforce file system detection for LV

E2fsck 1.41.12 (17-may-2010)

First step: Check Inode, block, and size

Step Two: Check the directory structure

3rd Step: Check the directory connectivity

Pass 4:checking Reference counts

5th Step: Check Cluster summary information

/dev/myvg/testlv:11/196608 files (0.0% non-contiguous), 13500/786432 blocks

4. Use RESIZE2FS to resize the logical boundary space size of the LV logical volume to a reduced size

RESIZE2FS/DEV/MYVG/TESTLV 2G logical boundary space for LV logical volumes is resized to 2G

[[email protected] ~]# RESIZE2FS/DEV/MYVG/TESTLV 2G Adjust Logical volume logical boundary size to 2G

RESIZE2FS 1.41.12 (17-may-2010)

Resizing the filesystem ON/DEV/MYVG/TESTLV to 524288 (4k) blocks.

The filesystem ON/DEV/MYVG/TESTLV is now 524288 blocks long.

5. Use Lvreduce to reduce the physical boundaries of the LV logical volume

Lvreduce-l 2G/DEV/MYVG/TESTLV reduction of physical boundary of logical volume to 2G

[[email protected] ~]# lvreduce-l 2G/DEV/MYVG/TESTLV The physical boundary of the logical volume is reduced to 2G

Warning:reducing Active Logical Volume to 2.00 GiB

This May DESTROY YOUR DATA (filesystem etc)

Does really want to reduce TESTLV? [y/n]: Y

Reducing logical volume TESTLV to 2.00 GiB

Logical Volume TESTLV successfully resized

6, then continue to mount the LV operation

MOUNT/DEV/MYVG/LV/MNT Mount LV Logical Volume

[[email protected] ~]# mount/dev/myvg/testlv/mnt mount LV Logical Volume

[[email protected] ~]# DF-LH View the partition information already mounted

Filesystem Size used Avail use% mounted on

/dev/sda2 4.9G 1.5G 3.1G 33%/

Tmpfs 947M 0 947M 0%/dev/shm

/DEV/SDA1 2.0G 61M 1.8G 4%/boot

/dev/sda3 3.9G 73M 3.6G 2%/Home

/dev/sda7 2.0G 35M 1.8G 2%/tmp

/dev/sda5 2.9G 1.7G 1.2G 59%/usr

/DEV/MAPPER/MYVG-TESTLV 2.0G 4.5M 1.9G 1%/mnt here LV Logical volume reduced to 2G


Third, snapshot volume

1, the life cycle is the entire data length, during this time, the amount of data growth can not exceed the size of the snapshot volume (that is, the size specified by the creation of the snapshot volume-L);

2, the snapshot volume should be read-only;

3. The snapshot volume must be in the same volume group as the original volume;

Lvcreate

-S: Snapshot snapshot of snapshot volume creation

-P R|W: Specifies that the snapshot volume permission R is read-only W Write

Format: Lvcreate-l #-N slv_name-s-P R/DEV/MYVG/TESTLV

Usage:lvcreate-l 1g-n testlv-snap-s-P R/DEV/MYVG/TESTLV

Create a 1G read-only snapshot volume for the/DEV/MYVG/TESTLV logical volume with the name Testlv-snap

[[email protected] ~]# lvcreate-l 1g-n testlv-snap-s-P R/DEV/MYVG/TESTLV

Logical volume "Testlv-snap" created

Mount the snap device

[Email protected] ~]# Mount/dev/myvg/testlv-snap/user

Mount:block Device/dev/mapper/myvg-testlv--snap is write-protected, mounting read-only

You can then back up the files in the snap mount directory, and if you encounter a deletion, you will be able to recover directly from snap.








This article is from the "Learn Linux history" blog, please be sure to keep this source http://woyaoxuelinux.blog.51cto.com/5663865/1870299

Linux commands: RESIZE2FS, LVM Logical Volume LV expansion and reduction

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.