1

I want to reformat a SanDisk Cruzer Edge USB flash drive but it appears read-only:

$ sudo dd if=/dev/zero of=/dev/sdg
dd: failed to open ‘/dev/sdg’: Read-only file system

I checked the readonly status with hdparm:

$ sudo /usr/sbin/hdparm /dev/sdg
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 14 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 multcount     =  0 (off)
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 1017/124/62, sectors = 7821312, start = 0

The readonly flag displays off but that I still cannot write to the drive. How do I solve this?


After running dosfsck on the device I get this output:

$ sudo /usr/sbin/dosfsck /dev/sdg
fsck.fat 3.0.22 (2013-07-19)
Logical sector size (1766 bytes) is not a multiple of the physical sector size.
2
  • What file system is on the device ? Sometimes if the file system is corrupt, it will be mounted ro. You can check the disk for errors.
    – Panther
    Commented Jan 3, 2014 at 21:30
  • The file system is fat32. I have added dosfsck output to the question.
    – Jephir
    Commented Jan 4, 2014 at 19:17

2 Answers 2

1

My guess is your GUI is automounting the device to some location when you plug it in. For example, when I plug a USB stick in to my Mate/Marco 1.12 system:

[root@frog ~]# mount
   ...
   ...
/dev/sdg on /run/media/pgoetz/4474-E825 type vfat (rw,nosuid,nodev,relatime,uid=
1001,gid=1001,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,
shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)

When mounted, you won't be able to actually dd to the device until the partition is unmounted:

umount /dev/sdg

Somewhat oddly, if I try running dd while the partition is mounted; e.g.

dd bs=4M if=./archlinux-2016.04.01-dual.iso of=/dev/sdg

it claims to be copying the files, but the copy doesn't actually take place until the partition is unmounted. The system must be caching the write on account of being blocked from actually writing to the device.

0

Try to repartition it with gparted or similar tool. I assume you only need one partition, so delete everything and create one with FS of your choice.

Oh, and by the way, didn't you mean /dev/sdg1 or smth. As far as I know there has to be a number at the end, not just sdg

ALSO: consider how long have you been using this flashdrive and how intensively have you been writing data to it. Flash memory has a total limit of write operations per cell (read here). When the limit is reached the drive should normally become read-only. I say normally, because there are some cases when the drive fails completely - this can happen if you are using cheap low-quality device.

4
  • You end dd with just sdg. It will then start at sector 0 wiping the patition table and all other important file system info. sdg1 would force it to skip to the beginning of the first partition usually sector 63.
    – cybernard
    Commented Jan 4, 2014 at 6:38
  • When using gparted I get the error "Can't write to /dev/sdg, because it is opened read-only."
    – Jephir
    Commented Jan 4, 2014 at 19:12
  • which operation exactly produces this message "Can't write to /dev/sdg, because it is opened read-only." ? Does it happen when you are trying to format or re-partition the disk? Also, do you run gparted as root? Commented Jan 5, 2014 at 13:35
  • ALSO, read the update to my initial answer. Your drive might have worn out. If this is the case you will no longer be able to write to it (and obviously not able to format it either) Commented Jan 5, 2014 at 13:47

Not the answer you're looking for? Browse other questions tagged .