A
A
anton13ms2019-10-01 09:05:31
linux
anton13ms, 2019-10-01 09:05:31

How to increase free space for a partition in LVM?

I can’t figure out how to increase the free space for the /var directory:
5d92ed14bd826351524396.png
11M is available there, but it’s not clear how to increase it :(

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Melkij, 2019-10-01
@anton13ms

Check vgdisplay for Free PE. If 0 - there is simply nothing to expand.
If there is free, then lvresize or lvextend. Then expand the file system (resize2fs for ext2/3/4 which you probably already have)
If free is not available, then you need to add a new disk or reduce other partitions. For example, /home . However, judging by its size and 45MB used, you cut the disk incorrectly for your task (why did you cut /var and /home separately at all?). Maybe it would be better to completely remount the /home partition somewhere, copy the data to the root /home and delete this volume completely.
If you need a separate / home - then again resize2fs or whatever file system you have there. Compress to some size (if possible), check that it is compressed, then reduce the logical volume (lvresize). It makes sense to ask resize2fs to be less than the size you want to shrink the partition. then, after lvresize, call resize2fs again and expand the partition back - so as not to accidentally make a mistake by a couple of megabytes and not damage the file system.

D
Dmitry, 2019-10-01
@Tabletko

We increase the volume on which /var lies We
increase the file system under /var
We rejoice ...

C
CityCat4, 2019-10-01
@CityCat4

I once wrote an instruction:
Expanding the disk using LVM We
format the added device. I'll omit the fdisk output. Use the 'o' subcommand to create a new partition table, then the 'n' subcommand to create a new partition. If the partition is the only one, fdisk itself substitutes the necessary sector numbers and assigns the type itself - 0x83 (Linux). To change the partition type to 0x8e (Linux LVM) use the 't' subcommand. The 'w' subcommand is used to write the partition table to disk. The partition table only needs to be created if a completely new, unformatted drive is being used.
Create a new physical volume to add it to LVM:

# pvcreate /dev/sdb1
      Physical volume "/dev/sdb1" successfully created

We find the name of the volume group to which we will add the newly created physical volume.
# vgdisplay
      --- Volume group ---
      VG Name               vg_windycat

We expand the volume group that we need with the newly created physical volume:
# vgextend vg_windycat /dev/sdb1
      Volume group "vg_windycat" successfully extended

We look at the names of the volumes to choose from them the one that we need to expand:
# lvscan
      ACTIVE            '/dev/vg_windycat/lv_swap' [4.69 GiB] inherit
      ACTIVE            '/dev/vg_windycat/lv_tmp' [4.00 GiB] inherit
      ACTIVE            '/dev/vg_windycat/lv_root' [39.06 GiB] inherit
      ACTIVE            '/dev/vg_windycat/lv_home' [51.76 GiB] inherit

Expand the selected logical volume:
# lvextend /dev/vg_windycat/lv_tmp /dev/sdb1
      Size of logical volume vg_windycat/lv_tmp changed from 4.00 GiB (1024 extents) to 24.00 GiB (6143 extents).
      Logical volume lv_tmp successfully resized

But extending a logical volume is not all. You still need to expand the disk in terms of the file system. To do this, we use the resize2fs command, which performs all the necessary operations and, depending on the size of the file system, can take quite a long time:
# resize2fs /dev/vg_windycat/lv_tmp
    resize2fs 1.41.12 (17-May-2010)
    Filesystem at /dev/vg_windycat/lv_tmp is mounted on /tmp; on-line resizing required
    old desc_blocks = 1, new_desc_blocks = 2
    Performing an on-line resize of /dev/vg_windycat/lv_tmp to 6290432 (4k) blocks.
    The filesystem on /dev/vg_windycat/lv_tmp is now 6290432 blocks long.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question