What happens when a disk is formatted?

Formatting a disk prepares it for storing files by erasing existing data and setting up a file system. When you format a disk, the operating system erases all existing files and writes new metadata to organize the storage space. Depending on the operating system and file system, formatting may also check for disk errors and reserve space for the file system.

Quick Answers

– Formatting erases existing data from a disk and prepares it for new files.
– The process writes new metadata to set up a file system to organize the disk space.

– Different operating systems and file systems handle formatting differently.
– Formatting checks for disk errors and reserves space for the file system.
– After formatting, the disk is empty and ready for new files to be written.

How Formatting Works

When a disk is formatted, the basic process includes:

  1. Existing data is overwritten – Any files or folders on the disk are erased by overwriting the data.
  2. Partition table is created – The partition table defines separate sections on the disk.
  3. File system metadata is written – Metadata such as inodes in Unix or file allocation tables in FAT are generated.
  4. Disk areas are checked for defects – The surface is scanned for bad sectors.
  5. Space is reserved for the file system – Some space is set aside for the file system to use for operations.

The exact steps depend on the operating system and file system. For example, Windows uses NTFS or FAT32 file systems while Linux uses Ext4 or XFS. But in general, the OS erases old data, sets up data structures to manage files, checks for errors, and reserves space.

Erasing Existing Data

When formatting a disk, the very first thing that happens is overwriting existing data. The OS will write zeros or random bits to the entire disk to replace any previous files or folders. This prevents old data from being accessible after the format.

Some file recovery is possible after a quick format since it may not overwrite all disk sectors. But a full format will scrub the disk clean by overwriting every sector. You won’t be able to recover any old files after a full format.

Creating a Partition Table

The partition table is metadata that divides the physical disk into logical sections called partitions. This allows you to have multiple partitions on one disk, each acting like a separate disk. The OS and partitioning tool create the partition table to define partitions sizes and types.

Common partition table types:

  • MBR (Master Boot Record) – Older style used on Windows and Linux. Limited to 4 primary partitions.
  • GPT (GUID Partition Table) – Newer style used on Windows and Linux. Supports unlimited partitions.
  • APM (Apple Partition Map) – Used on Macs. Based on MBR but with Apple specific structures.

The partition structure is initialized when the disk is formatted and helps logical partitions to be defined.

Writing File System Metadata

The most crucial part of formatting is writing the file system metadata. This metadata is used to structure and organize the disk so that files can be stored and retrieved in an orderly fashion.

For example, FAT16 file systems use file allocation tables to track used and free space. NTFS uses a master file table with entries for every file and directory. Ext4 uses inodes to index each file’s data blocks.

The format process generates all the data structures, tables, and rules required by the particular file system to coordinate file storage. This metadata is written to special reserved areas like the boot sector so it can persist.

Checking for Disk Errors

As part of formatting, most file systems will do a scan of the disk to check for bad sectors. If any defects are detected, those sectors are marked in the metadata as bad and won’t be used. This helps avoid storing data in parts of the disk that are unusable.

Some file systems like NTFS have self-healing features that can detect bad sector during normal operation and remap data to good regions. The initial format scan provides the first mapping of good vs bad areas.

Reserving Space for the File System

Most file systems reserve some storage space that is not available to users. This space can be used for things like journalling, metadata backups, or future expansion.

For example, Ext4 reserves 5% of disk space for root users and 1% for normal users. NTFS reserves space for metadata mirrors and backups. This ensures the file system always has space for internal operations.

The exact amount and location depend on the file system. But reformatting will regenerate this reserved space as needed by the OS.

Formatting Options

There are a few key formatting options available in most operating systems:

Quick Format

A quick format simply creates a new empty file system without erasing existing data. It rewrites metadata while leaving old data in place. This is faster but less secure since old data can still be recovered.

Full Format

Also called slow format, this overwrites all disk sectors before writing new file system metadata. No existing data will be recoverable after a full format since it’s completely overwritten. It takes longer but is more secure.

File System Type

You can choose which file system to use when formatting like NTFS for Windows and Ext4 for Linux. Different file systems have pros and cons for things like performance and features.

Cluster Size

File systems break disks into chunks called clusters or allocation units. The cluster size can be configured during formatting for optimization. A smaller cluster size reduces wasted space but requires more metadata.

Formatting Disk Types

The steps to format common disk types:

Hard Disk Drives (HDD)

HDDs can be formatted using tools built into Windows, MacOS, and Linux. Connect the HDD, launch the computer’s disk utility, select format, pick options, and start the process.

Solid State Drives (SSD)

SSDs are formatted using the same operating system tools. But SSDs typically use different file systems optimized for flash memory like Ext4, FAT32, or exFAT. Enable TRIM to improve performance.

USB Flash Drives

USB drives can be formatted with Quick Format in Windows or disk utility tools in MacOS and Linux. Be sure to back up any files on the USB drive first before formatting.

SD Cards

SD cards and other removable media use the SD formatter tool or OS disk utilities. Beware that formatting may reduce the lifespan of SD cards that have a limited number of rewrite cycles.

External Hard Drives

External drives connect via USB or eSATA and can be formatted like internal drives using Windows, MacOS, or Linux tools. Be sure to check for model specific format requirements.

Formatting Risks and Dangers

Formatting has some risks including:

  • Existing data is erased – All files and folders are wiped from the disk.
  • Accidental formatting of wrong disk – Causing data loss.
  • File system corruption – Power loss during format can corrupt the file system.
  • Wear on SSDs – Excessive formatting reduces flash longevity.

Always backup data before formatting. Be careful to select the correct disk and don’t interrupt the formatting process.

Recovering Data After Formatting

If you lost important files due to formatting, recovery is possible in some cases:

  • After quick format – Files may still reside on disk until overwritten.
  • Using file recovery software – Specialized tools can resurrect deleted files.
  • From backups – Retrieve copies of your data from backups.
  • Sending to data recovery pros – Expensive but can work on highly damaged disks.

However, prevention is key. Having good backups means formatting isn’t catastrophic. Make regular backup copies of critical data before formatting.

Conclusion

Formatting is an essential task for configuring new disks and wiping old ones. The process involves:

  • Overwriting existing data
  • Creating partition structures
  • Writing new file system metadata
  • Scanning for bad sectors
  • Reserving space for the OS

This prepares the disk for reliable file storage based on the file system chosen. Be aware of risks like data loss and know recovery options. With proper care, formatting is a quick way to reset a disk.