fdisk
gives you full control over hard-drives, ssds, flash-drives, and other disks.
fdisk
needs to be run with root privilages
Examples
List Available Disks and Partitions
$ sudo fdisk -l
[sudo] password for joe:
Disk /dev/nvme0n1: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: PM961 NVMe SAMSUNG 512GB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 1D01CEB6-E01F-4B03-9C66-A4A697097A0E
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 1050623 1048576 512M EFI System
/dev/nvme0n1p2 1050624 26216447 25165824 12G Linux swap
/dev/nvme0n1p3 26216448 1000214527 973998080 464.4G Linux root (x86-64)
Format a Disk
Common situations to want to format a disk with fdisk
include
- Performing a fresh Linux installation
- Re-partitioning a mangled flash drive
NOTE: While fdisk
is a powerful tool, keep in mind that it will let you format and wipe
your disks more easily than a GUI tool. Use care so you don’t accidentally delete your data!
NOTE: Make sure to double-check you are modifying the correct disk before applying changes.
$ sudo fdisk /dev/sda
...
Command (m for help):
- Type
m
to get help for all the actions available in the interface - Key Commands
m
- print the help menup
- print the current partition tabled
- delete a partitionn
- add a new partitionq
- quit without applying changesw
- write partition changes to disk (this can destroy the previous partition scheme!)
Once your partitions are set up, you may want to use mkfs
to install a filesystem on it
See also
man fdisk
- https://wiki.archlinux.org/title/Fdisk
du
- estimate directory sizedf
- mountpoint statistics- https://man.archlinux.org/man/mkfs.8