СHRISTMAS
WHEEL OF FORTUNE

Tap the button and win a guaranteed prize right now!

By registering, you are signing up to receiving e-mails.
JT
October 22 2024
Updated October 22 2024

Increase and decrease LVM disc space

Linux Maintenance

Working with disc space is one of the key skills in OS administration. It often happens that the size of a disc partition may be insufficient for services, in such cases it is expanded by reducing the size of others. The LVM tool allows dynamic resizing without rebooting the device.

How to quickly reduce partition size?

If you don't have sufficient resources than you can perform actions on powerful cloud servers. Serverspace provides isolated VPS / VDS servers for common and virtualize usage.

Create Server
Screenshot №1 — Create Server

First of all it is necessary to install a set of tools that will be used to partition the disc space. To work with the physical disc and its logical partitions we need the parted utility, and to work with lvm we need the lvm2 utility:

apt update && apt install parted lvm2
Install LVM
Screenshot №2 — Install LVM

Great, now that we have all the tools from the toolbox - let's go through the list of mounted file systems:

df -H
Disk space
Screenshot №3 — Disk space

When installing the image in /home, we lacked 2 GB - we need to increase the size to 3 GB, at the expense of the second partition. Unmount the working partition with the command:

umount  /dev/main/lvol0
Unmount disc
Screenshot №4 — Unmount disk

Note that you need to specify your logical partition! After the partition has been unmounted and is not used by the system - we can set a new space size for it.

resize2fs /dev/main/lvol0

The warning asks you to scan the partition for errors with the e2fsck utility, after which you will need to repeat the command. Let's speed up the process by entering two commands at once:

e2fsck -f /dev/main/lvol0 && resize2fs /dev/main/lvol0

Reduce filesystemScreenshot №5 — Reduce filesystem

Great, the message at the end notifies you of the new FS size. Shrink the lvm system logical partition with the command below:

lvreduce -L 1G /dev/main/lvol0
Reduce size of volume
Screenshot №6 — Reduce size of volume

The output of the command shows that the task was successfully completed, the partition was reduced! Using the freed space, we will enlarge another logical partition. Don't forget to mount partitions!

How to quickly increase the partition size?

Now the free space of the virtual group is exactly 1 GB, it must be defined to the logical partition lvol1. To do this, we will proceed in reverse order, first increasing the volume size:

lvextend -L /dev/main/lvol1 3G

You can find your volume with the lvscan command, in case it is not shown via df -H. After that let's increase the file system size to the maximum available:

Scan of logical volume
Screenshot №7 — Scan of logical volume

In a few commands the space was enlarged and moved from the neighbouring partition, all that was left was to mount it and test it to see if it worked:

mount /dev/main/lvol1 && df -H
Mount extended disk
Screenshot №8 — Mount extended disk
Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300

You might also like...

We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.