How do I make a USB flash drive writable on Linux?
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.
Related videos on Youtube
Michael Christensen
Updated on September 18, 2022Comments
-
Michael Christensen over 1 year
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 displaysoff
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.
-
Panther over 10 yearsWhat 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.
-
Michael Christensen over 10 yearsThe file system is fat32. I have added dosfsck output to the question.
-
-
cybernard over 10 yearsYou 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.
-
Michael Christensen over 10 yearsWhen using gparted I get the error "Can't write to /dev/sdg, because it is opened read-only."
-
Art Gertner over 10 yearswhich 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?
-
Art Gertner over 10 yearsALSO, 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)