Software Tutorial
Computer Software
How to fix a disk that is stuck in a 'Read-only' state with diskpart
How to fix a disk that is stuck in a 'Read-only' state with diskpart
Run DiskPart as Administrator by opening Command Prompt (Admin) and typing diskpart. 2. Identify the affected disk using list disk, select it with select disk X, and check its read-only status via attributes disk. 3. Clear the read-only flag using attributes disk clear readonly and confirm the change. 4. If the command fails, check for a physical lock switch, hardware failure, or system-level restrictions such as the WriteProtect registry key under StorageDevicePolicies, and modify or delete it if set to 1. 5. As a last resort, use clean, create partition primary, format fs=ntfs quick, and assign in DiskPart to erase all data and restore full functionality, ensuring the disk is no longer read-only unless hardware-enforced.

If a disk is stuck in a "read-only" state and you're unable to format, write, or delete data from it, the issue can often be resolved using the DiskPart utility in Windows. This problem commonly occurs due to corruption, file system errors, or the disk's attributes being set to read-only at the partition or volume level. Here's how to fix it using DiskPart.

1. Run DiskPart as Administrator
First, open Command Prompt with administrative privileges:
- Press
Win Xand select Command Prompt (Admin) or Windows Terminal (Admin). - Type
diskpartand press Enter.
Wait for the DiskPart utility to initialize.

2. Identify the Problem Disk
In the DiskPart prompt, run the following commands one by one:
list disk
This will show all disks connected to your system. Identify the disk that's read-only by its size and status.

Once identified (e.g., Disk 1), select it:
select disk X
Replace X with the actual disk number.
Then, check its current attributes:
attributes disk
Look for a line that says:Current Read-only State: Yes
If it says "Yes", that confirms the disk is set to read-only.
3. Clear the Read-only Attribute
Now, attempt to clear the read-only flag:
attributes disk clear readonly
If successful, you'll see a message like:Disk attributes cleared successfully.
Run attributes disk again to confirm the read-only state is now "No".
4. Check for Other Issues if Clear Fails
If the command fails or the disk remains read-only, consider the following:
- Physical switch: Some USB drives and SD cards have a physical lock switch. Make sure it’s in the unlocked position.
- Hardware failure: The disk may be failing or locked by the manufacturer (common with worn-out USB drives).
- Group Policy or Registry settings: In rare cases, system policies may enforce write protection. You can check:
- Registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies - If
WriteProtectexists and is set to1, change it to0or delete the key.
- Registry key:
- Third-party tools: Use manufacturer-specific tools (e.g., Kingston Format Utility, SanDisk Drive Formatter) if the issue persists.
5. Clean and Reinitialize the Disk (Optional)
If you no longer need the data on the disk, you can clean and reformat it:
In DiskPart:
clean create partition primary format fs=ntfs quick assign exit
This will erase all data and make the disk fully writable again.
⚠️ Warning: The
cleancommand deletes all partitions and data on the selected disk.
Summary
- Use
attributes disk clear readonlyin DiskPart to remove the read-only flag. - Confirm the disk isn’t physically locked or failing.
- Check for system-level write protection via the registry.
- As a last resort, use
cleanto reset the disk completely.
Basically, if DiskPart sees the read-only flag, it can often remove it—unless the lock is hardware-enforced. Most software-level read-only states can be fixed this way.
The above is the detailed content of How to fix a disk that is stuck in a 'Read-only' state with diskpart. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Clothoff.io
AI clothes remover
Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Fix: Recovery environment not found in Windows 11/10
Apr 28, 2023 pm 04:25 PM
The recovery environment is an integral part of Windows and is usually turned on when your PC encounters a problem. Now, what if your system fails to boot into the recovery environment and displays a "Recovery Environment Not Found" error message? This can be a very serious problem for you as you cannot even reset or repair your system. Fix 1 – Force boot the system into RE If you are unable to boot into the Windows Recovery Environment, you can force boot the system into it. 1. Shut down your computer. 2. After making sure that the device is completely turned off, tap the power button once to start the device. When you reach the manufacturer's logo screen, press and hold the power button again to completely shut down the device. 3. Repeat these force-boot-s again
5 Easy Ways to Format USB to NTFS Windows 11
Apr 13, 2023 pm 04:52 PM
USB drives are a great way to transfer data easily and efficiently. However, over time, your USB drive may lose its performance due to bad sectors or leftover data. If you have been facing performance issues with your USB drive, then formatting it can help you improve the same. NTFS is a widely supported format type in Windows and can help you transfer large amounts of data compared to FAT32. Here's how to format a USB drive to NTFS on Windows 11
How to find which disk is which in diskpart's 'list disk' command
Aug 21, 2025 am 02:07 AM
Usedisksizefromlistdiskoutputtomatchknowndrivecapacities,asDisk0(238GB)likelycorrespondstoa256GBSSD,Disk1(931GB)toa1TBHDD,andDisk2(14GB)toaUSBdrive.2.Cross-referencewithDiskManagement(diskmgmt.msc)toverifydiskhealth,partitionlayout,andvolumelabelsmat
How to fix a disk that is stuck in a 'Read-only' state with diskpart
Aug 06, 2025 am 04:15 AM
RunDiskPartasAdministratorbyopeningCommandPrompt(Admin)andtypingdiskpart.2.Identifytheaffecteddiskusinglistdisk,selectitwithselectdiskX,andcheckitsread-onlystatusviaattributesdisk.3.Cleartheread-onlyflagusingattributesdiskclearreadonlyandconfirmthech
How to use the diskpart command to format a drive in Windows
Aug 05, 2025 pm 01:56 PM
ToformatadriveusingdiskpartinWindows,openCommandPromptasAdministratorbypressingWindows XandselectingCommandPrompt(Admin)orWindowsTerminal(Admin),thenclickYesifpromptedbyUAC;next,typediskparttoenterthetool,listdisktoviewalldrives,selectdiskXreplacingX
How to mount a VHD file as a drive letter using diskpart commands
Aug 13, 2025 am 05:06 AM
OpenCommandPromptasAdministrator.2.Launchdiskpartbytypingdiskpart.3.SelecttheVHDfileusingselectvdiskfile="C:\Path\To\Your\disk.vhd".4.AttachtheVHDwithattachvdisk(orattachvdiskreadonlyforread-onlyaccess).5.Listvolumeswithlistvolume,selectthe
Automating diskpart commands with a script: [How to create a .txt script file]
Aug 07, 2025 am 03:02 AM
To create and use diskpart scripts, you must first write the commands in a text editor and save them as .txt file, and then run diskpart/s execution through the command prompt with administrator permissions. 1. Create a script file: Enter the diskpart command in Notepad, one per line, such as selectdisk0, clean, createpartitionprimary, assignletter=C, formatfs=ntfsquick, exit; 2. Save the file: Save the file in UTF-8 encoded .txt format, such as C:\scripts\clean_drive.txt, pay attention to selecting the "All Files" type
Fixing 'The selected disk is not a fixed MBR disk' error in diskpart
Aug 13, 2025 am 02:12 AM
Theerror"TheselecteddiskisnotafixedMBRdisk"primarilyoccurswhenWindowsidentifiesthediskas"removable"insteadof"fixed,"regardlessofpartitionstyle.2.Tofixit,ensurethediskisconnectedinternallyviaSATAorNVMe,notthroughaUSBadapt


