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.
Jephir
  • 1,049

2 Answers2

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.

pgoetz
  • 193
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.

Art Gertner
  • 7,429