Disk Architecture in Linux
Linux represents disks as device files in /dev/:
| Device | Type |
|---|---|
/dev/sda | First SATA/SCSI disk |
/dev/sdb | Second SATA/SCSI disk |
/dev/nvme0n1 | First NVMe disk |
/dev/sda1 | First partition on sda |
Listing Disks and Partitions
lsblk — Block Devices
lsblkOutput:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:1 0 8G 0 disk
├─nvme0n1p1 259:3 0 7.9G 0 part /
├─nvme0n1p14 259:4 0 4M 0 part
└─nvme0n1p15 259:5 0 106M 0 part /boot/efi
nvme1n1 259:0 0 5G 0 disk
fdisk — Detailed Disk Info
sudo fdisk -lFile System Info
# Show file system types
sudo lsblk -f
# Check specific partition
sudo blkid /dev/nvme0n1p1File Systems
A file system organizes data on a partition. You must format a partition before using it.
| File System | Description | Best For |
|---|---|---|
| ext4 | Standard Linux FS, journaling | General purpose |
| xfs | High-performance, scalable | Large files, databases |
| btrfs | Copy-on-write, snapshots | Advanced features |
| vfat | FAT32, cross-platform | Boot partitions, USB |
Creating Partitions with fdisk
# Open fdisk on a disk
sudo fdisk /dev/nvme1n1Interactive commands:
| Key | Action |
|---|---|
n | Create new partition |
p | Print partition table |
d | Delete a partition |
t | Change partition type |
w | Write changes and exit |
q | Quit without saving |
Step-by-Step: Create a 2GB Partition
sudo fdisk /dev/nvme1n1Command: n # New partition
Select: p # Primary
Partition number: 1 # First partition
First sector: Enter # Accept default
Last sector: +2G # 2GB size
Command: w # Write and exit
Verify:
lsblkFormatting Partitions
Create a file system on the new partition:
# Format as ext4
sudo mkfs -t ext4 /dev/nvme1n1p1
# Format as xfs
sudo mkfs -t xfs /dev/nvme1n1p1
# Add a label
sudo e2label /dev/nvme1n1p1 "DATA"Mount Points
A mount point is a directory where a partition's contents become accessible.
Mounting a Partition
# Create mount point
sudo mkdir -p /data
# Mount the partition
sudo mount /dev/nvme1n1p1 /data
# Verify
df -hT | grep dataUnmounting
sudo umount /data
# or
sudo umount /dev/nvme1n1p1⚠️
You cannot unmount a partition if any process is using files on it. Use lsof /data to find which processes are accessing it.
Checking Mounted File Systems
# All mounted file systems
df -hT
# Specific mount
mount | grep nvme1n1Persistent Mounts with /etc/fstab
Mounts created with mount are lost on reboot. Make them persistent:
# View current fstab
cat /etc/fstabExample fstab entry:
# <device> <mount> <type> <options> <dump> <fsck>
UUID=b78a0d9e-5657... /data ext4 defaults 0 2
LABEL=DATA /data ext4 defaults 0 2
Columns Explained
| Column | Purpose |
|---|---|
| Device | UUID, LABEL, or device path |
| Mount point | Directory to mount on |
| Type | File system type (ext4, xfs) |
| Options | Mount options (defaults, ro, noexec) |
| Dump | Backup flag (0 = no) |
| Fsck | Check order (0 = skip, 1 = root, 2 = others) |
Adding a Persistent Mount
# Get the UUID
sudo blkid /dev/nvme1n1p1
# Edit fstab
sudo nano /etc/fstab
# Add line:
UUID=your-uuid-here /data ext4 defaults 0 2
# Test without rebooting
sudo mount -a💡
Always use UUID in fstab instead of device names like /dev/sdb1. Device names can change between reboots, but UUIDs are permanent.
Deleting Partitions
# Unmount first
sudo umount /dev/nvme1n1p1
# Open fdisk
sudo fdisk /dev/nvme1n1
# Delete partition
Command: d
Command: wChecking File System Health
# Check file system (must be unmounted)
sudo umount /dev/nvme1n1p1
sudo fsck /dev/nvme1n1p1
# Check and repair
sudo fsck -y /dev/nvme1n1p1Summary
lsblkandfdisk -llist disks and partitionsfdiskcreates/deletes partitions interactivelymkfs -t ext4formats partitions with a file systemmount/umountattach/detach partitions to directories/etc/fstabmakes mounts persistent across reboots- Always use UUID in fstab for reliability
fsckchecks and repairs file systems
Next Steps
Next, we'll cover LVM (Logical Volume Manager) — flexible storage that can be resized without downtime.