Fix diskpart failed to clear disk attributes
In this article
Diskpart's "Failed to clear disk attributes" error usually appears when the disk is read-only, has a protected partition, or lacks administrator rights. The fix is to run diskpart as administrator, use the correct attributes disk clear readonly command, and check that the disk is not offline or in use.
What diskpart attributes actually do
Diskpart is a Windows command-line tool for managing disks, partitions, and volumes. The attributes disk command shows or changes two flags on a physical disk: Read-only and Boot Disk. The read-only attribute prevents any write operation to the disk, including formatting, partitioning, or deleting files. The boot disk attribute marks the disk as containing the system boot files.
When you run attributes disk clear readonly, diskpart tries to remove the read-only flag. If the disk is hardware-locked, protected by BitLocker, or the system denies the change, you get the generic "Failed to clear disk attributes" message. It is not a single cause—it is a symptom of several possible underlying conditions.
Why the error happens
- Missing administrator privileges: Diskpart must run elevated. A normal command prompt will often fail to change attributes.
- Disk is offline: In Disk Management, a disk can be marked offline. Diskpart cannot change attributes on an offline disk.
- Hardware write-protect switch: Many external drives and SD cards have a physical switch. If it is set to lock, no software command can override it.
- USB or SATA bridge controller: Some external enclosures report the disk as read-only even when the switch is off.
- BitLocker or device encryption: If the disk is encrypted, diskpart may refuse to clear attributes without first unlocking the volume.
- Disk is in use by another process: A background service, antivirus scan, or open file handle can block the attribute change.
Step-by-step fix
- Press Windows + X and select Terminal (Admin) or Command Prompt (Admin). This is the most common missing step.
- Type
diskpartand press Enter. - Type
list diskand press Enter. Note the disk number that has the problem (usually disk 1, 2, etc.). - Type
select disk X(replace X with the actual number) and press Enter. - Type
attributes diskand press Enter. Look at the current state—if it says "Current Read-only State: Yes," you are on the right track. - Type
attributes disk clear readonlyand press Enter. If it succeeds, you will see "Disk attributes cleared successfully." - If it fails, check if the disk is offline: type
online diskand press Enter, then retry step 6. - If the disk is still read-only, close diskpart and check the physical switch on the drive or card. For SD cards, slide the lock to the unlocked position.
When the error persists: deeper fixes
If the above steps do not work, the issue is likely hardware or encryption related. Try these in order:
- Use Disk Management: Open
diskmgmt.msc, right-click the disk label (not the partition) and choose Online if it is offline, then try diskpart again. - Unlock BitLocker: Open BitLocker Drive Encryption in Control Panel and suspend or disable encryption for that drive, then retry.
- Try another USB port or cable: A faulty cable can cause the drive to be detected as write-protected.
- Use a different computer: If the physical switch is fine but the drive still shows read-only on multiple machines, the drive's controller may have failed.
- Check the registry (internal drives only): For internal SATA drives, a registry key under
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicieswith aWriteProtectvalue of 1 can force read-only. Set it to 0 and restart. This is rare and should be done with caution.
Common mistakes and misconceptions
Many users confuse disk attributes with partition attributes. The command attributes volume works on volumes, not disks. If you accidentally select a volume instead of a disk, diskpart will not clear the disk read-only flag. Also, the error message does not always mean the disk is physically broken—it often just means the software cannot change the flag due to a lock.
Another misconception is that clean will fix it. The clean command removes partitions and volumes, but it still requires write access to the disk. If the disk is read-only, clean will fail with a similar error. You must clear the read-only attribute first.
Alternatives to diskpart
If diskpart fails, you have other options:
- Disk Management GUI: Right-click the disk and select Properties > Hardware > Properties > Change settings > Policies tab, and uncheck "Read-only." This works for some USB drives.
- PowerShell: Run
Clear-Disk -Number X -RemoveData(this wipes the disk) or useSet-Disk -Number X -IsReadOnly $false. The latter is the PowerShell equivalent of clearing the attribute. - Third-party disk tools: Many free partition managers can clear the read-only attribute. They often use lower-level drivers that can override some software locks.
- Low-level format utility: For drives with a stuck attribute, a low-level format tool can sometimes reset the flag, but this erases all data and should be a last resort.
Safety and data protection
Before attempting any fix, back up any data you need. Clearing the read-only attribute does not erase data, but the clean command does. Never run clean on the wrong disk—double-check the disk number in list disk. If the disk is an external drive that is still under warranty, consider returning it instead of performing risky operations.
If the disk contains the Windows system files (disk 0 usually), do not clear the boot disk attribute unless you are certain what you are doing. Removing the boot flag can make Windows unbootable.
Frequently Asked Questions
Does "attributes disk clear readonly" erase my files?
No. This command only changes the read-only flag. Your files remain intact. However, if you then run clean or format the disk, that will erase data.
Why does diskpart say "access denied" when I try to clear attributes?
This almost always means you are not running the command prompt as administrator. Right-click the Start button and choose "Terminal (Admin)" or "Command Prompt (Admin)" and try again.
Can I clear the read-only attribute on an SD card?
Yes, but first check the physical lock switch on the side of the card. If the switch is set to lock, no software command will work. If the switch is fine, the card may have a failing controller and might be unreliable.
What if the disk is a USB drive and the switch is not present?
Some USB flash drives have no switch but still report read-only. Try a different USB port, another computer, or use the PowerShell command Set-Disk -Number X -IsReadOnly $false. If it still fails, the drive is likely failing.
Is there a way to force clear the attribute without losing data?
Yes, the methods above (admin diskpart, PowerShell, Disk Management) do not touch data. Only if you run clean or format will data be lost. Always try the non-destructive methods first.