Disks and Partitions: lsblk, fdisk, parted

Before you can use a disk, Linux needs to know about it, partition it, and put a filesystem on it. The first step is always inspection: what disks are connected and how are they currently set up?

lsblk: see all block devices

This is the first command to run when working with disks:

lsblk                # tree view of all disks and partitions
lsblk -f             # show filesystems and labels
lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT,UUID
lsblk -p             # full /dev/ paths

Sample output:

NAME   SIZE  FSTYPE   MOUNTPOINT
sda    500G
├─sda1 1G    vfat     /boot/efi
├─sda2 100G  ext4     /
└─sda3 399G  ext4     /home
sdb    1T
└─sdb1 1T    ext4     /data

df: disk space USAGE

df -h                # human-readable
df -hT               # also show filesystem type
df -i                # inode usage (for "no space" but disk shows free)

du: directory sizes

du -sh ~/Downloads               # total of one folder
du -sh */                        # each subdir of current
du -sh * 2>/dev/null | sort -h   # sort by size
du -ah . | sort -hr | head -20   # top 20 biggest files+dirs

fdisk and gdisk: partition disks

fdisk works for MBR-style disks; gdisk for GPT (modern, bigger disks). Most modern systems use GPT.

sudo fdisk -l                   # list all disks and partitions
sudo fdisk /dev/sdb             # interactive partitioning of sdb

Inside fdisk:

p     print partition table
n     new partition
d     delete partition
t     change partition type
w     write changes (commits everything)
q     quit without saving

parted: scriptable partitioning

Better for automation; supports both MBR and GPT.

sudo parted /dev/sdb

# Inside parted
print
mklabel gpt
mkpart primary ext4 0% 100%
print
quit

# Or one-shot
sudo parted /dev/sdb mklabel gpt
sudo parted /dev/sdb mkpart primary ext4 0% 100%

Make a filesystem (mkfs)

sudo mkfs.ext4 /dev/sdb1         # ext4 (standard Linux)
sudo mkfs.xfs /dev/sdb1          # XFS (great for big files)
sudo mkfs.btrfs /dev/sdb1        # btrfs (snapshots, COW)
sudo mkfs.vfat /dev/sdb1         # FAT32 (USB sticks, EFI)
sudo mkfs.ntfs /dev/sdb1         # NTFS (Windows compat)

# Add a label
sudo mkfs.ext4 -L mydata /dev/sdb1

Get UUIDs (for fstab)

blkid                   # all devices with UUIDs
lsblk -f                # also shows UUIDs and labels
ls -l /dev/disk/by-uuid/

Mount a filesystem

Temporary mount (gone on reboot):

sudo mkdir -p /mnt/data
sudo mount /dev/sdb1 /mnt/data

# Verify
df -h /mnt/data
mount | grep /mnt/data

# Unmount
sudo umount /mnt/data

Permanent mount: edit /etc/fstab (covered in the next article).

Add a new disk: full workflow

# 1. Find it
sudo lsblk      # confirm new disk shows up (e.g. /dev/sdc)

# 2. Partition it (one full-disk partition)
sudo parted /dev/sdc mklabel gpt
sudo parted /dev/sdc mkpart primary ext4 0% 100%

# 3. Format
sudo mkfs.ext4 -L newdata /dev/sdc1

# 4. Mount temporarily to test
sudo mkdir -p /mnt/newdata
sudo mount /dev/sdc1 /mnt/newdata
df -h /mnt/newdata

# 5. Add to fstab for permanent mount
echo "UUID=$(blkid -s UUID -o value /dev/sdc1) /data ext4 defaults 0 2" | 
    sudo tee -a /etc/fstab
sudo umount /mnt/newdata
sudo mount -a   # mount everything in fstab; verifies syntax

Resize / grow a partition

Cloud workflow: increase disk size in your provider’s console, then on the VM:

# Refresh kernel's view of the disk
sudo growpart /dev/sda 1

# Resize the filesystem
sudo resize2fs /dev/sda1            # ext4
sudo xfs_growfs /                    # XFS

Check filesystem health

# Read-only check (must be unmounted)
sudo umount /dev/sdb1
sudo fsck -n /dev/sdb1

# Force a check at next boot
sudo touch /forcefsck

Common mistakes

  • Working on the wrong disk in fdisk — always verify with lsblk first. /dev/sda is usually your boot disk.
  • Editing /etc/fstab incorrectly and then rebooting — system fails to boot. Always run sudo mount -a to validate before reboot.
  • Using device names (/dev/sdb1) in fstab — these can change. Use UUIDs.
  • Forgetting w in fdisk — your changes weren’t written.

What to learn next

Mounting and /etc/fstab — making your filesystems available automatically every boot. Up next.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *