Saturday, April 6, 2019

Extending root partition size online in RHEL or CentOS 7

Why do we need to extend root partition size?

There are couple of reasons that root filesystem should always be having free space, else:

1. Without free space programs and OS can crash.
2. No new services or application can be started on the server.
3. Can't write anymore data resulting DU

Hence admin will be left with two options either remove unnecessary files and free up some space or extend root partition size online i.e. without impacting running application or downtime. Below detailed steps will help you to extend your root partition space online:


Step 1. Check current root partition size:

# df -kh
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   46G  6.1G   40G  14% /

Here root partition is of "46GB".


Step 2. Add a new disk and re-scan HBA's to discover it:

# fdisk -l
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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


Step 3. Add new disk to physical volume:

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


Step 4. Add this new disk in to the existing volume group, from which root partition belongs to:

# vgscan
  Reading volume groups from cache.
  Found volume group "centos" using metadata type lvm2


# vgextend centos /dev/sdb
  Volume group "centos" successfully extended
 

Step 5. Extend +15GB to existing root partition using lvextend:

# lvextend -L +15G /dev/centos/root
  Size of logical volume centos/root changed from <45.12 GiB (11550 extents) to <60.12 GiB (15390 extents).
  Logical volume centos/root successfully resized.

Logical volume is increased by 15GB, but not active with new size due to which you will still see same size as before.


# df -kh
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   46G  6.1G   40G  14% /


Step 6. To resize your root partition with newly added space use "xfs_growfs" :

# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=2956800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=11827200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=5775, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 11827200 to 15759360

NOTE: "xfs_growfs" supports only XFS partition. In case you have EXT4 then use "resize2fs"

# df -kh
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   61G  6.1G   55G  11% /

You can see that now root partition is having "61G" total size.

NOTE: In case you want to shrink logical volume size in XFS, it's not supported. Reference : https://access.redhat.com/discussions/3332611

No comments:

Post a Comment