The Unix Filesystem - noyage/redhat GitHub Wiki

What is a filesystem

  • a logical container that is used to store files and directories.
  • Each system is created in a separate partition or logical volume
  • a typical RHEL system usually has many file systems
  • 2 are created by default on RHEL
    • / and /boot
    • others created after installation; /home , /opt, /tmp , /var, /usr

Types of filesystems

  • Several types of file systems
  • 3 basic groups
  • disk-based
    • For hard disks using SCSI, iSCSi, SAS, SATA, USB, Fibre Channel
  • network-based
    • disk-based file systems shared over a network for remote access
  • memory-based
    • virtual. Created automatically at system setup
  • The first 2 types store information persistently ; any data in virtual file systems are lost upon system reboot.

Linux File Systems

  • RedHat-based linuxes (RHEL/Rocky/Alma/...) all use XFS by default
  • Debian-based linuxes (includes Ubuntu) use EXT4 by default

Show mounted filesystems

  • $ df -h
  • $ mount
  • $ mount -t xfs
  • $ mount -t ext4
  • $ cat /etc/fstab <-- filesystems mounted at boot time

Creating a filesystem

  • note for VM's, it's ok to create a filesystem on the whole disk (/dev/sdb etc)
  • for physical machines, create partitions on a disk and then put a fs on the partition
  1. Partition the hard drive (optional if a VM)
  • make sure drive exists in lsblk
  • use format or parted to partition a disk:
    • parted /dev/sdb
    • format /dev/sdb
  1. Create an ext4 or xfs filesystem on the partition (or entire disk)
  • mkfs.xfs /dev/sdb1 (where 1 is the partition number)
  • mkfs.ext4 /dev/sdb1
  • to use entire disk, use /dev/sdb instead of /dev/sdbX

UNIX

  • In unix, everything is a file
    • data files
    • compiled code (system binaries such as/usr/bin/ls)
    • directories (folder)
    • devices (keyboard, mouse, disk drives, screen, printers,...)
  • files have a user and group defined
  • files have 3 sets permissions for user/group/other
  • each permission set is represented by 3 binary digits
  • root directory "/" at top
  • The Unix File System

Owner/Group

  • all files have an owner and a group
  • ls or stat command
$ ls -l /etc/passwd
-rw-r--r--. 1 root root 2645 Dec 19 13:58 /etc/passwd

---

$ stat /etc/passwd
  File: /etc/passwd
  Size: 2645      	Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d	Inode: 201326853   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:passwd_file_t:s0
Access: 2025-04-12 16:01:01.335299886 -0400
Modify: 2024-12-19 13:58:26.510758416 -0500
Change: 2024-12-19 13:58:26.511758513 -0500
 Birth: 2024-12-19 13:58:26.510758416 -0500

File Permissions

  • user + group + other + selinux
  • the trailing dot indicates SELinux security context
  • user, group and other have read-write-execute permissions
  • rwx has a different meaning for directories than for files

Change file permissions

  • specify via ugo or bits (4+2+1)
    • chmod g+x (filename)
    • chmod 770 (filename

Change owner/group

  • chown user:group (filename)
⚠️ **GitHub.com Fallback** ⚠️