πΎ Linux/Unix: Storage Tools β lsblk
, blkid
, fdisk
, parted
Explained with Examples
π§² Introduction β Why Learn Storage Tools in Linux?
Managing storage devices is a critical task for any Linux administrator. Whether you’re checking disks, identifying filesystems, or partitioning drives, tools like lsblk
, blkid
, fdisk
, and parted
help you inspect, modify, and manage block devices efficiently.
π― In this guide, youβll learn:
- How to view attached storage devices
- How to identify filesystems and partitions
- How to create or modify disk partitions
- Real command outputs and practical use cases
π¦ 1. lsblk
β List Block Devices
β
What is lsblk
?
lsblk
lists information about all available or specified block devices. Itβs commonly used to visualize storage hierarchies.
π οΈ Syntax:
lsblk [options]
πΉ Common Options:
Option | Description |
---|---|
-f | Show filesystems |
-o | Specify columns to display |
-a | List all devices (including empty) |
π§ͺ Example 1: Show all block devices
lsblk
π€ Output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
ββsda1 8:1 0 48G 0 part /
ββsda2 8:2 0 2G 0 part [SWAP]
π§ͺ Example 2: Show filesystem info
lsblk -f
π€ Output:
NAME FSTYPE LABEL UUID MOUNTPOINT
sda1 ext4 9a1f-123a-b45f-xxxx /
sda2 swap 1234-5678 [SWAP]
π 2. blkid
β Display Block Device Attributes
β
What is blkid
?
blkid
displays UUIDs and filesystem types for block devices. Useful for fstab configuration and bootloader referencing.
π οΈ Syntax:
blkid [device]
π§ͺ Example 1: View all block IDs
blkid
π€ Output:
/dev/sda1: UUID="9a1f-123a-b45f-xxxx" TYPE="ext4"
/dev/sda2: UUID="1234-5678" TYPE="swap"
π§ UUIDs are preferred in /etc/fstab
because they are persistent across boots.
π§© 3. fdisk
β Partition Table Manager (MBR)
β
What is fdisk
?
fdisk
is a powerful utility to view and modify partitions on disks using the MBR partitioning scheme.
π οΈ Syntax:
sudo fdisk /dev/sdX
Replace
/dev/sdX
with your actual disk (e.g.,/dev/sda
).
π§ͺ Example: Start interactive partitioning
sudo fdisk /dev/sda
π€ Menu (inside fdisk prompt):
Command (m for help): m
Command (m for help): p # Print partition table
Command (m for help): n # Add new partition
Command (m for help): d # Delete partition
Command (m for help): w # Write changes and exit
π§ Always back up before modifying partitions.
π 4. parted
β Partition Tool (MBR & GPT)
β
What is parted
?
parted
is a more advanced partition tool supporting both MBR and GPT partition tables. Itβs also script-friendly.
π οΈ Syntax:
sudo parted /dev/sdX
π§ͺ Example: Show partition layout
sudo parted /dev/sda print
π€ Output:
Model: ATA VBOX HARDDISK
Disk /dev/sda: 50GB
Partition Table: gpt
Number Start End Size File system Name Flags
1 1049kB 49.0GB 49.0GB ext4
2 49.0GB 50.0GB 1.0GB linux-swap
π§ parted
supports larger disks and modern GPT formatting.
π§ Comparison Table
Tool | Purpose | GPT Support | GUI Required | Common Use Case |
---|---|---|---|---|
lsblk | View block device tree | β | β | Quick overview of disks |
blkid | Get filesystem UUID/type | β | β | fstab editing, UUID lookup |
fdisk | Partition disk (MBR only) | β | β | Legacy partition management |
parted | Partition disk (MBR/GPT) | β | β | Modern systems, automation |
π Summary β Recap & Next Steps
Linux offers powerful tools to inspect, configure, and manage storage devices and partitions. Whether you’re preparing disks, identifying UUIDs, or editing partitions, these commands are essential for system setup and maintenance.
π Key Takeaways:
- Use
lsblk
to view block devices and mount points - Use
blkid
to get UUID and filesystem info - Use
fdisk
for interactive MBR-based partitioning - Use
parted
for GPT partitioning and modern disk layouts
β FAQs
β What is the difference between lsblk
and blkid
?
β
lsblk
shows a device tree and mount points. blkid
shows filesystem types and UUIDs.
β Which tool supports GPT disks?
β
Use parted
or gdisk
for GPT. fdisk
supports MBR only.
β Is it safe to use fdisk
on a mounted partition?
β No. Unmount partitions before making changes.
β Can I script disk partitioning with parted
?
β
Yes. parted
supports non-interactive commands like:
parted -s /dev/sdb mklabel gpt mkpart primary ext4 1MiB 100%
β How do I find my swap partition?
β
Use:
lsblk -f | grep swap
or
swapon --show
Share Now :