Skip to content

Filesystem Management

Prerequisites

  • Root or sudo privileges
  • Awareness of which disk to modify (do NOT format the OS disk)

Procedure: List Block Devices

When to use: Identifying disk names, sizes, and partitions before modifying them.

Steps:

  1. List all block devices in a tree view:

    lsblk
    

  2. List devices with UUIDs (needed for fstab):

    lsblk -f
    

Troubleshooting:

  • If a disk doesn't show up: Check virtualization settings or physical connections. Scan SCSI bus echo "- - -" > /sys/class/scsi_host/host0/scan.

Procedure: Create a Partition with fdisk

When to use: Slicing a raw disk (e.g., /dev/vdb) into usable partitions.

Steps:

  1. Open the disk utility:

    fdisk /dev/vdb
    

  2. Create new partition:

    • Type n (new)
    • Type p (primary)
    • Press Enter for defaults (partition number, start sector)
    • Enter size (e.g., +10G) for last sector
    • Type w (write changes and exit)
  3. Refresh kernel partition table:

    partprobe
    

Troubleshooting:

  • "Device busy": The disk is currently mounted. Unmount it first.

Procedure: Format a Partition

When to use: Creating a filesystem (ext4, xfs) on a partition so it can store files.

Steps:

  1. Format as ext4:

    mkfs.ext4 /dev/vdb1
    

  2. Or format as XFS:

    mkfs.xfs /dev/vdb1
    

Troubleshooting:

  • "Will not make a filesystem here!": You might be trying to format the whole disk (/dev/vdb) instead of the partition (/dev/vdb1), or it's mounted.

Procedure: Mount a Filesystem

When to use: Attaching a storage device to the directory tree.

Steps:

  1. Create a mount point (directory):

    mkdir -p /mnt/data
    

  2. Mount the partition:

    mount /dev/vdb1 /mnt/data
    

  3. Verify:

    df -h /mnt/data
    

Troubleshooting:

  • "mount point does not exist": Run mkdir.
  • "wrong fs type": Ensure the partition was formatted with mkfs.

Procedure: Configure Persistent Mounts in /etc/fstab

When to use: Ensuring filesystems mount automatically after reboot.

Steps:

  1. Find the UUID of the partition:

    blkid /dev/vdb1
    

  2. Edit /etc/fstab:

    nano /etc/fstab
    

  3. Add a line at the end:

    UUID=<your-uuid-here>  /mnt/data  ext4  defaults  0  2
    

  4. Verify (crucial step!):

    mount -a
    
    If this outputs no errors, it is safe to reboot.

  5. Reload systemd so it picks up the updated fstab:

    systemctl daemon-reload
    

  6. For newly formatted filesystems, apply the correct SELinux context:

    restorecon -Rv /mountpoint
    
    A fresh filesystem gets an unlabeled_t SELinux context by default. Without relabeling, services writing to it may get permission denied even if the Linux file permissions are correct.

Troubleshooting:

  • WARNING: If mount -a fails, DO NOT REBOOT. You will drop to emergency shell. Fix the syntax in /etc/fstab first.

Procedure: Set Up an NFS Server

When to use: Sharing a directory on this machine with other machines (or yourself) over the network.

Steps:

  1. Install the NFS utilities:

    dnf install nfs-utils
    

  2. Create the directory to export:

    mkdir -p /data/nfs
    

  3. Add an export entry to /etc/exports:

    /data/nfs  *(rw,sync,no_root_squash)
    
    Replace * with a specific IP or subnet to restrict access.

  4. Start the NFS server and apply the exports:

    systemctl enable --now nfs-server
    exportfs -a
    

  5. Open the firewall:

    firewall-cmd --add-service=nfs --add-service=mountd --add-service=rpc-bind --permanent
    firewall-cmd --reload
    

  6. Verify the export is visible:

    showmount -e localhost
    

Troubleshooting:

  • mount.nfs: access denied — the client IP is not matched in /etc/exports, or you forgot to run exportfs -a after editing.
  • mount.nfs: Connection timed out — firewall is blocking ports 111 or 2049.
  • Share not in showmount -e — run exportfs -a or restart nfs-server.

Procedure: Mount an NFS Share

When to use: Accessing a directory shared by an NFS server from a client machine.

Steps:

  1. Install the NFS client utilities (if not already installed):

    dnf install nfs-utils
    

  2. Create a mount point:

    mkdir -p /mnt/nfs
    

  3. Mount the share:

    mount -t nfs <server-ip>:/data/nfs /mnt/nfs
    
    If successful, the command produces no output.

  4. Verify:

    df -hT | grep nfs
    

  5. To make the mount persistent, add to /etc/fstab:

    <server-ip>:/data/nfs  /mnt/nfs  nfs  defaults  0  0
    
    Then run mount -a to verify.

Troubleshooting:

  • Connection timed out — NFS server firewall is blocking the client.
  • access denied — your IP is not in the server's /etc/exports.

Procedure: Set Up a Samba Server

When to use: Sharing a directory using the SMB protocol (compatible with Windows clients and Linux mount.cifs).

Steps:

  1. Install Samba packages:

    dnf install samba samba-client cifs-utils
    

  2. Create the share directory:

    mkdir -p /data/samba
    

  3. Create a group and add users:

    groupadd samba_group
    usermod -aG samba_group scoring
    

  4. Set a Samba password for each user:

    smbpasswd -a scoring
    

  5. Set permissions and SELinux context:

    chmod -R 0755 /data/samba
    chown -R root:samba_group /data/samba
    chcon -t samba_share_t /data/samba
    

  6. Add a share section to /etc/samba/smb.conf:

    [sysadm]
    comment = Samba share for sysadmin lab
    path = /data/samba
    valid users = @samba_group
    browsable = yes
    writable = yes
    

  7. Verify the configuration:

    testparm
    

  8. Start and enable the Samba services:

    systemctl enable --now smb nmb
    

  9. Open the firewall:

    firewall-cmd --add-service=samba --permanent
    firewall-cmd --reload
    

  10. Verify the share is visible:

    smbclient -L //localhost -U scoring
    

Troubleshooting:

  • NT_STATUS_LOGON_FAILURE — wrong password or user does not have a Samba password. Run smbpasswd -a <user>.
  • NT_STATUS_ACCESS_DENIED — user is not in valid users, or SELinux context is wrong (chcon -t samba_share_t /data/samba).
  • Share not in list — smb service may not be running.

Procedure: Mount a Samba Share

When to use: Mounting a Samba/CIFS share from the client side to verify it works or for persistent access.

Steps:

  1. Install cifs-utils if not already present:

    dnf install cifs-utils
    

  2. Create a mount point:

    mkdir -p /mnt/samba
    

  3. Mount the share:

    mount -t cifs -o username=scoring //localhost/sysadm /mnt/samba
    
    Enter the Samba password when prompted.

  4. Verify:

    df -hT | grep cifs
    

  5. To make the mount persistent, add to /etc/fstab:

    //localhost/sysadm  /mnt/samba  cifs  username=scoring,password=<pass>  0  0
    
    Then run mount -a to verify.

Troubleshooting:

  • mount error(13): Permission denied — wrong credentials, user not in valid users, or SELinux issue on the server.
  • mount error(112): Host is down — Samba service is not running on the server.

Quick Reference

Action Command
List disks lsblk
Partition fdisk /dev/disk
Format ext4 mkfs.ext4 /dev/part
Mount mount dev dir
Unmount umount dir
Check usage df -h
Check UUID blkid
Verify fstab mount -a
  • Concepts: Filesystems