πŸ’Ύ Linux/Unix: Storage, Archiving & Compression
Estimated reading: 4 minutes 23 views

πŸ’Ύ 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:

OptionDescription
-fShow filesystems
-oSpecify columns to display
-aList 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

ToolPurposeGPT SupportGUI RequiredCommon Use Case
lsblkView block device treeβœ…βŒQuick overview of disks
blkidGet filesystem UUID/typeβœ…βŒfstab editing, UUID lookup
fdiskPartition disk (MBR only)❌❌Legacy partition management
partedPartition 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 :

Leave a Reply

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

Share

πŸ”΅ Linux/Unix: Storage Tools (lsblk, blkid, fdisk, parted)

Or Copy Link

CONTENTS
Scroll to Top