16

My current settings are as below, where the /dev/mapper/centos-root partition is almost full.

Looks like this partition is on disk /dev/mapper/centos-root. but there is another disk /dev/vda , which still has enough free space

Are these two disks separate physical disks?

how to increase the /dev/mapper/centos-root partition?

[root@devbox ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   18G   17G  1.4G  93% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G   48M  3.8G   2% /dev/shm
tmpfs                    3.9G   74M  3.8G   2% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda1                497M  297M  201M  60% /boot
tmpfs                    783M   48K  783M   1% /run/user/1001

[root@devbox ~]# fdisk -l

Disk /dev/vda: 85.9 GB, 85899345920 bytes, 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001ec6a

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048    41943039    20458496   8e  Linux LVM
/dev/vda3        41943040    52428799     5242880   8e  Linux LVM

Disk /dev/mapper/centos-root: 18.8 GB, 18756927488 bytes, 36634624 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@devbox ~]# 
Humberto Castellon
  • 879
  • 1
  • 7
  • 17
Hongwei Liu
  • 301
  • 1
  • 2
  • 4
  • 1
    For some reason your disk is split in 3 partitions. Normally CentOS won't do that, it will use Logical Volumes instead that are safer to resize. You'd have to delete `/dev/vda2` and `/dev/vda3` to extend `/dev/vda1` to use the entire disk, and then resize the Logical Volumes within `/dev/vda1` too to match the new size, but before you do that you have to figure out what is in `/dev/vda2` and `/dev/vda3`, why they exist and if the data in them is not important and can be deleted. – Havenard Nov 01 '18 at 21:27
  • If this is a new system perhaps you should reinstall and pay more attention to how the partitioning is done by the installer. – Havenard Nov 01 '18 at 21:29
  • Ahm, without LVM output there is hardly a chance to understand what options you have and what might be a good solution. The disk holds 85 GB, ~20 are allocated by `/` and `swap`. vda3 is LVM labeled, but that space does not relate to mounted partitions. Check `vgdisplay` and `lvdisplay`. And please post ouputs properly quoted, otherwise they are hardly readable after posting. – hargut Nov 01 '18 at 21:37
  • 1
    _Are these two disks separate physical disks?_ They are not separate disks actually. You are dealing with a system with uses **Logical Volume Management - LVM**. Before doing anything, I suggest you to read [LVM HOWTO](http://tldp.org/HOWTO/LVM-HOWTO/index.html) in order to understand the concepts behind it. Then, you can follow instructions from Jorge's answer below. I strongly recommend you **not to perform partition layout changes** until you discover by yourself the relationship among `/dev/vda2`, `/dev/vda3` and `/dev/mapper/centos-root`. – Anderson Medeiros Gomes Nov 02 '18 at 16:00

3 Answers3

28

The first thing is to check if you have free extents in your volume group, to do that, you will use:

vgdisplay

which will return details on the VG, the important line you must check is the one that states Free PE / Size. There you will see the size available to create or extend logical volumes. For instance in my case I have a server that says:

Free PE / Size           3834 / 14.98 GiB

Given that you have the required free space you should use:

lvextend /dev/mapper/centos-root -L +2G

In the latter case I am extending the logical volume adding 2GB. Note the +, if you give only the size, it will go to the specified size, I usually use this syntax because it is more transparent with the space you have available in the volume group.

After you successfully extended the volume (check with lvscan), you have to extend the file system, you can use:

resize2fs /dev/mapper/centos-root

As mentioned by @tinmarino and @y-melo in the comments. The command above will only work for ext2, ext3 and ext4. For xfs you should use xfs_growfs /dev/mapper/centos-root

Run df again to check that the available space has changed.

What if there's no space in the VG?

You have to first extend the volume group to be able to extend the logical volumes. For this matter you have to add a new disk. I am assuming that the CentOS box is a virtual machine because of the size of the disk, but of course this can be done on a physical server too, it is just that you have to physically add a disk.

Once you have the disk on the server, you have to create an LVM physical volume (PV), this can be created on a partition or even on the disk, I don't know the pros of doing it on the disk, but in my experience I have found it confusing as you won't be able to see a partition table, so I would recommend creating a partition first.

To create the PV over disk `/dev/vdb' partition 1 you do:

pvcreate /dev/vdb1

Once you have the PV, extend the VG (I don't know the name, I bet it is centos, check on your vgdisplay):

vgextend centos /dev/vdb1

TL;DR

For VG: vg0, LV:lv0 and new disk /dev/sdb. Extending 5GB

  1. Check available space on the VG: vgdisplay. If enough go to 4
  2. If you don't have space add a disk and create a PV: pvcreate /dev/sdb1
  3. Extend the VG: vgextend vg0 /dev/sdb1
  4. Extend the LV: lvextend /dev/vg0/lv0 -L +5G
  5. Check: lvscan
  6. Resize the file system: resize2fs /dev/vg0/lv0 (or xfs_growfs /dev/vg0/lv0)
  7. Check: df -h | grep lv0
Jorge Valentini
  • 563
  • 4
  • 11
2

If you have free extents, which could be easiliy possible judging your outputs, then lvextend and xfs_growfs or resize2fs could be the commands you are looking for.

hargut
  • 3,908
  • 7
  • 10
  • This doesn't have enough information in it to be useful – A X Aug 25 '19 at 04:06
  • It also depends on the amount of knowledege the reader has. In case there is little knowledge on lvm & file systems your statement is possibly true. Generally my answers do assume that the asking person has a solid understanding of the problem intended to be solved. – hargut Aug 25 '19 at 21:44
  • 1
    xfs_growfs worked for my situation – FractalSpace May 04 '20 at 19:12
-1

I know its a little old but for me this was mysql binary logs that where taking up the space.

as mysql root run

PURGE BINARY LOGS BEFORE DATE(NOW() - INTERVAL 3 DAY) + INTERVAL 0 SECOND;

this cleared most of my space back to about 20%