CoreOS is a Linux operating system optimized for running containerized applications. It is the heartbeat of the popular enterprise grade Red Hat OpenShift container platform. CoreOS is designed to be lightweight operating system based on the Linux kernel, and focusing on security, automation and ease of application deployment. In this guide we show you how to extend the root file system(/sysroot) of CoreOS based systems, this can be Red Hat CoreOS(RHCOS) or Fedora CoreOS(FCOS).

The first action is increasing the size of your VM virtual disk. The steps to follow will vary from one virtualization environment to another. This procedure is necessary to accommodate data requirements that have changed since the creation of the virtual disk, at the time you provisioned the virtual machine.

Step 1: Increase virtual disk size

In this guide we demonstrate how to increase virtual disk size in a VMware environment from vCenter console.

Here are some helpful links that can be referenced for other cloud environments.

On vCenter console select the virtual machine from the Inventory and click Edit Settings.

Click Hard Disk and review the current size as desired.

I’ll update my disk size from 16GB to 40GB:

Update the changes using OK button.

Restart the instance by going to VM > Actions > Power section.

Wait as the instance is restarted before you can perform extension on the guest.

Step 2: Extend /sysroot partition on Red Hat / Fedora CoreOS

The recommended and correct approach to extend /sysroot partition is reprovisioning the node. If this is not a viable option, one can use rhcos-growpart or extend filesystem using xfs_growfs.

Method 1: Using xfs_growfs

Since the /sysroot partition is an XFS file system, xfs_growfs command can be used to grow an XFS file system while mounted.

Confirm virtual disk was extended:

$ lsblk
NAME                         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0                          7:0    0  500G  0 loop
sda                            8:0    0   40G  0 disk
├─sda1                         8:1    0  384M  0 part /boot
├─sda2                         8:2    0  127M  0 part /boot/efi
├─sda3                         8:3    0    1M  0 part
└─sda4                         8:4    0 39.5G  0 part
  └─coreos-luks-root-nocrypt 253:0    0 39.5G  0 dm   /sysroot

Check current mounted partition size

$ df -hT /
Filesystem                           Type  Size  Used Avail Use% Mounted on
/dev/mapper/coreos-luks-root-nocrypt xfs    16G   12G  4.2G  74% /

Use xfs_growfs command to grow the partition.

$ sudo xfs_growfs /sysroot/
meta-data=/dev/mapper/coreos-luks-root-nocrypt isize=512    agcount=24, agsize=170048 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=4058875, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 4058875 to 10350331

Check current size

$ df -hT /
Filesystem                           Type  Size  Used Avail Use% Mounted on
/dev/mapper/coreos-luks-root-nocrypt xfs    40G   11G   30G  26% /

Method 2: Using rhcos-growpart

# OCP 4.4 and below
$ sudo /usr/libexec/rhcos-growpart  /sysroot

# OCP 4.5 and above
$ sudo /usr/libexec/rhcos-growpart  /sysroot

The rhcos-growpart is a wrapper of /bin/growpart from cloud-utils-growpart package.

We hope this guide helped you to extend root filesystem /sysroot on OpenShift CoreOS (RHCOS) or OKD Fedora CoreOS(FCOS).

More guides on containerization:

Run CentOS Container Pod in Kubernetes | OpenShift

How To Check Running Kubernetes Components Version

How To Get Docker & Podman Container’s IP Address