15

I just got my Raspberry Pi and a brand new 16 GB Class 10 SD card. I am using Linux Mint and am trying to image the Raspbian Debian 7 (Wheezy) OS to the card, but whenever I try

dd bs=4M if=2013-05-25-wheezy-raspbian.img of=/dev/sdc

I get the error

dd: opening `/dev/sdc': Read-only file system

I have tried every way possible to change the permission using

chmod a=rwx /dev/sdc

and I added this line to /etc/fstab:

UUID=9016-4EF8  /media/matt/SDcard vfat user,uid=1000,gid=100,dmask=027,fmask=137  0  0

Here are some printouts from the command line:

matt-Aspire-5552 SDcard # blkid
/dev/sda1: LABEL="PQSERVICE" UUID="8806A1F106A1E104" TYPE="ntfs"
/dev/sda2: LABEL="SYSTEM RESERVED" UUID="EABAA321BAA2E971" TYPE="ntfs"
/dev/sda3: LABEL="Acer" UUID="6A5AE8025AE7C8C1" TYPE="ntfs"
/dev/sda5: UUID="a27e3081-abad-432d-8ffa-a24245684cd8" TYPE="ext4"
/dev/sdc1: UUID="9016-4EF8" TYPE="vfat"

And fdisk -l:

matt-Aspire-5552 SDcard # fdisk -l

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x2bd2c32a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    41945087    20971520   27  Hidden NTFS WinRE
/dev/sda2        41945088    42149887      102400    7  HPFS/NTFS/exFAT
/dev/sda3        42149888   371296943   164573528    7  HPFS/NTFS/exFAT
/dev/sda4       371298302   625141759   126921729    5  Extended
Partition 4 does not start on physical sector boundary.
/dev/sda5       371298304   625141759   126921728   83  Linux

Disk /dev/sdc: 15.8 GB, 15811477504 bytes
255 heads, 63 sectors/track, 1922 cylinders, total 30881792 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            8192    30881791    15436800    c  W95 FAT32 (LBA)

And I have even tried changing the permissions tab in the Properties of the SD card mount folder to be read-write, but that didn't change anything.

All of this has been done in sudo su root.

4
  • 2
    could you please check the position of read-only switch on the side of your SD card? and maybe try to flip it back and forth a few times.
    – lenik
    Jul 1, 2013 at 2:57
  • Please do not chmod the device node /dev/hdc.
    – hans_meine
    Aug 12, 2015 at 17:58
  • 1
    I had to fix the switch on the SD card with a piece of tape. Without the tape, the switch changed its position upon insertion into the card slot.
    – klaus se
    Jan 24, 2016 at 22:36

9 Answers 9

9

Putting Linux ISO on SD Card

  1. Gain superuser priveleges:
    • sudo su -
  2. Remove entry from /etc/fstab
  3. Unmount /dev/sdX
    • umount /dev/sdX
  4. Physically remove SD card
  5. Inspect SD card and make sure it's not LOCKED
  6. Physically insert SD card
  7. Find which device Linux assigns the card
    • dmesg | tail
  8. Write contents of ISO to SD card
    • dd if=/path/to/file.iso of=/dev/sdX bs=4096
2
  • 4
    I also suspect the physical lock slider. (Item 5.)
    – hans_meine
    Aug 12, 2015 at 17:57
  • Along similar lines, my microSD adapter card was faulty. Read only, regardless of the position of the lock slider. Jan 24, 2018 at 2:52
6

Physical write protection

Here's the image for those who had never used SD cards before.

Attribution.

It is analogous for a micro SD adapter with a MicroSD inside: the dongle is on the adapter:

3
  • Actually I see from the comments on the question it was the lock switch -- my apologies.
    – goldilocks
    Sep 29, 2016 at 10:44
  • @goldilocks no worries! I usually just read titles like most Googlers :-) Sep 29, 2016 at 10:45
  • So, up is unlocked and down is locked, right? Then, it still is write-protected in either position. It's a micro SD with adapter... maybe the adapter is the isuee? I'll see about that...
    – SebasSBM
    Jun 13 at 12:38
4

I had an issue with a card reader as well. The switch on the card I found does nothing, it is essentially a price of plastic you're sliding. That in turn activates another switch inside the card reader. In my case the switch in the card reader was bent a little too far so that it never made contact, and forcing it to mount read only no matter what. I bent it back very carefully with the tiniest pair of needlenose pliers ever and it worked fine. That's what worked for me. Hope it helps.

2

Having been a Linux user for about 12 years, I was fairly confused as to how an unmounted block device could be a read-only file system. I'm still confused; Ubuntu didn't give me any useful information as to why things were going wrong or how to fix them.

In the end, I reformatted the SD card using my camera. After that, the dd command worked fine.

UPDATE

You won't believe this, but spraying compressed air into the card slot near where the read-only switch is sensed fixed it for me. I hardly believe it.

3
  • You don't even need compressed air ... blowing by mouth a few times into the slot of the card reader fixed the "broken" cardreader. :)
    – user33267
    Jul 29, 2015 at 15:25
  • 1
    The 80s video gaming solution
    – deltaray
    Jan 9, 2019 at 16:10
  • Upvoted this answer, not because I ran into the same need-air-blown issue, but because that entertaining story also taught us a valuable lesson: always swap some components during troubleshooting, so that we can deduce which part was faulty. In my case, after hours of fiddling my OS setting, I ended up swap a different sd card adapter and it worked! You never know.
    – RayLuo
    Jul 23 at 18:56
1

You are getting that error because, when you are inserting the SD card into the Raspberry Pi, the SD card is mounted to the root file system in a read-only mode (default).

This prevents you from performing any write operation on the SD carry. Therefore failing of dd is likely.

You actually need to remount the SD card manually, by enabling the rw option, so that this time the SD card is mounted in read-write mode.

Assuming /dev/sdc is the logical name of your SD card:

  1. $ sudo mount -o remount,rw /dev/sdc

The above command, mounts the SD card for rw access, and I guess you no longer have a problem re-flashing the Raspbian OS image onto it.

Alternative:

  1. Editing the /etc/fstab file using your preferred editor like this

    $sudo leafpad /etc/fstab

  2. Search for a line similar to this:

    /dev/sdc /mnt/sdcard sdc ro,nosuid,nodev,noatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0 0

  3. Replace ro with rw in the above line.

  4. Save the file.

  5. I hope it works..

2
  • 2
    This answer does not address the question; the question is about dd, which writes to the block device, and not to a mounted filesystem, and is best done while the device is not mounted at all.
    – hans_meine
    Aug 12, 2015 at 17:56
  • However, it solved my problem. I was able to write to the sd card from my Linux laptop using Etcher, but then could not modify any files on it (while still on the laptop.)
    – mhwombat
    May 28, 2018 at 22:16
1

I had this problem too.

Atlas RPI # dd bs=1024k if=2013-12-20-wheezy-raspbian.img of=/dev/sdb
dd: opening '/dev/sdb': Read-only file system

How I fixed it was as follows:

Atlas RPI # dd bs=1024k if=2013-12-20-wheezy-raspbian.img of=/dev/sdb1
^C49+0 records in
48+0 records out
50331648 bytes (50 MB) copied, 6.54082 s, 7.7 MB/s

That is to say, I started deliberate writing to the first partition (which is deliberately wrong). After one second of writing I aborted this with Ctrl + C. Then I did:

Atlas RPI # dd bs=1024k if=2013-12-20-wheezy-raspbian.img of=/dev/sdb
2825+0 records in
2825+0 records out
2962227200 bytes (3.0 GB) copied, 412.419 s, 7.2 MB/s
Atlas RPI #

And it works perfectly - Tada!!! Maybe it's just an odd filesystem that the SD cards are factory formatted with? Who knows.

1
  • Not sure if this is the cleanest way to fix it, but the hack worked for me, too.
    – rodrunner
    Sep 18, 2015 at 16:12
0

On your PC that you are using to write the image to the SD card, make sure that the SD card is un-mounted, ad that you run the dd command as root.

Something like this:

sudo umount /dev/sdc
sudo dd bs=4M if=2013-05-25-wheezy-raspbian.img of=/dev/sdc

You should now be able to take the SD card out of your PC and plug it into your Pi.

0

I had a faulty card reader that had that same issue.

The SD card would come up read-only no matter where the switch was. I used a different SD card reader in the end.

0

I just ran into this as well when tring to load an image to the SD from another computer (at this very moment). Don't use sudo to unmount the SD card in the first step (or even su). Every time I had unmounted the SD card using sudo, it set it as Read-Only.

Then use sudo with dd.

Hope that helps ya.

1
  • then get error, "dd error writing operation not permitted" Jul 14, 2017 at 23:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.