Linux Partitioning
Summary
- Block Device
- A physical storage device that manages data in fixed-size blocks.
- Examples: HDDs (Hard disk drives), SSDs (solid state drives), and USB flash drives.
- Partition
- A logical division of a block device into smaller, independent sections.
- Examples: GPT (GUID Partition Table, MBR (Master Boot Record).
- Filesystem
- A data structure used by an operating system (OS) to manage and organize data on partitions of a block device.
- Examples: XFS, EXT4, NTFS, FAT32, exFAT, NFS, SMB, APFS, HFS+.
Common Tasks
Partition and Format a New Disk
List partition layout on all block devices
parted -l
Open parted on the block device you want to modify
parted /dev/sdb
View partition table for block device specified above
(parted) print
Create a new partition table
If needed.
(parted) mklabel gpt
Make new XFS partition filling up entire block device
(parted) mkpart hdd xfs 0% 100%
Make a new filesystem on the new partition
mkfs.xfs /dev/sdb1
Find UUID of a partition
lsblk -f
Mount a partition at boot
Edit your /etc/fstab
to add a line like the following:
UUID=5b433ecf-875a-4282-a876-47073fc3a207 /mnt/hdd xfs defaults 0 0
Erase a Disk
dd if=/dev/zero of=/dev/sdx status=progress && sync