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:
-
List all block devices in a tree view:
lsblk -
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:
-
Open the disk utility:
fdisk /dev/vdb -
Create new partition:
- Type
n(new) - Type
p(primary) - Press
Enterfor defaults (partition number, start sector) - Enter size (e.g.,
+10G) for last sector - Type
w(write changes and exit)
- Type
-
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:
-
Format as ext4:
mkfs.ext4 /dev/vdb1 -
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:
-
Create a mount point (directory):
mkdir -p /mnt/data -
Mount the partition:
mount /dev/vdb1 /mnt/data -
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:
-
Find the UUID of the partition:
blkid /dev/vdb1 -
Edit
/etc/fstab:nano /etc/fstab -
Add a line at the end:
UUID=<your-uuid-here> /mnt/data ext4 defaults 0 2 -
Verify (crucial step!):
If this outputs no errors, it is safe to reboot.mount -a -
Reload systemd so it picks up the updated fstab:
systemctl daemon-reload -
For newly formatted filesystems, apply the correct SELinux context:
A fresh filesystem gets anrestorecon -Rv /mountpointunlabeled_tSELinux 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 -afails, DO NOT REBOOT. You will drop to emergency shell. Fix the syntax in/etc/fstabfirst.
Procedure: Set Up an NFS Server¶
When to use: Sharing a directory on this machine with other machines (or yourself) over the network.
Steps:
-
Install the NFS utilities:
dnf install nfs-utils -
Create the directory to export:
mkdir -p /data/nfs -
Add an export entry to
/etc/exports:Replace/data/nfs *(rw,sync,no_root_squash)*with a specific IP or subnet to restrict access. -
Start the NFS server and apply the exports:
systemctl enable --now nfs-server exportfs -a -
Open the firewall:
firewall-cmd --add-service=nfs --add-service=mountd --add-service=rpc-bind --permanent firewall-cmd --reload -
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 runexportfs -aafter editing.mount.nfs: Connection timed out— firewall is blocking ports 111 or 2049.- Share not in
showmount -e— runexportfs -aor restartnfs-server.
Procedure: Mount an NFS Share¶
When to use: Accessing a directory shared by an NFS server from a client machine.
Steps:
-
Install the NFS client utilities (if not already installed):
dnf install nfs-utils -
Create a mount point:
mkdir -p /mnt/nfs -
Mount the share:
If successful, the command produces no output.mount -t nfs <server-ip>:/data/nfs /mnt/nfs -
Verify:
df -hT | grep nfs -
To make the mount persistent, add to
/etc/fstab:Then run<server-ip>:/data/nfs /mnt/nfs nfs defaults 0 0mount -ato 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:
-
Install Samba packages:
dnf install samba samba-client cifs-utils -
Create the share directory:
mkdir -p /data/samba -
Create a group and add users:
groupadd samba_group usermod -aG samba_group scoring -
Set a Samba password for each user:
smbpasswd -a scoring -
Set permissions and SELinux context:
chmod -R 0755 /data/samba chown -R root:samba_group /data/samba chcon -t samba_share_t /data/samba -
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 -
Verify the configuration:
testparm -
Start and enable the Samba services:
systemctl enable --now smb nmb -
Open the firewall:
firewall-cmd --add-service=samba --permanent firewall-cmd --reload -
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. Runsmbpasswd -a <user>.NT_STATUS_ACCESS_DENIED— user is not invalid users, or SELinux context is wrong (chcon -t samba_share_t /data/samba).- Share not in list —
smbservice 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:
-
Install
cifs-utilsif not already present:dnf install cifs-utils -
Create a mount point:
mkdir -p /mnt/samba -
Mount the share:
Enter the Samba password when prompted.mount -t cifs -o username=scoring //localhost/sysadm /mnt/samba -
Verify:
df -hT | grep cifs -
To make the mount persistent, add to
/etc/fstab:Then run//localhost/sysadm /mnt/samba cifs username=scoring,password=<pass> 0 0mount -ato verify.
Troubleshooting:
mount error(13): Permission denied— wrong credentials, user not invalid 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 |
Related Documentation¶
- Concepts: Filesystems