Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
fdisk
is a command-line utility in Linux that is used to manage disk partitions. It allows you to create, delete, and modify partitions on hard drives, solid-state drives, and other disk devices.
Here's a tutorial on the Linux fdisk
command:
Display available disk devices:
Use the lsblk
or fdisk
command to list all available disk devices:
lsblk
or
sudo fdisk -l
Start fdisk
on a specific disk device:
To work with a specific disk device, run fdisk
as the root user. Replace /dev/sdX
with the device identifier for your disk (e.g., /dev/sda
, /dev/sdb
):
sudo fdisk /dev/sdX
This will start the fdisk
utility in interactive mode for the specified disk.
Common fdisk
commands:
p
: Print the current partition tablen
: Create a new partitiond
: Delete a partitiont
: Change a partition's typew
: Write the changes to the disk and exitq
: Quit without saving changesCreate a new partition:
n
and press Enter to create a new partitionw
and press Enter to write the changes to the diskDelete a partition:
d
and press Enter to delete a partitionw
and press Enter to write the changes to the diskChange a partition's type:
t
and press Enter to change the partition type83
for Linux, 82
for Linux swap)w
and press Enter to write the changes to the diskExit fdisk
without saving changes:
If you made a mistake or want to cancel the changes, type q
and press Enter to quit fdisk
without saving any changes.
Remember that modifying partitions can lead to data loss, so always ensure that you have a backup of your data before using fdisk
. By understanding the fdisk
command and its various options, you can effectively manage disk partitions on your Linux system.
How to use fdisk command in Linux:
The fdisk
command is used for disk partitioning. To use fdisk
:
sudo fdisk /dev/sdX
Replace /dev/sdX
with the appropriate disk identifier.
Formatting partitions after using fdisk: After partitioning, format the partitions using a file system. For example, to format a partition as ext4:
sudo mkfs.ext4 /dev/sdXY
Replace /dev/sdXY
with the appropriate partition identifier.