Linux: Disk Partitioning and Formatting a Filesystem 🐧💻
🛠️ Partitioning with parted
parted
Overview: In Linux, the
parted
tool is used for disk partitioning and supports both MBR (Master Boot Record) and GPT (GUID Partition Table) partitioning schemes.Modes:
Interactive Mode: Launches a separate program for user interaction.
Command Line Mode: Allows running commands directly in the shell.
🔍 Viewing Disks
Command:
sudo parted -l
Lists all connected disks and their partitions.
Example Output:
/dev/sda
: 128GB disk with existing partitions./dev/sdb
: 8GB USB drive with no partitions yet.
🛠️ Partitioning a Disk
Selecting the Disk:
Use:
sudo parted /dev/sdb
This starts the
parted
tool for the selected disk.
Creating a Partition Table:
Command:
mklabel gpt
Sets the partition table to GPT.
Creating Partitions:
Command:
mkpart <type> <filesystem> <start> <end>
Type: Partition type (primary for GPT).
Filesystem: The file system to format (e.g., ext4).
Start/End: Defines partition size.
Example:
mkpart primary ext4 1MiB 5GiB
creates a 5GiB partition.
Formatting the Partition:
Command:
sudo mkfs -t ext4 /dev/sdb1
Formats the newly created partition with the ext4 file system.
🧮 Data Measurement
Exact vs. Estimated Sizes:
Mebibyte (MiB): 1 MiB = 1024^2 bytes.
Gibibyte (GiB): 1 GiB = 1024^3 bytes.
Kilobyte (KB) and Gigabyte (GB) use 1000 bytes and 1000^3 bytes, respectively.
📁 Mounting the Filesystem
Final Step: To use the disk for reading and writing files, you must mount the file system to a directory.
Command:
mount /dev/sdb1 /mnt/your_mount_point
⚠️ Caution
Be cautious with
parted
as incorrect modifications can lead to data loss. Always double-check the disk and partition details before proceeding.
Partitioning and formatting a disk with Linux's parted
tool can efficiently manage and prepare storage, but requires careful handling to avoid mistakes. 🚀🔧
Last updated