What if a few simple commands could save your data and sanity when managing disks?
Why fdisk and lsblk in Linux CLI? - Purpose & Use Cases
Imagine you just bought a new hard drive and want to use it on your Linux computer. You try to figure out its size, partitions, and how to set it up by opening multiple windows, guessing device names, and writing notes on paper.
Doing this by hand is slow and confusing. You might mix up device names, miss important details, or accidentally delete data. Without clear commands, it's easy to make mistakes that can cause data loss or system problems.
Using fdisk and lsblk commands lets you quickly see all disks and partitions, and safely create or modify partitions. They give clear, organized information and simple interactive tools to manage disks without guesswork.
cat /proc/partitions
ls /dev/sd*
# guess which device is new
lsblk
fdisk -l
# see all disks and partitions clearly
You can confidently manage disk partitions and storage devices, making your system setup faster, safer, and less stressful.
When installing a new Linux system, you use lsblk to list all drives and fdisk to create partitions for system, swap, and data, ensuring everything is correctly set up before installation.
Manual disk management is confusing and risky.
fdisk and lsblk provide clear, safe ways to view and edit disk partitions.
They save time and prevent costly mistakes when handling storage devices.
Practice
fdisk command in Linux?Solution
Step 1: Understand the role of fdisk
Thefdiskcommand 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 BQuick Check:
fdisk = disk partition tool [OK]
- Confusing fdisk with lsblk
- Thinking fdisk lists files
- Assuming fdisk monitors network
lsblk?Solution
Step 1: Identify the option to list all devices
The--alloption withlsblklists all devices, including empty ones.Step 2: Check other options
-dlists only whole disks (no partitions),-llists in list format,-fshows filesystem info but not all devices.Final Answer:
lsblk --all -> Option AQuick Check:
lsblk --all = show all devices [OK]
- Using -d instead of --all
- Confusing -l with --all
- Using -f to list devices
/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
Solution
Step 1: Read the lsblk output
The line for/dev/sda1shows a size of 50G under the SIZE column.Step 2: Understand partition sizes
The disksdais 100G total, split into two partitions of 50G each.Final Answer:
50G -> Option CQuick Check:
/dev/sda1 size = 50G [OK]
- Confusing disk size with partition size
- Adding partition sizes incorrectly
- Ignoring the SIZE column
fdisk /dev/sdb but get the error: cannot open /dev/sdb: Permission denied. What is the most likely cause?Solution
Step 1: Understand permission requirements
Runningfdiskon 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 DQuick Check:
fdisk needs root access [OK]
- Assuming mounted disk causes 'Permission denied'
- Thinking formatting affects fdisk detection
- Confusing fdisk errors with lsblk issues
/dev/sdc using fdisk. After creating the partition, which command should you run to immediately see the updated partition layout in a tree view?Solution
Step 1: Identify command to show partition tree
lsblkdisplays block devices and partitions in a clear tree format, perfect for checking new partitions.Step 2: Compare with other commands
fdisk -llists partitions but not in tree view;mountmounts partitions;df -hshows disk usage, not layout.Final Answer:
lsblk /dev/sdc -> Option AQuick Check:
lsblk shows partition tree [OK]
- Using fdisk -l expecting tree view
- Trying to mount before checking partitions
- Using df to see partition layout
Ready to prove it?
Pass the test and this pattern moves unknown
