0
0
Linux CLIscripting~10 mins

fdisk and lsblk in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - fdisk and lsblk
Start
Run lsblk
Display block devices
Run fdisk -l
Display detailed partition info
User decides next step
Create/Delete partitions with fdisk
Exit
First, lsblk lists block devices simply. Then fdisk -l shows detailed partition info. User can then manage partitions with fdisk.
Execution Sample
Linux CLI
lsblk
fdisk -l
List block devices and show detailed partition info.
Execution Table
StepCommandOutput SummaryDetails Shown
1lsblkLists block devices in tree formShows device names, sizes, types, mount points
2fdisk -lLists detailed partition infoShows device, start/end sectors, size, type, boot flag
3User views infoDecides on partition changesNo output, user action step
4fdisk /dev/sdx (optional)Starts fdisk interactive modeUser can create/delete partitions
5ExitEnd of processNo output
💡 User finishes viewing or editing partitions and exits fdisk.
Variable Tracker
VariableStartAfter lsblkAfter fdisk -lAfter fdisk interactiveFinal
block_devicesunknownlist of devices with sizes and mount pointsdetailed partition info per deviceupdated partition table if changedfinal partition table
Key Moments - 3 Insights
Why does lsblk show a simple tree but fdisk -l shows detailed numbers?
lsblk shows a quick overview of devices and mounts (see execution_table step 1), while fdisk -l shows detailed partition layout with sectors and types (step 2). They serve different purposes.
Can I use fdisk without lsblk first?
Yes, but lsblk helps you see devices and mount points quickly before making changes with fdisk (see execution_table step 1 and 4).
What happens if I change partitions in fdisk?
The partition table updates after you write changes in fdisk interactive mode (step 4). This affects the block_devices variable (variable_tracker).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what does the lsblk command show at step 1?
ADetailed partition sectors and types
BBlock devices in a tree with sizes and mount points
CInteractive partition editing
DNo output
💡 Hint
Check execution_table row 1 under Output Summary
At which step does the user start editing partitions interactively?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at execution_table row 4 Command and Output Summary
If no changes are made in fdisk interactive mode, what is the final state of block_devices?
AList of devices with old partition info
BUnknown
CUpdated partition table
DEmpty
💡 Hint
See variable_tracker row block_devices final column
Concept Snapshot
lsblk shows block devices simply in a tree with sizes and mount points.
fdisk -l lists detailed partition info including sectors and types.
Use fdisk interactively to create or delete partitions.
Always check lsblk before fdisk to avoid mistakes.
Exit fdisk to save or discard changes.
Full Transcript
This visual execution shows how lsblk and fdisk commands work together. First, lsblk lists block devices in a simple tree format showing device names, sizes, types, and mount points. Then fdisk -l lists detailed partition information including start and end sectors, sizes, partition types, and boot flags. The user can then decide to run fdisk interactively to create or delete partitions. The variable block_devices changes from unknown to a list of devices after lsblk, then to detailed partition info after fdisk -l, and finally updates if partitions are changed in fdisk. Key moments include understanding the difference between lsblk and fdisk -l outputs, the role of lsblk before fdisk, and what happens when partitions are changed. The quizzes test understanding of command outputs and steps. The snapshot summarizes the commands and their usage.