Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to reduce / reduce the size of LVM in Linux

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to reduce / reduce the size of LVM in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Reducing / shrinking logical volumes is the highest risk of data corruption.

So, if possible, try to avoid this situation, but if there is no other choice, then continue.

Before reducing LVM, it is recommended to make a backup.

When you run out of disk space in LVM, you can free up some free space on the volume group by narrowing the existing LVM that does not use all the space, rather than adding a new physical disk.

It is important to note that shrinking is not supported on GFS2 or XFS file systems.

If you are new to logical Volume Management (LVM), I suggest you start with our previous article.

Part 1: how to create / configure LVM in Linux (logical volume management)

Part 2: how to extend / add LVM in Linux (logical volume adjustment)

Reducing logical volumes involves the following steps:

Unmount the file system

Check the file system for any errors

Reduce the size of the file system

Reduce the size of a logical volume

Recheck the file system for errors (optional)

Mount the file system

Check the reduced file system size

For example, you have a 100GB LVM that doesn't use all the space, and you want to reduce it to 80GB so that 20GB can be used for other purposes.

# df-h / testlvm1 Filesystem Size Used Avail Use% Mounted on/dev/mapper/vg01-lv002 100G 15G 85G 12% / testlvm1 unmount the file system

Use the umount command to unmount the file system:

# umount / testlvm1 checks the file system for any errors

Use the e2fsck command to check the file system for errors:

# e2fsck-f / dev/mapper/vg01-lv002 e2fsck 1.42.9 (28-Dec-2013) Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/mapper/vg01-lv002: 13Checking reference countsPass 6553600 files (0.0% non-contiguous), 12231854 and sizesPass 26212352 blocks shrink the file system

The following command will shrink the testlvm1 file system from 100GB to 80GB.

Common syntax for file system resizing (resize2fs):

Resize2fs [existing logical volume name] [new file system size]

The actual command is as follows:

# resize2fs / dev/mapper/vg01-lv002 80g resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on / dev/mapper/vg01-lv002 to 28321400 (4k) blocks.The filesystem on / dev/mapper/vg01-lv002 is now 28321400 blocks long. Reduce logical volume (LVM) capacity

Now reduce the size of the logical volume (LVM) using the lvreduce command. / dev/mapper/vg01-lv002 shrinks the logical volume (LVM) from 100GB to 80GB with the following command.

Common syntax for LVM reduction (lvreduce):

Lvreduce [new LVM size] [existing logical volume name]

The actual command is as follows:

# lvreduce-L 80g / dev/mapper/vg01-lv002 WARNING: Reducing active logical volume to 80.00 GiBTHIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv002? [Yzone]: yReducing logical volume lv002 to 80.00 GiBLogical volume lv002 successfully resized optional: check the file system for errors

After reducing the LVM, check the file system again for errors:

# e2fsck-f / dev/mapper/vg01-lv002 e2fsck 1.42.9 (28-Dec-2013) Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/mapper/vg01-lv002: 13Mab 4853600 files (0.0% non-contiguous), 1023185Checking reference countsPass 2021235 blocks mount the file system and check the reduced size

Finally, mount the file system and check the reduced file system size.

Mount the logical volume using the mount command:

# mount / testlvm1

Use the df command to check the mounted volumes.

# df-h / testlvm1 Filesystem Size Used Avail Use% Mounted on/dev/mapper/vg01-lv002 80g 15g 65g 18% / testlvm1 Thank you for reading! This is the end of the article on "how to reduce / reduce the size of LVM in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report