LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Write-Protected File System (https://www.linuxquestions.org/questions/linux-software-2/write-protected-file-system-4175590640/)

granfran 10-03-2016 02:15 AM

Write-Protected File System
 
Greetings. My flash that contains my debian OS suddenly became "read-only" after a power failure. I booted with another OS disk and tried to fsck the flash drive; however this message appears: "disk write-protected; use the -n option to do a read only check".

I can run fsck with the -n option, but I need to repair the device and make it unprotected again. I have even tried to mkfs the device, but cannot because of the write-protected status.

Thanks in advance.

sag47 10-03-2016 02:21 AM

Does the drive contain a physical read-only switch? I know some flash cards have that.

granfran 10-03-2016 02:27 AM

No, this one does not have a switch. From what I can tell, Linux will put a partition into "write protected" mode when it detects file inconsistencies.

hydrurga 10-03-2016 04:09 AM

Can you please post the entire output from the fsck command?

I would suggest that if the data on the flash disk is important to you, before anything else you make a byte-for-byte backup of the filesystem onto another device in case any of your subsequent recovery efforts go awry.

granfran 10-03-2016 06:36 AM

Below is the output:

Quote:

fsck.ext3: Read-only file system while trying to open /dev/sdc5
Disk write-protected; use the -n option to do a read-only
check of the device

hydrurga 10-03-2016 07:37 AM

Are you sure that /dev/sdc5 is the Debian o/s filesystem in question? A blkid should confirm it (consider label, size etc.).

Also check that the filesystem is actually unmounted and not being auto mounted by your other o/s disk by issuing a mount | grep sdc5 command.

To see what fdisk thinks of the flash, could you also throw a fdisk -l /dev/sdc at it?

granfran 10-03-2016 09:32 AM

I confirmed that the disk is not mounted. The results of the other commands are below:

blkid

Quote:

/dev/sdb5: UUID="a5449d20-732a-4310-89b7-a50893b61a1d" TYPE="ext4" PARTUUID="55ae2695-05"
fdisk -l /dev/sdc

Code:

Disk /dev/sdc: 7.5 GiB, 8004304896 bytes, 15633408 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: 0x55ae2695

Device    Boot    Start      End  Sectors  Size Id Type
/dev/sdc1  *          64  851967  851904  416M 17 Hidden HPFS/NTFS
/dev/sdc2        854014 15632383 14778370    7G  5 Extended
/dev/sdc5        854016 14925823 14071808  6.7G 83 Linux
/dev/sdc6      14927872 15632383  704512  344M 82 Linux swap / Solaris


hydrurga 10-03-2016 10:14 AM

That looks fine to me. So what happens when you try to mount the filesystem? (mount -t ext4 -v -o rw /dev/sdc5 mountpoint [change mountpoint to your desired mount point]).

It's a bit unusual that your original fsck command tried to use fsck.ext3 rather than fsck.ext4. What command did you issue?

granfran 10-03-2016 10:32 AM

mount -t ext4 -v -o rw /dev/sdc5 /mnt

Quote:

mount: /dev/sdc5 is write-protected, mounting read-only
mount: wrong fs type, bad option, bad superblock on /dev/sdc5,
missing codepage or helper program, or other error

In some cases useful info is found in syslog - try
dmesg | tail or so.

I used fsck. Now when I use fsck it uses fsck.ext4 with the same results. I don't have an explanation of why it used ext3 before.

hydrurga 10-03-2016 12:04 PM

Ok. Filesystem corruption looks the most likely reason, I'm afraid to say.

What does fsck.ext4 with the -n option give you? If it looks too bad, you'll probably need to start looking at recovery software such as testdisk (if the data is important to you).

If the data isn't important to you, you can always reformat the relevant partition(s) and reload your operating system. That's assuming you don't have a backup image somewhere.

granfran 10-03-2016 12:15 PM

fsck with -n is below:

/dev/sdc5: clean, 109061/439776 files, 1753081/1758976 blocks


mkfs won't let me proceed because it is write-protected.

Doesn't this imply that the problem is not corrupted file system?

hydrurga 10-03-2016 12:36 PM

Quote:

Originally Posted by granfran (Post 5613259)
fsck with -n is below:

/dev/sdc5: clean, 109061/439776 files, 1753081/1758976 blocks

mkfs won't let me proceed because it is write-protected.

Doesn't this imply that the problem is not corrupted file system?

Indeed it does. Strange that mounting the flash generates the error but fsck checks out ok. Something else must be in play.

Have you tried hdparm -r0 /dev/sdc ?

michaelk 10-03-2016 12:38 PM

I would not expect a power failure to damage the drive and it could be a coincidence but it could of failed. As stated I would copy anything important off the drive as soon as possible. Can you mount the drive read only?

Flash drives do fail and in several ways. Be lucky that it failed read only and not completely dead.

sundialsvcs 10-03-2016 12:45 PM

Obviously, "computers don't 'just decide' to do these things." Look at the output of the dmesg command, which displays the swirl of messages that occur at boot, and I predict that you will discover that a file-system integrity check failed. Therefore, the disk was mounted read-only.

sag47 10-03-2016 12:53 PM

Also, what is the make/model of the drive? How is it connected to your computer (e.g. SATA, USB, etc)?


All times are GMT -5. The time now is 06:34 AM.