Close Menu
DPC Virtual Tips
    Read More

    How to Troubleshoot Packet Drops on an ESXi Host

    August 16, 2026

    SlurmDBD Is Down: What Continues Working and What Does Not

    August 15, 2026

    How to Investigate Jobs Stuck in COMPLETING State on Slurm

    August 14, 2026
    • Home
    • About Us
    • Contact
    • Cookie Policy
    • Comment Policy
    • Privacy Policy
    • Terms of Use
    • Disclaimer
    Tuesday, August 25
    DPC Virtual Tips
    • Home
    • Operating Systems
    • PowerFlex
    • HPC
    • Virtualization
    • About the Author
    • About Us
    • Contact
    DPC Virtual Tips
    Home » Resizing Filesystems on RHEL 8
    Operating Systems

    Resizing Filesystems on RHEL 8

    DaniloBy DaniloJuly 30, 2025Updated:August 1, 2026No Comments6 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    RHEL 8 filesystem resize
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Resizing Filesystems on RHEL 8 shows some examples of resizing filesystems using Red Hat Enterprise Linux.

    Warning: Before anything, you must understand that this task can be hazardous. All the steps that are being performed here are being performed in a lab environment using a virtual machine. So, if you plan to do it in a production environment, we’ll not be responsible for any data loss or data unavailability. Be careful!

    Note: We will show some examples using the ext4 and xfs filesystems!

    Preparing the Disk: Creating the Partition Table

    The first step is to create the partition table in our block device. In this case, for instance, our block device is the /dev/sdg with 100GB.

    1- Check the block device size. As we can see, the block device /dev/sdg has no partitions and has a size of 100 GB:

    lsblk -l | grep -i -E "name|sdg"

    2- We can create an MBR/DOS or a GPT partition table. For this example, let’s create a GPT partition table. We’ve written an article about MBR and GPT. Click here to access this article:

    parted -s /dev/sdg mklabel gpt

    3- To confirm if the partition table was created:

    parted /dev/sdg print

    So, the GPT partition table has been created successfully!

    Creating the Disk Partition and the Filesystem

    After creating the partition table, we need to create the disk partition. So, let’s do that:

    1- Define the unit as MiB and create a disk partition using all the available space:

    parted -s /dev/sdg unit MiB
    parted -s /dev/sdg mkpart primary ext4 1MiB 100%

    2- Inspect the partition table to ensure that the disk partition has been created:

    parted /dev/sdg print

    3- The next step is to create the filesystem over the disk partition. We’ll use the ext4 filesystem:

    mkfs.ext4 /dev/sdg1

    4- Inspect details of the filesystem like the block count and block size:

    dumpe2fs /dev/sdg1 | grep -i -E "block count|block size"

    Note: In this case, the ext4 block size is 4KiB (4096 bytes).

    Mounting the Disk Partition

    To effectively use the disk partition, we need to mount it in a system directory. So, let’s break down all the necessary steps for that:

    1- Create a local directory. In this case, for instance, we’ll create a directory under /mnt:

    mkdir -p /mnt/dir-ext4-SDG1

    2- To mount the disk partition /dev/sdg1 in the created directory:

    mount -t ext4 /dev/sdg1 /mnt/dir-ext4-SDG1

    The basic syntax for the mount command is:

    -t ext4 = Defining the filesystem type to be used during the mount operation

    /dev/sdg1 = Disk partition to be mounted

    /mnt/dir-ext4-SDG1 = Local directory to be used as a mount point

    3- Inspect to check if the disk partition was mounted:

    lsblk -fi | grep -i -E "name|sdg"

    As we can see, the disk partition has been mounted successfully.

    4- Let’s create some files in this partition:

    dd if=/dev/zero of=/mnt/dir-ext4-SDG1/file1.dd bs=1M count=250
    dd if=/dev/zero of=/mnt/dir-ext4-SDG1/file2.dd bs=1M count=250
    dd if=/dev/zero of=/mnt/dir-ext4-SDG1/file3.dd bs=1M count=250

    5- Inspect the partition usage with “df”:

    df -Th | grep -i -E "filesystem|sdg|used"

    6- To remember, if you reboot your system, the disk partition will not mount automatically during the system boot. To persist the mount during reboots, we need to add the appropriate entry in the /etc/fstab. Let’s do that. Add the following entry in /etc/fstab configuration file:

    /dev/sdg1       /mnt/dir-ext4-SDG1      ext4    defaults        0       0

    7- Mount:

    mount -a

    After executing the “mount -a”, if everything is okay, it’s not expected to receive any error!

    Shrink the Ext4 Filesystem

    To shrink an ext4 filesystem, we must unmount it first!
    There are two ways to do that:

    • Shrink the filesystem to the smallest safe size.
    • Resize the filesystem to a specific block count.

    First and foremost, to resize an ext4 filesystem, you need to learn how to work with “blocks”. Let’s break down an example of that:

    1- Let’s inspect the block details of our disk partition/filesystem /dev/sdg1:

    dumpe2fs /dev/sdg1 | grep -i -E "block count|block size"

    As we can see, our filesystem has 26213888 blocks, and each block has 4096 bytes. So, if we multiply the block count by the block size, we’ll have the disk partition/filesystem size in bytes. Let’s do this math using the terminal:

    echo $((26213888 * 4096 / 1024 /1024 /1024))

    The result of this operation will be the size of the filesystem in GB. – Note that this value is near the value shown with the “df” command:

    2- Going forward, there is a way to identify the minimum block size that we can safely use, if we need to shrink the filesystem:

    resize2fs -P /dev/sdg1

    So, let’s work with this value. If the estimated minimum size of the filesystem is 634947 blocks, how can we find the value in GB?

    echo $((VALUE_REPORTED_BY_RESIZE2FS_-P * BLOCK_SIZE / 1024 / 1024 / 1024))
                                                        KB     MG     GB

    So, using the formula, the result is:

    echo $((634947 * 4096 / 1024 / 1024 / 1024 ))
    2

    Answer: The minimum safe value to shrink the filesystem is 2GB.

    Step-by-step to shrink the filesystem to the minimum block size:

    1- If the filesystem is mounted, unmount it:

    umount /dev/sdg1

    2- Execute the “e2fsck”:

    e2fsck -f /dev/sdg1

    3- Shrink the filesystem to 634947 blocks (to remember, this number of blocks was provided by the resize2fs -P command):

    resize2fs /dev/sdg1 634947

    4- Mount and inspect to confirm:

    mount -a
    systemctl daemon-reload
    df -Th | grep -i -E "filesystem|sdg"

    As we can see, the new size is around 2GB!

    5- Check if all created files are in the mount point:

    As we can confirm, all created files are in the mount point!

    Expand/Resize the Ext4 Filesystem

    To expand an ext4 filesystem, we do not need to unmount it if it is mounted!
    Let’s break down this task:

    1- The first recommended step is to confirm the size of the block device – in our case, for instance, there is only one partition in our block device – if you have more than one partition, you may need to adjust the procedure:

    lsblk /dev/sdg1

    2- Confirm the current size of the filesystem using the “df”:

    Subtract the current filesystem size from the total device size to find how much you can grow.

    3- To grow using all the available space:

    resize2fs /dev/sdg1

    4- Inspect and confirm it:

    df -Th | grep -i -E "filesystem|sdg"

    As we can confirm, the filesystem was grown successfully!

    Working with the XFS Filesystem

    An XFS filesystem cannot be shrunk!

    You can resize XFS with xfs_growfs, but only online (while mounted).

    To wrap this up:

    FilesystemResize ToolShrink SupportUnmount Required?
    ext4resize2fs✅ Yes✅ Only for shrinking
    XFSxfs_growfs❌ No❌ Always online

    That’s it for now 🙂

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleLogical Volume Management (LVM) Overview on RHEL 8
    Next Article Working with Network File System (NFS) on RHEL 8
    Danilo

    Infrastructure Engineer with experience in Virtualization, Linux, Windows Server and learning automation using Python. DPC Virtual Tips was created to share practical tutorials, lab experiences and troubleshooting guides focused on enterprise infrastructure technologies.

    Related Posts

    Linux Server Has Free Memory but Is Swapping: Why?

    August 13, 2026

    How to Determine Whether Packet Loss Is Local or Network Related on Linux

    August 12, 2026

    How to Investigate TCP Retransmissions on Linux

    August 11, 2026

    Comments are closed.

    Search
    Categories
    • HPC (12)
    • Operating Systems (85)
    • PowerFlex (22)
    • Virtualization (130)
    Read More
    Virtualization

    How to Troubleshoot Packet Drops on an ESXi Host

    By DaniloAugust 16, 20260
    HPC

    SlurmDBD Is Down: What Continues Working and What Does Not

    By DaniloAugust 15, 20260
    HPC

    How to Investigate Jobs Stuck in COMPLETING State on Slurm

    By DaniloAugust 14, 20260
    Operating Systems

    Linux Server Has Free Memory but Is Swapping: Why?

    By DaniloAugust 13, 20260
    Operating Systems

    How to Determine Whether Packet Loss Is Local or Network Related on Linux

    By DaniloAugust 12, 20260
    Latest Posts

    How to Troubleshoot Packet Drops on an ESXi Host

    August 16, 2026

    SlurmDBD Is Down: What Continues Working and What Does Not

    August 15, 2026

    How to Investigate Jobs Stuck in COMPLETING State on Slurm

    August 14, 2026
    Images from Gallery
    hpc main commands
    linux commands
    install rock linux
    lustre fs
    shell scripting
    vSAN Trace Files
    Categories
    • HPC
    • Operating Systems
    • PowerFlex
    • Virtualization
    • Home
    • About Us
    • Contact
    • Cookie Policy
    • Comment Policy
    • Privacy Policy
    • Terms of Use
    • Disclaimer
    Copyright © 2026, DPC Virtual Tips. All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.

    We use cookies to ensure your best experience on our website. If you continue using our website, we'll assume you agree to our cookie policy