| 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
Layer 2: The Partitions (The Rooms) divide the drive into logical sections names appear as numbers appended to the device name
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 Devicescommand lsblkoutput 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 diskstructure
The Technical View: sudo fdisk l
fdisk is a partition manipulation tool-l flag provides deep technical details
fdisk -l The Free Space View: df
df stands for disk freeby 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 sizesrun alone du lists every file recursively use to summarize specific folders sudo du -sh /var/log
|
||||||||||||||||||||||||||||||
| Filesystem Types: ext4, XFS, Btrfs, FAT32, NTFS | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| Partitioning Disks: fdisk, parted | ||||||||||||||||||||||||||||||
|
Using fdisk (for MBR and disks under 2TB)
classic toolmenued with single letter commands
Using parted (for GPT and disks over 2TB)
old MBR partition cannot handle drives > 2TBuse GPT (guid partition table) sudo parted /dev/sdb (parted) mklabl gpt (parted) mkpart primary ext4 0% 100% (parted) quitparted 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
Navigate to the Partition
cd /mnt/databy default root owns the mount point to change permissions sudo chown -R <user>:<group> /mnt/data Unmounting
sudo umount /mnt/datacan'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/fstabsystemd reads the file at boot to know drives to mount The Danger
if a syntax error occurs in /etc/fstab, the box might not bootbox will enter Emergency Mode always backup /etc/fstab before making any edits Identifying the Drive (UUID)
could put /dev/sdb1 in the fstab filea 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 blkidoutput /dev/sdb1: LABEL="Backups" UUID="550e8400-e29b-41d4-a716-446655440000" TYPE="ext4"copy UUID w/o quotes Editing fstab
sudo nano /etc/fstabfile 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
Test Before Rebooting
run
sudo mount atells 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
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/sdb1to check the root drive there are two options
|
||||||||||||||||||||||||||||||
| 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 Windowsan 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
NTFS and Windows Drive
Windows permissions don't map to Windowswhen an NTFS drive is mounted every file
with NTFS there is no granular security |
||||||||||||||||||||||||||||||
| Real-World Scenario: Adding a Backup Drive | ||||||||||||||||||||||||||||||
physically installing a 2TB drive into a computer
a permanent, dedicated storage volume ready to receive data |
||||||||||||||||||||||||||||||
| Summary | ||||||||||||||||||||||||||||||
covered
key points
|