You are not logged in.

#1 2016-09-26 12:39:43

ralph_hellgrind
Member
Registered: 2016-02-03
Posts: 46

Cannot format USB drive

Hello, I have a 16 GB USB 3.0 flashdrive and I want to format it but whenever I try to do so, I get the following output:

cannot open /dev/sdb: Read-only file system

I have tried commands like 'dd', 'fdisk', cfdisk', 'sfdisk', 'mkfs.vfat' but I always get the same output.

What do I do to get this corrected. [I have unmounted the USB drive before trying the above mentioned commands to format it, but to no avail].


Thanks!

Offline

#2 2016-09-26 12:45:58

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,858
Website

Re: Cannot format USB drive

Does the USB stick have a hardware switch that locks it to read-only mode?

If not, please post the output of

mount | grep "on /dev"

as well as the journal from an affected session.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#3 2016-09-27 03:13:55

ralph_hellgrind
Member
Registered: 2016-02-03
Posts: 46

Re: Cannot format USB drive

There is no hardware switch to lock it into read only mode.

The output of


mount | grep "on /dev"

dev on /dev type devtmpfs (rw,nosuid,relatime,size=4035504k,nr_inodes=1008876,mode=755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
mqueue on /dev/mqueue type mqueue (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)

And the output of


fdisk -l

Disk /dev/sdb: 14.5 GiB, 15504900096 bytes, 30283008 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
Disklabel type: dos
Disk identifier: 0x00000000


Thanks!

Offline

#4 2016-09-27 06:36:10

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: Cannot format USB drive

Is the read-only flag set on the device?

hdparm -r /dev/sdb

If yes, you can try to unset it with

hdparm -r0 /dev/sdb

and then see whether you can write to the device.

But if it still fails, something might be broken there...


pkgshackscfgblag

Offline

#5 2016-09-27 12:54:58

Anon1234
Member
Registered: 2016-03-30
Posts: 6

Re: Cannot format USB drive

Another newbie here, so not sure if this will help

But what file system are you trying to format in? If for example it is NTFS, have you installed the ntfs-3g package?

I had a similar issue writing to a USB stick that was only mounting in read only mode

Offline

#6 2016-09-27 15:15:05

headkase
Member
Registered: 2011-12-06
Posts: 1,976

Re: Cannot format USB drive

Sanity check, you are trying to format the drive with root privileges right?  Like either in a su'd console or with the sudo command?

Offline

#7 2016-10-01 07:32:58

ralph_hellgrind
Member
Registered: 2016-02-03
Posts: 46

Re: Cannot format USB drive

Yes, I am trying to format it by being root user (or su).
I am trying to format it with FAT filesystem and I am using the command:

mkfs.vfat

I tried using 'hdparm' as follows:

# hdparm -r0 /dev/sdb

/dev/sdb:
setting readonly to 0 (off)
readonly      =  0 (off)

But when I try to format it I again get the error:

Could not open /dev/sdb: Read-only file system

Thanks!

Offline

#8 2016-10-01 11:47:48

ukhippo
Member
From: Non-paged pool
Registered: 2014-02-21
Posts: 366

Re: Cannot format USB drive

Sanity check: you are trying to format the partition (presumably /dev/sdb1) and not the device (/dev/sdb)?

If so, can you delete and recreate the partition?

Offline

#9 2016-10-01 14:18:57

ralph_hellgrind
Member
Registered: 2016-02-03
Posts: 46

Re: Cannot format USB drive

There is no '/dev/sdbx'. It only shows '/dev/sdb' when I try to use the 'fdisk -l' command.
The modified output of 'fdisk -l' is:


Disk /dev/sdb: 14.5 GiB, 15504900096 bytes, 30283008 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
Disklabel type: dos
Disk identifier: 0x00000000

I cannot delete and recreate the partition. When I try to do so:


fdisk /dev/sdb

It gives the output-

fdisk: cannot open /dev/sdb: Read-only file system

Thanks

Offline

#10 2016-10-01 14:59:17

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,919

Re: Cannot format USB drive

remove the usb drive,  wait a few seconds then plug it in again.

post dmesg | tail -n 25 , partx -s /dev/sdb and lsblk output .


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Online

#11 2016-10-02 06:21:52

ralph_hellgrind
Member
Registered: 2016-02-03
Posts: 46

Re: Cannot format USB drive

The outputs of 'dmesg', 'partx' and 'lsblk' are as follows:


tail -n 25
[   43.213293] fuse init (API version 7.25)
[  165.433200] usb 1-3: new high-speed USB device number 5 using xhci_hcd
[  165.670015] usb-storage 1-3:1.0: USB Mass Storage device detected
[  165.673509] scsi host4: usb-storage 1-3:1.0
[  165.673654] usbcore: registered new interface driver usb-storage
[  165.910520] usbcore: registered new interface driver uas
[  166.677402] scsi 4:0:0:0: Direct-Access     SanDisk  SanDisk Ultra    PMAP PQ: 0 ANSI: 6
[  166.677937] sd 4:0:0:0: [sdb] 30283008 512-byte logical blocks: (15.5 GB/14.4 GiB)
[  166.678136] sd 4:0:0:0: [sdb] Write Protect is off
[  166.678140] sd 4:0:0:0: [sdb] Mode Sense: 2b 00 00 08
[  166.678345] sd 4:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[  166.961737]  sdb:
[  166.962365] sd 4:0:0:0: [sdb] Write Protect is on
[  166.962371] sd 4:0:0:0: [sdb] Mode Sense: 2b 00 80 08
[  166.962567] sd 4:0:0:0: [sdb] Attached SCSI removable disk

# partx -s /dev/sdb
partx: /dev/sdb: failed to read partition table

# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 931.5G  0 disk
├─sda1   8:1    0    30G  0 part /
├─sda2   8:2    0     8G  0 part [SWAP]
└─sda3   8:3    0 893.5G  0 part /home
sdb      8:16   1  14.5G  1 disk /run/media/<user>/Movies
sr0     11:0    1  1024M  0 rom

Thanks!

Offline

#12 2016-10-02 09:31:04

philo
Member
Registered: 2015-01-26
Posts: 251

Re: Cannot format USB drive

Please use code, not bold.

Offline

#13 2016-10-02 12:00:18

ukhippo
Member
From: Non-paged pool
Registered: 2014-02-21
Posts: 366

Re: Cannot format USB drive

1. As philo says, please use “code” tags, not “b” tags, when posting program output. It preserves formatting and makes it easier to read.

2. You mount disk partitions, not disks - so why is /dev/sdb mounted?
I'm guessing you've got some sort of misconfigured automounter.
Correct your automounter to not mount /dev/sdb and then unmount the disk.
Can you now run fdisk/partx? If not, try replugging.

Offline

#14 2016-10-03 04:08:01

ralph_hellgrind
Member
Registered: 2016-02-03
Posts: 46

Re: Cannot format USB drive

Ok, will use 'code' tag and not 'b' tag. Sorry.

When mounting other USB drives, the OS mounts them correctly. In case of this particular USB drive, this is happening. When I plug in the device, it opens the drive and I can see the contents in it. I can copy it's contents but cannot write to it.

I tried unmounting the drive and manually mounting it to a folder named 'Mount_USB' but I am getting the following error:

# mkdir Mount_USB
# mount /dev/sdb Mount_USB/
mount: /dev/sdb is write-protected, mounting read-only

I used this USB drive in a laptop where a WD external encrypted drive was also plugged in and it's (WD external HDD) contents were unlocked using the GUI of WD's drive unlocking software. I think that this error is occurring after this incident. Do you think this has got something to do with the errors I am getting?

Offline

#15 2016-10-03 06:14:56

seth
Member
Registered: 2012-09-03
Posts: 51,175

Re: Cannot format USB drive

Formatting a mounted device is a bad idea, so always ensure to unmount it first.

The device is considered write protected.
This is either a misinterpretation of the usb stack in the kernel or the device actually is write only.
1. Try another USB slot. Try all you have and avoid any adapters/readers
2. Can you write into it from a windows box?

In case of 2:

Check file permissions "stat /dev/sdb" and try to alter them "chmod +w /dev/sdb" (notice that sdb must of course match the actually troubling device and not some other usb key attached ;-)
Then try again.

In case it's a kernel bug, this might (or not) be due to some FS junk in the first sector of the device. You might be better of creating a partition table (using either fdisk or cfdisk)

Offline

#16 2016-10-03 06:30:38

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: Cannot format USB drive

Generally, I don't think that the issue is caused by the FS being directly on /dev/sdX rather than a partition, or the FS not having been unmounted properly, or whatever else...
If even fdisk (and similar) fail, it becomes more of a hardware issue.

ralph_hellgrind wrote:

I tried using 'hdparm' as follows:

# hdparm -r0 /dev/sdb
/dev/sdb:
 setting readonly to 0 (off)
 readonly      =  0 (off)

What was the output of `hdparm -r` before you explicitly turned off read-only mode? If it was on, does it turn back on when you reconnect it?

Last edited by ayekat (2016-10-03 06:30:57)


pkgshackscfgblag

Offline

#17 2016-10-05 17:42:32

ralph_hellgrind
Member
Registered: 2016-02-03
Posts: 46

Re: Cannot format USB drive

chmod +w /dev/sdb

did not work.

hdparm -r /dev/sdb 

/dev/sdb:
 readonly      =  1 (on)

hdparm /dev/sdb 

/dev/sdb:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 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      =  1 (on)
 readahead     = 256 (on)
 geometry      = 14786/64/32, sectors = 30283008, start = 0

Thanks

Offline

Board footer

Powered by FluxBB