FSTAB
fdisk is a command-line utility used to manipulate disk partition tables on Linux. It's often used for creating, deleting, resizing, and managing disk partitions. Here's a basic cheat sheet for fdisk:
Starting fdisk
- Launch fdisk on a Specific Disk:
Replacesudo fdisk /dev/sdX/dev/sdXwith the specific disk (e.g.,/dev/sda).
Basic fdisk Commands
- m: Display the help menu.
- p: Print the partition table.
- n: Add a new partition.
- d: Delete a partition.
- t: Change a partition's system id (type).
- l: List known partition types.
- w: Write the table to disk and exit.
- q: Quit without saving changes.
Creating a New Partition
- Start fdisk:
sudo fdisk /dev/sdX. - Create Partition: Press
nfor a new partition. - Select Type: Choose
pfor primary orefor extended. - Specify Partition Number: Choose a number (e.g.,
1). - Set the Start and End: Accept the default start sector and specify the end (or size).
- Write and Exit: Press
wto write changes and exit.
Deleting a Partition
- Start fdisk:
sudo fdisk /dev/sdX. - Delete Partition: Press
d. - Select Partition Number: Enter the number of the partition to delete.
- Write and Exit: Press
wto write changes and exit.
Changing a Partition Type
- Start fdisk:
sudo fdisk /dev/sdX. - Change Type: Press
t. - Select Partition: Enter the partition number.
- Enter Hex Code: Enter the hex code for the desired type (use
lto list codes). - Write and Exit: Press
wto write changes and exit.
Tips
- Always back up important data before making changes to disk partitions.
- After changing disk partitions, you may need to format new partitions using
mkfs(e.g.,mkfs.ext4for an ext4 filesystem). - Use
lsblkorfdisk -lto list all block devices and their partition layouts. - Be cautious while using
fdiskas improper use can lead to data loss.