Using fdisk and lsblk to List and Identify Disk Partitions
📖 Scenario: You are managing a Linux system and want to see the details of your disk drives and their partitions. You will use two common commands: fdisk and lsblk. These commands help you understand how your disks are divided and what partitions exist.
🎯 Goal: Learn how to use fdisk to list disk partitions and lsblk to display block devices in a tree format. You will write simple commands to view this information and understand the output.
📋 What You'll Learn
Use the fdisk command with the -l option to list all disk partitions
Use the lsblk command to display block devices in a tree view
Understand how to read the output of both commands
💡 Why This Matters
🌍 Real World
System administrators often need to check disk partitions and usage to manage storage and troubleshoot issues.
💼 Career
Knowing how to use <code>fdisk</code> and <code>lsblk</code> is essential for Linux system administration and automation tasks.
Progress0 / 4 steps
1
List all disk partitions using fdisk
Type the command sudo fdisk -l to list all disk partitions on your system.
Linux CLI
Hint
The fdisk command with -l lists all partitions. You need sudo to run it with the right permissions.
2
Display block devices using lsblk
Type the command lsblk to show all block devices and their partitions in a tree format.
Linux CLI
Hint
The lsblk command shows disks and partitions in a clear tree view.
3
Filter fdisk output for a specific disk
Use the command sudo fdisk -l /dev/sda to list partitions only for the disk /dev/sda.
Linux CLI
Hint
Replace /dev/sda with the disk you want to check. This command shows only that disk's partitions.
4
Show detailed lsblk output with sizes and mount points
Type the command lsblk -o NAME,SIZE,MOUNTPOINT to display device names, sizes, and mount points.
Linux CLI
Hint
The -o option lets you choose which columns to show. Here, you see device names, sizes, and where they are mounted.
Practice
(1/5)
1. What is the primary purpose of the fdisk command in Linux?
easy
A. To display the current directory contents
B. To create and modify disk partitions
C. To list running processes
D. To monitor network connections
Solution
Step 1: Understand the role of fdisk
The fdisk command is used to create, delete, and modify disk partitions on Linux systems.
Step 2: Compare with other commands
Other options like listing directories, processes, or network connections are unrelated to disk partitioning.
Final Answer:
To create and modify disk partitions -> Option B
Quick Check:
fdisk = disk partition tool [OK]
Hint: fdisk = fix disk partitions [OK]
Common Mistakes:
Confusing fdisk with lsblk
Thinking fdisk lists files
Assuming fdisk monitors network
2. Which of the following is the correct syntax to list all block devices using lsblk?
easy
A. lsblk --all
B. lsblk -d
C. lsblk -l
D. lsblk -f
Solution
Step 1: Identify the option to list all devices
The --all option with lsblk lists all devices, including empty ones.
Step 2: Check other options
-d lists only whole disks (no partitions), -l lists in list format, -f shows filesystem info but not all devices.
Final Answer:
lsblk --all -> Option A
Quick Check:
lsblk --all = show all devices [OK]
Hint: --all shows everything in lsblk [OK]
Common Mistakes:
Using -d instead of --all
Confusing -l with --all
Using -f to list devices
3. Given the command output below, what is the size of the partition /dev/sda1?
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
sda1 8:1 0 50G 0 part /
sda2 8:2 0 50G 0 part /home
medium
A. 100G
B. 0G
C. 50G
D. 150G
Solution
Step 1: Read the lsblk output
The line for /dev/sda1 shows a size of 50G under the SIZE column.
Step 2: Understand partition sizes
The disk sda is 100G total, split into two partitions of 50G each.
Final Answer:
50G -> Option C
Quick Check:
/dev/sda1 size = 50G [OK]
Hint: Check SIZE column for partition size [OK]
Common Mistakes:
Confusing disk size with partition size
Adding partition sizes incorrectly
Ignoring the SIZE column
4. You run fdisk /dev/sdb but get the error: cannot open /dev/sdb: Permission denied. What is the most likely cause?
medium
A. The disk /dev/sdb is formatted with ext4
B. The disk /dev/sdb is already mounted
C. The lsblk command is not installed
D. You forgot to run the command as root or with sudo
Solution
Step 1: Understand permission requirements
Running fdisk on disks requires root privileges; without sudo or root, device access is denied.
Step 2: Check other options
Disk being mounted or formatted does not cause 'Permission denied' error; missing lsblk is unrelated.
Final Answer:
You forgot to run the command as root or with sudo -> Option D
Quick Check:
fdisk needs root access [OK]
Hint: Use sudo with fdisk to access disks [OK]
Common Mistakes:
Assuming mounted disk causes 'Permission denied'
Thinking formatting affects fdisk detection
Confusing fdisk errors with lsblk issues
5. You want to create a new partition on /dev/sdc using fdisk. After creating the partition, which command should you run to immediately see the updated partition layout in a tree view?
hard
A. lsblk /dev/sdc
B. fdisk -l /dev/sdc
C. mount /dev/sdc1 /mnt
D. df -h /dev/sdc
Solution
Step 1: Identify command to show partition tree
lsblk displays block devices and partitions in a clear tree format, perfect for checking new partitions.
Step 2: Compare with other commands
fdisk -l lists partitions but not in tree view; mount mounts partitions; df -h shows disk usage, not layout.
Final Answer:
lsblk /dev/sdc -> Option A
Quick Check:
lsblk shows partition tree [OK]
Hint: Use lsblk to view partitions visually [OK]
Common Mistakes:
Using fdisk -l expecting tree view
Trying to mount before checking partitions
Using df to see partition layout
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.