How to Zero Out Used Space on a Storage Drive

Abstract: Securely erase recoverable data from free space on a Linux drive by writing zeros to unused blocks without affecting active files.

Created: 2026-10-03 by

To securely erase only the used space on a Linux storage drive while preserving existing files, you must zero out the free (unallocated) space rather than the entire disk. This is achieved by creating a file filled with zeros that grows until it consumes all available free space, then deleting that file. This method ensures that previously deleted data becomes unrecoverable without affecting your current operating system or active partitions.

Understanding Used vs. Free Space

It is critical to distinguish between "used" and "free" space when discussing data security. When you delete a file in Linux, the filesystem typically does not immediately overwrite the data. Instead, it marks the blocks as "free" in the inode table, making them available for new writes. Until those blocks are reused, the old data remains on the physical media and can be recovered by forensic tools.

Zeroing out used space would mean overwriting every block currently holding your active files, which results in total data loss. The goal here is to target the free space—the gaps between your files—so that if someone recovers a deleted file, they find only zeros instead of the original content. This technique is ideal for preparing a drive for reuse, selling hardware, or enhancing privacy without wiping your current installation.

Prerequisites and Safety Checks

Before proceeding, ensure you have sufficient free space to create the zero-filled file. If your drive is nearly full, this process will fail because there is no room to grow the file. You should also have root privileges, as writing directly to the filesystem root requires administrative access. It is highly recommended to perform this operation from a live USB environment if you want to guarantee that no other processes are writing to the drive, but it can be done on a running system if necessary.

If you are managing complex storage layouts, such as Logical Volume Management (LVM), refer to our guide on How to Extend Disk Space with LVM on Linux Server to understand how volume groups interact with free space allocation. Ensuring your filesystem is healthy before starting is also wise; however, do not run fsck after the wipe, as it is unnecessary for this specific task and may cause confusion.

Step-by-Step Zeroing Process

The most reliable method involves using the dd command combined with shell redirection to write zeros into a file located in the directory where you want to clear space. We will use /dev/zero as the source of the data.

  1. Open a terminal and switch to the root user or use sudo.
  2. Navigate to the partition you wish to clean. For example, to clean the root partition:
cd /

This step is crucial. By changing to the root directory (/), we ensure the file is created on the primary filesystem. If you want to clean a different mount point, navigate there first.

  1. Create the zero-filled file. Run the following command. This creates a file named zeroes and fills it with zeros until the disk is full.
sudo dd if=/dev/zero of=./zeroes bs=1M status=progress

Note that status=progress is valid in modern versions of GNU coreutils and provides a real-time view of the write speed and bytes transferred. Without this flag, the command runs silently, which can be disorienting during long operations. The bs=1M setting sets the block size to 1 megabyte, balancing speed and memory usage. Adjust this value if you encounter performance issues, though 1M is generally optimal for HDDs and SSDs.

Wait for the command to complete. It will fail with an error message like "No space left on device" when it has successfully consumed all available free space. This error is expected and indicates success.

  1. Delete the zero-filled file. Once the drive is full, remove the file to release the space back to the filesystem.
sudo rm ./zeroes

This deletion marks the blocks as free again, but now they contain zeros. Any future write operation will overwrite these zeros, ensuring that previously deleted data cannot be reconstructed.

Alternative Methods for Specific Filesystems

While the dd method works universally across ext4, XFS, Btrfs, and other common Linux filesystems, some modern filesystems offer built-in secure deletion features. For instance, Btrfs supports the btrfs balance command with scrubbing options that can securely rewrite unused metadata and data chunks. However, the dd approach remains the most straightforward and compatible solution for general users.

If you are dealing with encrypted volumes, note that zeroing out the underlying block device does not decrypt the data. The encryption keys remain intact, and the ciphertext stored in the "free" space remains unreadable without the key. Therefore, this method is primarily useful for preventing recovery of unencrypted deleted files or for sanitizing drives before reformatting.

Verifying the Result

After completing the process, you can verify that the space has been reclaimed by checking disk usage with df -h. The "Available" space should return to its pre-wipe level. To confirm that the data is indeed zeroed, you could theoretically recover a deleted file and inspect its contents, but this is rarely necessary unless you are conducting a security audit. The act of filling and deleting the space guarantees that any subsequent read of those sectors returns zeros.

Frequently Asked Questions

Does this method work on SSDs?

Yes, but it is less efficient than on HDDs. SSDs use wear-leveling algorithms, meaning the physical location of the data may change during the write process. While zeroing free space still obscures deleted data, TRIM commands are more effective for SSDs. Consider using fstrim for regular maintenance on SSDs.

Can I zero out space on a mounted Windows NTFS drive?

Not directly from Linux using standard tools. You would need to use Windows-specific utilities like SDelete or format the drive. Linux tools like wipe or shred are designed for Unix-like filesystems and may not handle NTFS metadata correctly.

What happens if the power fails during the process?

If power is lost, the partially written file will remain on the disk. You should simply restart the process. The existing zeros will be overwritten or expanded, and the final deletion step will clean up any residual fragments. No data corruption occurs to your existing files.

Is this faster than formatting the drive?

No. Formatting wipes the entire drive structure, including system files, which takes less time than selectively zeroing out only the free space while keeping the OS intact. Use this method only when you need to preserve existing data.

Why did my previous attempt fail with "Permission denied"?

You likely attempted to write to a directory where you do not have write permissions, or you forgot to use sudo. Always execute the dd command with elevated privileges when targeting the root filesystem or other protected mounts.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More