Getting older, not necessarily wiser!
A common task in any Operating System (OS) is setting up a drive, be it SSS, mechanical, or USB. Most OS’s have a graphical utility for this purpose, and Linux is no exception, with several available. However, you should know how to setup and partition your drive form the command line with a program like fdisk.
The fdisk command allows us to view, manipulate, and delete partitions on any drive.
The fdisk program has the following syntax.
fdisk [options] device
fdisk -l [device]
The two most common ways of using the program are fdisk -l and fdisk device. When run with a device, fdisk enters a menu driven mode.
The fdisk program is one of a hand full of command line utilities for partitioning a drive. The first version It was introduced in 1993. In Linux fdisk is part of the util-linux package.
One of the more common options is -l, which lists partition tables of a specified device, or when no device is specified then all devices found in the /proc/partition directory.
This will provide information on each device including the full path (needed to open individual devices), as well as information about existing partitions on each device.
The other common option for execution is with a device path (see above example).
Note the full path to the device is required. Device naming will depend on the type of device. Standard SATA drives are listed as sda through sdz. In this example, sdc is the third drive on the system. M2 drives are generally listed as nvme1, nvme2, ect. This command will open a menu system in fdisk. The following are some of the more common menu options.
m: lists all menu options available.
z: reverse of above, reverts from GPT back to MBR.
p: Print partition table for device.
d: delete a partition.
n: create a new partition.
t: set a partition type (for example type 1 is EFI, type 19 is Linux swap, type 20 is Linux ext). You can list all partition types form here.
w: this writes all changes to your drive, then exits the program.
Some of the more common command line op0tions for fdisk are as follows.
-l: list all drives
-h: display help text
-L: colorize output (shell/monitor must support this)
-x: similar to -l, but with more detail
-v: version of fdisk
Refer to the manpage for a complete list of options.
This has been a quick overview of the fdisk command and some of the more common options/usage. It should cover most things an average user would need to do. Please refer to the manpage for your distribution for a complete list of all options and features.