How to Fix disk space full issue in CentOS

 If you face disk space full issue with CentOS, you can follow the below mentioned steps to resolve it.

  • Check Hard disk Status
  • Delete big files, old files and unused files
  • Tar or Compress the unused files
  • Move files to another partitions and create Link to free up the space
  • check hard disk status
  • Add additional disk and extend using LVM
Use the below command to check the bad blocks in your disk

# badblocks -v /dev/sdb


bad blocks check completed and found 0 bad blocks, 

Next, iostat command is used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates. 


Use the below command to list the partitions

# df -h

Below command to exclude tmpfs

# df -h | grep -v tmpfs


Now we are going to increase the /data disk space (for lab purpose)

# fallocate -l 9G /data/9gdata


Below command helps to list the disk usage in the numbers reverse order

# du -a / | sort -nr | more


From the above list we can find the big files, we can compress the file using the below tar command

# tar -czvf /root/9gdata.tar.gz /data/9gdata


we have compressed 9gdata file from 9.1G to 9.0M

Next, lets move files to another partitions and create Link to free up the space

mv /data/9gdata /root
# ln -s /root/9gdata /data/


We have created a soft link to free up the disk space, and we have moved the 9G file to other partition.


Add additional disk and extend using LVM

Add new disk to your server and use the below command to scan it

# echo "- - -" > /sys/class/scsi_host/host0/scan
# echo "- - -" > /sys/class/scsi_host/host1/scan
# echo "- - -" > /sys/class/scsi_host/host2/scan
# echo "- - -" > /sys/class/scsi_host/host3/scan

Use the below command to look for newly added disk

# fdisk -l

# fdisk /dev/sdc

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xcadad4c3.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 1
Value out of range.
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039):

Created a new partition 1 of type 'Linux' and of size 20 GiB.

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.


Before extend /data use the below command to check the file system usage

# lsof /data

# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created.

# vgdisplay
  --- Volume group ---
  VG Name               vg_data
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <9.97 GiB
  PE Size               32.00 MiB
  Total PE              319
  Alloc PE / Size       319 / <9.97 GiB
  Free  PE / Size       0 / 0
  VG UUID               18pvub-kbC5-Mc6o-aBIt-eB1i-NCTY-6W97x5

Extend the existing VG:

# vgextend vg_data /dev/sdc1
  Volume group "vg_data" successfully extended

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_data/lv_data
  LV Name                lv_data
  VG Name                vg_data
  LV UUID                4p8Anj-nVM0-ScV5-s30D-3D51-YYkT-xFjCAA
  LV Write Access        read/write
  LV Creation host, time CentOS, 2021-03-09 02:47:36 -0800
  LV Status              available
  # open                 1
  LV Size                <9.97 GiB
  Current LE             319
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

Extend the existing LV:

 lvextend -l +100%FREE /dev/vg_data/lv_data
  Size of logical volume vg_data/lv_data changed from <9.97 GiB (319 extents) to <29.94 GiB (958 extents).
  Logical volume vg_data/lv_data successfully resized.

Use the below command to resize2fs

#resize2fs /dev/vg_data/lv_data

or 

xfs_growfs /dev/mapper/vg_data02-lv_data02 (if XFS filesystem)



Comments