Skip to content

Intermediate · Storage: partitions, file systems and LVM · topic 25 of 57 · 30 min

File systems and mounting: XFS, ext4, mount and df

Explanation

A file system is the structure that stores files and folders on a partition. RHEL's default is XFS; ext4 is also supported. mkfs.xfs or mkfs.ext4 creates one, mount attaches it to a directory, umount detaches it, and df -h and du show the space used.

What a file system is

A partition is just raw space. A file system organises that space: it keeps a list of files and folders, their owners and permissions, and which blocks hold their data. Creating a file system is called formatting, and it erases whatever was on the partition before.

XFSext4
RHEL defaultYes (since RHEL 7)No, but fully supported
StrengthsVery large files and file systems, parallel I/OSimple, mature, small systems
Grow while mountedYes (xfs_growfs)Yes (resize2fs)
ShrinkNO, neverYes, but only unmounted
Createmkfs.xfsmkfs.ext4

The one fact to remember: XFS cannot be shrunk. If you may need to make a file system smaller later, plan for that (or use ext4).

bash
# mkfs.xfs /dev/vdb1
meta-data=/dev/vdb1              isize=512    agcount=4, agsize=131008 blks
data     =                       bsize=4096   blocks=524032, imaxpct=25
...
# mkfs.ext4 -L backups /dev/vdc1        # -L gives a label
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 262144 4k blocks and 65536 inodes
...
# lsblk -f /dev/vdb /dev/vdc
NAME   FSTYPE LABEL   UUID                                 MOUNTPOINTS
vdb
└─vdb1 xfs            5b2f3c1e-8d7a-4f0b-a9e1-3c6d2b8f9a10
vdc
└─vdc1 ext4   backups 0e9c7d6b-1a2f-4c3d-8e5f-6a7b8c9d0e1f
Each new file system gets a UUID: a unique ID that never changes, even if the disk name does.

Mounting: attaching to the tree

To use a file system you mount it on a directory, called the mount point. After that, everything you put in that directory is stored on that file system. umount detaches it again (note the spelling: umount, no n).

bash
# mkdir -p /data
# mount /dev/vdb1 /data
# df -h /data
Filesystem      Size  Used Avail Use% Mounted on
/dev/vdb1       2.0G   47M  2.0G   3% /data
# findmnt /data
TARGET SOURCE    FSTYPE OPTIONS
/data  /dev/vdb1 xfs    rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota
# umount /data

mount without options mounts read-write with default options. Useful options: -o ro (read-only), -o noexec (do not allow running programs from here), -o remount,rw (change options of a mounted file system). A mount made with the mount command is lost at reboot; the next topic makes it permanent.

How much space? df and du

bash
$ df -h                         # every mounted file system
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   17G  4.1G   13G  25% /
/dev/vda1             1014M  298M  717M  30% /boot
/dev/vdb1              2.0G   47M  2.0G   3% /data
$ df -i /                       # inodes: number of files, can run out before space does
$ du -sh /var/log               # size of one directory tree
612M    /var/log
$ du -h --max-depth=1 /var | sort -h | tail -3     # biggest folders under /var

df asks the file system how full it is. du adds up file sizes by walking the tree. They can disagree: if a program still has a deleted file open, df counts the space but du cannot see the file. Restarting that program frees the space. lsof +L1 lists such deleted-but-open files.

Common mistakes

  • "umount: /data: target is busy": some process, often your own shell, is using it. cd out of it, then check with lsof /data or fuser -vm /data.
  • Mounting on a directory that already has files. They are hidden (not deleted) while something is mounted on top, which confuses people. Mount on empty directories.
  • Running mkfs on a partition that has data, or on the whole disk instead of the partition (/dev/vdb instead of /dev/vdb1).
  • Planning to shrink an XFS file system later. It is not possible; back up, recreate smaller, and restore.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

File systems and mounting: XFS, ext4, mount and df · 1/6

partition + mkfs = file system

A file system organises a partition into files and folders. Formatting erases what was there.

Prefer a video by a teacher? Find free videos on “mkfs xfs mount umount df du linux tutorial” on YouTube ↗

In real life: Disk full on a school ERP server

A school management ERP in Indore stops saving attendance. df -h shows / at 100%. du -h --max-depth=1 / | sort -h points to /var, then to /var/log, where an app has written a 9 GB debug log. The admin compresses and moves the old log, restarts the app to release the open file, and adds a separate 10 GB XFS file system for /var/log so logs can never fill / again.

bash
# df -h /
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   17G   17G   20K 100% /
# du -sh /var/log/erp
9.1G    /var/log/erp

Practice (0/3 done)

Task 1 · Question

Which file system type can NOT be shrunk?

Task 2 · Code · Python

Write full_mounts(df_text, limit) for "df -h"-style text. Skip the header line and blank lines. Each other line has 6 columns: Filesystem, Size, Used, Avail, Use% (like "88%") and Mounted on. Return the mount points whose Use% is at or above limit (an int), in the same order.

Task 3 · Practice

Format the 1 GiB partition you made earlier with XFS, mount it on /mnt/xfsdata, create a file in it, check the space with df -h, then unmount it and show the file is no longer visible in /mnt/xfsdata.

Quick quiz

Question 1

1.What is the default file system on RHEL 9?

Question 2

2.Which command shows file system types and UUIDs of block devices?

Question 3

3.umount says "target is busy". What is a likely cause?

Question 4

4.df says / is full but du finds much less. What can explain it?

Question 5

5.What happens to a mount made with the mount command after a reboot?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

What is the default file system on RHEL 9?

Answer: XFS

XFS has been the default since RHEL 7.

Which command shows file system types and UUIDs of block devices?

Answer: lsblk -f

lsblk -f (or blkid) shows FSTYPE and UUID.

umount says "target is busy". What is a likely cause?

Answer: Your shell or a process is using a file in that directory

Leave the directory and find users with lsof or fuser.

df says / is full but du finds much less. What can explain it?

Answer: A deleted file is still held open by a process

Space is freed only when the process closes the file.

What happens to a mount made with the mount command after a reboot?

Answer: It is gone unless it is in /etc/fstab

Only /etc/fstab (or a mount unit) makes it permanent.

What should the 6th field be for an XFS file system?Related

Answer: 0

XFS is not checked by fsck at boot, so 0.

From Permanent mounts with /etc/fstab and UUIDs

Which command grows a mounted XFS file system to fill its LV?Related

Answer: xfs_growfs /data

xfs_growfs takes the mount point.

From Growing storage and adding swap

You started a service with systemctl start, but after a reboot it is not running. What did you forget?Related

Answer: systemctl enable

start runs it now; enable makes it start at boot.

From Processes, signals and systemd services

What does "parted /dev/vdb mkpart data xfs 1MiB 2GiB" NOT do?Related

Answer: Create an XFS file system

The xfs word is only a hint; run mkfs.xfs afterwards.

From Disks and partitions: MBR, GPT, fdisk and parted

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 3 more topics in “Storage: partitions, file systems and LVM” before its exam: Permanent mounts with /etc/fstab and UUIDs, LVM: physical volumes, volume groups and logical volumes, Growing storage and adding swap.
  2. Module 5 exam: Storage · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, SELinux and SSH. 57 topics left in the course before the final exam.

← Previous: Disks and partitions: MBR, GPT, fdisk and parted