Disk Management and Filesystems

Understanding Storage in Linux: Disks, Partitions, and Filesystems
administrator tasks include managing storage
need to add and partition new hard drives
need to format drives with a filesystem so kernel read them
need to mount the drives so users can access them

Three Layers of Abstraction
Layer 1: The Disk (The Building)
SSDs and HDDs are Block Devices
Linux assigns names based on how they're connected
  • /dev/sda: the first SATA or SCSI drive (a = first, b = second, etc.)
  • /dev/sdb: the second SATA drive
  • /dev/nvme0n1: a modern NVMe (M.2) SSD
  • /dev/vda: a virtual disk in running Linux in a VM

Layer 2: The Partitions (The Rooms)
divide the drive into logical sections
names appear as numbers appended to the device name
  • /dev/sda1
  • - first partition on the first disk
  • /dev/sda2
  • - second partition on the first disk

Layer 3: The Filesystems (The Shelving System)
formatting is the act of writing a Filesystem onto a partition
creates the internal index that allowing the kernel to locate the desired file

The Mount Point
from the text

Once you have a formatted partition, you have to attach it to the 
Linux directory tree. This is called Mounting. You pick an empty 
directory (like /mnt/data) and tell Linux: "When I look in this 
folder, show me the contents of that partition."

Harland, Jude. Linux Basics 2025: 
The Ultimate Handbook for Mastering the OS, Terminal, and Network Administration (p. 217). 
Kindle Edition. 
Note: Fortunately a new SSD was plugged into the mini-PC (Ubuntu Linux Box) and the system automatically recognized the OEM filesystem. Nothing was needed to do.

Viewing Disk Information: lsblk, fdisk -l, df, du
The Tree View: lsblk
lsblk stands for List Block Devices
command
lsblk
output
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT 
sda 8:0 0 500G 0 disk 
├─sda1 8:1 0 512M 0 part /boot/efi 
└─sda2 8:2 0 499G 0 part / 
sdb 8:16 0 1T 0 disk
structure
  • sda is a 500GB physical disl
  • has two partitions: sda1 and sda2
  • sda2 is mounted at / (root), holds operating system
  • sdb is a 1TB disk, raw and empty

The Technical View: sudo fdisk l
fdisk is a partition manipulation tool
-l flag provides deep technical details
  • sector sizes
  • identifier codes
  • partition table types (MBR vs GPT)
