"Access Denied": The SD Card Error That Nearly Ruined My Evening
It was one of those evenings where everything was supposed to just work.
I had spent the better part of the day building a Yocto image. If you have ever done this, you know it is not a quick thing. You configure your layers, you kick off a build, you wait, you fix something, you wait some more, and eventually you end up with a shiny image file that feels like it cost you a small piece of your soul. Mine was finally done. All that was left was the easy part: flash it onto an SD card, pop it into the board, and watch it boot.
So I opened Raspberry Pi Imager, selected my custom image, picked the SD card, and hit write. Simple. This is the boring, reliable step. The step that never goes wrong.
Except this time a little dialog box popped up and stared back at me:
Access denied error while writing file to disk. The disk may be write-protected or in use by another application. Please ensure the disk is not mounted and try again.
And that was it. No progress bar, no flashing, nothing. Just a polite refusal.
My first thought, naturally, was the worst one: the card is dead. It is corrupted. I have wasted a card and now I need to find another one before I can even test the thing I spent all day building. If you have felt that specific flavor of frustration, this post is for you, because the good news is that this error usually means nothing of the sort.
What this error actually means
The wording of the message sends people down the wrong path. Because it says "write-protected" and "access denied," it is easy to assume the card is broken. In reality, this is one of the friendlier errors you can get. It shows up before any real writing happens, which is a big clue. A card that is genuinely corrupted or physically failing tends to die partway through the write, or fail the verification step at the end. Failing right at the start, at the "access" stage, is a completely different animal.
What this error is really telling you is that Imager could not get exclusive write access to the disk. There are only a handful of reasons for that, and almost all of them are trivial to fix:
The card has a write-protect lock switched on.
The card is mounted and some other program is holding onto it.
Imager does not have the permissions it needs to write to a raw disk.
Antivirus or ransomware protection is quietly blocking raw disk writes.
None of those mean your card is toast. They just mean something is standing between Imager and the card, and you need to clear the way.
Working through the fix
Here is the order I would recommend, going from "most likely and easiest" to "slightly more involved."
Check the physical lock first. If you are using a full size SD card or an adapter, look at the left edge for a tiny slider. If it is pushed toward the "LOCK" label, the card is write-protected in hardware and nothing you do in software will change that. Slide it back up and reinsert. This is the single most common cause of this exact message, and it is embarrassing how often it is the answer.
Make sure nothing else is holding the card. Close any File Explorer windows showing the card, any photo apps, any backup tools. Then safely eject and reinsert it so there is no stale connection hanging around.
Clear the software read-only flag. Windows can flag a disk as read-only at the operating system level even when there is no physical lock. Open Command Prompt as administrator and run diskpart, then work through these commands one at a time:
diskpart
list disk
select disk N
attributes disk
attributes disk clear readonly
exit
Replace N with your card's disk number, which you identify by its size in the list disk output. Be careful here, because this is the one place you can cause damage by selecting the wrong disk. Note that a card's real size shows up smaller than the number on the label, so a 32 GB card appears as roughly 29 GB. The attributes disk line shows you whether a read-only state is actually set, and the next line clears it without erasing your data.
Run Imager as administrator. Writing a raw image to a disk needs elevated permissions. Right click the Raspberry Pi Imager shortcut and choose "Run as administrator." A surprising number of access-denied cases are just this.
Check Controlled Folder Access. On Windows, go to Windows Security, then Virus and threat protection, then Ransomware protection. If Controlled Folder Access is on, it can block raw disk writes. Turn it off temporarily, flash your image, then turn it back on.
If it still refuses, wipe the partition table. As a last resort, diskpart's clean command removes the partition table entirely, which clears any lingering volume that might be locking the disk. Select the correct disk exactly as before, then run clean. Afterward the card will show up as unallocated with no drive letter, and Windows may nag you to format it. Do not format it. Raspberry Pi Imager actually prefers a raw, unpartitioned disk and will handle the partitioning itself.
The lesson I took from it
The thing that stuck with me is how misleading a good error message can be. "Access denied, may be write-protected" sounds like a hardware death sentence, but it is almost always just a lock, a mount, or a permissions hiccup. Nine times out of ten you are one "Run as administrator" click away from watching that progress bar finally move.
So if you have spent all day building a Yocto image and the very last step slaps you with this error, take a breath. Your card is probably fine, your image is probably fine, and you are probably about ninety seconds away from booting the thing you worked so hard on. Clear the path, hit write again, and go enjoy the part where it actually boots.
