Partitioning and Formatting Safety
Quick answer
Partitioning defines ranges on a device; formatting writes filesystem metadata. Both can destroy existing data if directed at the wrong target. Practice only with a fresh regular image file or a verified disposable VM disk.
Prepare the practice environment
Run python3 lab-fixtures/storage/setup.py from the extracted root as an ordinary user. Enter the printed fresh private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. Only disposable regular files may be written. Optional examples require an authorized snapshot VM. Never substitute actual devices or modify mounts, system configuration or active swap. Review the lab guide.
How it works
GPT and MBR are partition-table formats, not filesystems. GPT is commonly used on modern systems. Before any mutation, verify the VM snapshot, disk attachment, capacity, serial/identity and absence of mounts or valuable data. A regular image file can hold a filesystem without a partition table. Formatting tools are filesystem-specific; mkfs.ext4 creates ext4 metadata. Never use a real /dev path in these exercises. Review proposed partition changes before writing; rollback by discarding the image or restoring the authorized VM snapshot.
Changing a partition boundary changes the block range offered to its contents; creating a filesystem writes new filesystem metadata into a selected range. Neither action is a backup, and neither automatically adjusts every other storage layer. In the regular-file fixture, keep the original and the experimental copy distinct. Treat a plan or dry run as a preview, not authorization to write to a physical device.
Try the examples
test ! -e ./disk.img && test ! -L ./disk.img || exit 1(set -o noclobber; : > ./disk.img) || exit 1truncate -s 33554432 ./disk.img || exit 1test -f ./disk.img && test ! -L ./disk.img || exit 1stat -c '%s' ./disk.imgThis creates only a regular sparse file, not a disk or filesystem.
Expected stdout:
33554432test ! -e ./disk.img && test ! -L ./disk.img || exit 1(set -o noclobber; : > ./disk.img) || exit 1truncate -s 33554432 ./disk.img || exit 1test -f ./disk.img && test ! -L ./disk.img || exit 1fdisk -l ./disk.imgVM only with fdisk installed. Blank image listing does not create a partition table.
Manual example; not executed locally. Follow its stated environment restrictions.
test ! -e ./disk.img && test ! -L ./disk.img || exit 1(set -o noclobber; : > ./disk.img) || exit 1truncate -s 33554432 ./disk.img || exit 1test -f ./disk.img && test ! -L ./disk.img || exit 1mkfs.ext4 -L BM_LAB ./disk.imgblkid -p -s TYPE -o value ./disk.imgVM only; expect ext4 after successful formatting of this fresh image, not a real device. Do not force formatting if it refuses.
Manual example; not executed locally. Follow its stated environment restrictions.
Common mistakes
Never reuse commands by substituting a real disk path. Do not assume a blank partition table means a disk is empty.
Practice
Write a target-verification checklist, create a fresh 32 MiB regular image and verify its type and size. In an authorized VM, review partition-tool output before any write.
Related references
Study: fdisk, parted, mkfs-ext4. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Partitioning and formatting safety — Knowledge Check
Apply storage concepts to synthetic fixtures and VM-only scenarios.
GPT is what?
What change does mkfs.ext4 make to a verified disposable image?
Safest lab target?
Before a partition write?