fdisk -l
The Free Space View: df
df stands for disk free
by default shows sizes in 1K blocks
-h flag is for human readable output
example
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 499G 50G 420G 11% /
The Usage View: du
du scans directories and calculates their sizes
run alone du lists every file recursively
use to summarize specific folders
sudo du -sh /var/log
  • -s - summary (total size, don't list every file)
  • -h - human readable

Filesystem Types: ext4, XFS, Btrfs, FAT32, NTFS
Type Standard/Compatible Pros Cons Recommendations
ext4
Fourth Extended Filesystem
default for
Ubuntu, Debian and others
extremely stable
good performance
not as scalable as XFS
lacks modern features
use for most everything
XFS default for
Red Hat and CentOS
performs well with large files and arrays
handles parallel operations very well
cannot shrink partition use for data servers
Red Hat
BTRFS
B-Tree Filesystem
used by
Fedora and OpenSUSE
advanced features like :
snapshots
transparent compression
self-healing data
slightly less stable
can be complex to manage
great for desktops
FAT32 and exFAT compatible Read/Write support for :
Windows
Mac
Linux
FAT32 can't handle files > 4GB
exFA doesn't use permissions
use only on USB sticks
NTFS Windows native Windows format Linux support is good
slower than Linux filesystems
permissions don't map correctly
use only if dual-boot system
Partitioning Disks: fdisk, parted
Using fdisk (for MBR and disks under 2TB)
classic tool
menued with single letter commands
  1. open the disk
    sudo fdisk /dev/sdb
    prompt changes to
    Command (m for help)
  2. create a partion table
    enter 'o' to create ageneric MBR partition table
  3. create a partition
    type n for new
    • Partition type : press p for primart
    • Partion number : 1
    • First sector : press Enter (default)
    • Last sector : accept default or enter the desired size of the partition
  4. verify by entering p to show current layout
    in list should see
    /dev/sdb1
  5. write changes by entering w to write and exit
Using parted (for GPT and disks over 2TB)
old MBR partition cannot handle drives > 2TB
use GPT (guid partition table)
sudo parted /dev/sdb
(parted) mklabl gpt
(parted) mkpart primary ext4 0% 100%
(parted) quit
parted applies changes immediately

Creating Filesystems: mkfs
with a partition created (sdb1), formatting is the next step
mkfs - make filesystem
Formatting with ext4
sudo mkfs.ext4 /dev/sdb1
Formatting with XFS
sudo mkfs.xfs /dev/sdb1
Formatting with FAT32 (for USB devices)
sudo mkfs.vfat /dev/sdb1
Labelling a Partition
sudo mkfs.vfat -L "<label>"/dev/sdb1
Mounting and Unmounting Filesystems: mount, umount
a formatted partition needs to be added to the directory tree
  1. create a mount point
    mount point is an empty directory
    generally created in /mnt or /media
    sudo mkdir /mnt/data
  2. mount the drive <
    sudo mount /dev/sdb1 /mnt/data
  3. verify using lsblk or df-h
Navigate to the Partition
cd /mnt/data
by default root owns the mount point
to change permissions
sudo chown -R <user>:<group> /mnt/data
Unmounting
sudo umount /mnt/data
can't unmount from the partition

Persistent Mounts: Understanding /etc/fstab
mount command is temporary
on reboot the partition will not be remounted
to make mounts permanent need to edit the File System Table file
/etc/fstab
systemd reads the file at boot to know drives to mount

The Danger
if a syntax error occurs in /etc/fstab, the box might not boot
box will enter Emergency Mode
always backup /etc/fstab before making any edits

Identifying the Drive (UUID)
could put /dev/sdb1 in the fstab file
a new USB could take the name sdb making the former sdb become sdc
use the UUID (Universally Unique Identifier) written into the drive's filesystem header
UUID never changes unless the drive is reformatted
to find UUID
sudo blkid
output
/dev/sdb1: LABEL="Backups" UUID="550e8400-e29b-41d4-a716-446655440000" TYPE="ext4"
copy UUID w/o quotes
Editing fstab
sudo nano /etc/fstab
file format is
[Device] [Mount Point] [Filesystem] [Options] [Dump] [Pass]
add the line to the end of file
UUID=550e8400... /mnt/data ext4 defaults 0 2
  1. Device - copied UUID
  2. Mount Point - /mnt/data
  3. Filesystem - ext4
  4. Options - defaults is usually fine (it means read/write, async, auto-mount, etc.)
  5. Dump - Legacy backup flag
  6. Pass - Filesystem check order
    set to 1 for Root drive
    2 for other drives
    0 to skip checking
Test Before Rebooting
run
sudo mount a
tells the system to mount all entries in fstab
if there are no error messages, all is good
if there are errors, fix fstab before rebooting

Checking and Repairing Filesystems: fsck
when things go wrong and thefilesystem gets corrupted, Linx canforce the filesystem into Read-Only Mode
prevents further damage
use File System Consistency Check tool fsck
never run fsck on a mounted filesystem
running fsck on a mounted drive can destroy a filesystem
  1. unmount the drive
    sudo umount /dev/sdb1
  2. run the check
    sudo fsck /dev/sdb1
tool will scan drive
prompts like this will be given
I found an orphaned inode at block 450. Fix? [y/n]
 I found a mismatch in free block count. Fix? [y/n]
can run using -y flag
sudo fsck -y /dev/sdb1
to check the root drive there are two options
  1. Force check on boot: Create a specific empty file
    sudo touch /forcefsck
    Reboot
    system will detect this file, run a check during the boot sequence, and then remove the file
  2. Rescue Mode: Boot from a Linux USB stick (Live CD)
    run fsck on the computer's hard drive from there
Working with External Drives and USB Devices
managing external drives differs whether is box has a GUI desktop or is a headless server
a headless server has no user devices (monitor, keyboard, mouse etc.) attached to it

Desktop Experience
if running GNOME plugging a USB stick works like Windows
an icon appears
done by a background service named udisk2
automatically creates a mount point and mounts the drive
location is usually
/media/<user>/USB_NAME)
when done right-click and choose Eject or Safely Remove

Server Experience
nothing happens automatically
  1. plug in the USB drive
  2. find device name by running one of the commands
    dmesg | tail
    lsblk
  3. create a directory
    sudo mkdir /mnt/usb
  4. mount the drive
    sudo mount /dev/sdc1 /mnt/usb
  5. do what needs to be done
  6. unmount the drive
    sudo umount /mnt/usb
  7. unplug the drive
NTFS and Windows Drive
Windows permissions don't map to Windows
when an NTFS drive is mounted every file
  • is owned by root
  • has executable permissions (777)

with NTFS there is no granular security

Real-World Scenario: Adding a Backup Drive
physically installing a 2TB drive into a computer
  1. shut down the server, screw in the drive, and reboot
  2. identify the drive using lsblk
    for example new drive at sdb
  3. partitioning
    sudo parted /dev/sdb mklabel gpt 
    sudo parted /dev/sdb mkpart primary ext4 0% 100%
  4. formatting
    sudo mkfs.ext4 -L "ServerBackups" /dev/sdb1
  5. preparation
    sudo mkdir /var/backups_drive
  6. testing
    sudo mount /dev/sdb1 /var/backups_drive
    verify size
    df -h
  7. persistence - get the UUID
    sudo blkid
  8. verification
    sudo umount /var/backups_drive 
    sudo mount -a 
    lsblk 

a permanent, dedicated storage volume ready to receive data

Summary
covered
  • layers - physical disk > partition > filesystem > mount point
  • surveying - using lsblk to see tree, using df -h to check for free space
  • filestreams - why ext4 is the standard
  • formatting - using mkfs to prepare a partition
  • mounting - attaching drives temporarially using mount
  • fstab - editing /etc/fstab to make mounts persist
  • repairing - use fsck to repair corrupted drives, unmount drive first

key points
  • lsblk - best command to view disks and partitions
  • /dev/sdX - standard naming convention for drives
  • Mount Point - directory where drive's files appear
  • df -h - checks for free disk space
  • mkfs.ext4 - formats partion with standard Linux filesystem
  • /etc/fstab - config file for persistent mounts, use UUDs
  • fsck - file system check, run only on unmounted drives
  • partioning - use fdisk for small drives, parted for drives over 2TB
index