You are not logged in.

#1 2024-05-25 14:42:49

magnicu
Member
Registered: 2024-05-25
Posts: 18

[SOLVED] Disk is read-only after formatting

I did a format of HDD with dd and then used fdisk with g,n,w and then set mkfs.ext4.
However... I got a read-only disk.

Can someone please tell me how I fix it, as it's very frustrating to format it again(done 2 times already) as it's a huge disk?

Last edited by magnicu (2024-05-29 08:21:52)

Offline

#2 2024-05-25 14:52:58

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,642

Re: [SOLVED] Disk is read-only after formatting

Welcome to the forums

What is the indication that it is a read only disk?   Is it mounted RO?  Can you not write to it? or does fsck fail?
How are you mounting it? 
Can you write to it with elevated privilege?  (as root?)
What does "set mkfs.ext4" mean?
How do you format a drive with dd?
So, you created a gpt table, created a partition, and wrote it.  Did you use the entire drive?

My guess is that the drive is just fine.  I might even believe the drive is mounted as RW.  My inclination is to think this a permissions problem.

With the drive mounted, what is the output of mount  ?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#3 2024-05-25 15:36:11

magnicu
Member
Registered: 2024-05-25
Posts: 18

Re: [SOLVED] Disk is read-only after formatting

Thanks.

The drive is 99.999% healthy, it's probably just my broken hands.

By read-only, I meant that I can't do much with it: can't create new folder/file, paste to it etc.

I get
/dev/xxx on /run/media/user/xxx-xxx-xxx-xxx-xxx type ext4 (rw,nosuid,nodev,relatime,errors=remount-ro,uhelper=udisks2)
for that disk.

The rw is for read-write, I guess.

I did the following to format it:
sudo dd if=/dev/zero of=/dev/xxx bs=4096 status=progress
sudo fdisk /dev/xxx
then pressed: g, n and then w.
and then sudo mkfs.ext4 -m 1 -b 4096 /dev/xxx

Offline

#4 2024-05-25 15:48:34

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,979

Re: [SOLVED] Disk is read-only after formatting

sudo touch /run/media/user/<xxx-xxx-xxx-xxx-xxx>/icanhazfile

You might want to add a label to the filesystem.

Offline

#5 2024-05-25 16:08:25

loqs
Member
Registered: 2014-03-06
Posts: 18,911

Re: [SOLVED] Disk is read-only after formatting

magnicu wrote:

By read-only, I meant that I can't do much with it: can't create new folder/file, paste to it etc.

If the user performing those operations is not root did you modify the new file-system so that user has permission to perform those operations?

Offline

#6 2024-05-25 16:19:08

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,642

Re: [SOLVED] Disk is read-only after formatting

Yes, it does look like it is is RW.   I suspect permissions.   That is clearly not the verbose output, I assume you are redacting it for some reason, or is your username 'user'

What is the output of ls -l /run/media/user ?  I'm looking for who owns that drive. (Probably root)
Are you the only user using that drive?  If so, ext4 allows us to change the owner from root to another user.

My suggestion would be to create a folder on that drive (as root) named after your user.  Then chown that folder to your user.   If there are other users that need that drive, create similar folders for them.

This is a big drive (by your assertion).  You are mounting it as a user to /run/media/user which ties it to a user session.  Is that what you really want?  Are you looking to make this a removable drive for moving files around?  Are you looking to use it for backup?  Are you looking to have it mounted as part of your regular file system to increase your system's storage?   

The point is, maybe we can find another way to mount it (fstab, systemd-mount).


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#7 2024-05-25 17:01:18

magnicu
Member
Registered: 2024-05-25
Posts: 18

Re: [SOLVED] Disk is read-only after formatting

seth, I was under impression this is not necessary, or is it?

loqs, I did not, but I think ewaller is right and I didn't do formatting/mounting as I wanted.

ewaller, I totally get your way of asking, it's more than fine with me.
Only I use this HDD and I use it as day by day data disk. It's not meant to be removable or for backups etc, just a regular secondary internal disk. And yes, you're right, it's owned by root (drwxr-xr-x 3 root root 4096) at the moment.
Your suggestion with folders was only because you wasn't sure how I use it, am I correct? If not, why would this approach be better instead of making the entire disk owned by user in my case?
And I think I probably didn't perform the formatting the right way, as you said, the /run/media/user ties it to user session and as a result I would lose data on the session end? So doing sudo chown user:user /run/media/user will not help me much I guess.

Offline

#8 2024-05-25 17:08:58

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,979

Re: [SOLVED] Disk is read-only after formatting

You don't need a label, it just makes the udisks mounts more readable.
The root of a new filesystem belongs to the root, "sudo touch /…/icanhazfile" was meant to demonstrate that this is likely the only problem and you'd have to change the ownership of the filesystemd root node or add some user owned directory.

So doing sudo chown user:user /run/media/user will not help me much I guess.

No, because that's the wrong location.

sudo chown user:user /run/media/user/myPornStorage # assuming you used that filesystem label

however would.

I probably didn't perform the formatting the right way

Depends

and then sudo mkfs.ext4 -m 1 -b 4096 /dev/xxx

you probably meant "/dev/sdX1"?
(The pointless obfuscation doesn't allow us to judge your actual actions because we don't know them)

Offline

#9 2024-05-25 17:22:48

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,642

Re: [SOLVED] Disk is read-only after formatting

The data would be safe, it is just that the drive does not automatically mount there.  /run/media is generally intended for transient mounts.

I would suggest using systemd-mount or fstab to automatically mount the drive at a fixed mount point.   As this is an ext4 volume, you can change the owner of the drive using chown and it will stay persistent across mounts.    You might try sudo chown yourusername /run/media/user/xxx-xxx-xxx-xxx and then try writing to the drive as your user.

Edit:  By the way, at this point, we have figured out the format is fine.  It is the mounting and permissions.

Last edited by ewaller (2024-05-25 17:27:04)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#10 2024-05-25 17:50:24

magnicu
Member
Registered: 2024-05-25
Posts: 18

Re: [SOLVED] Disk is read-only after formatting

Yes, it was the permissions problem. Worked as you both suggested with sudo chown user:user /run/media/user/xxx-xxx-xxx-xxx
I didn't mean to make it autounmount(session based?), but I'll leave it this way at the momemnt, as it requires root to access the disk, but this is another subject I will focus on later.
I will use the fstab for automount next time.

Thank you for your help guys

Offline

#11 2024-05-25 17:54:42

cryptearth
Member
Registered: 2024-02-03
Posts: 2,186

Re: [SOLVED] Disk is read-only after formatting

magnicu wrote:

I get
/dev/xxx on /run/media/user/xxx-xxx-xxx-xxx-xxx type ext4 (rw,nosuid,nodev,relatime,errors=remount-ro,uhelper=udisks2)
for that disk.

I did the following to format it:
sudo dd if=/dev/zero of=/dev/xxx bs=4096 status=progress
sudo fdisk /dev/xxx
then pressed: g, n and then w.
and then sudo mkfs.ext4 -m 1 -b 4096 /dev/xxx

just out of pure curiosity: did you unmount the drive before killing it with zeroes? just from the flow of reading it just sounds as: "yea, had this drive automounted - and then in some windows-fashion I zeroed it while it was still mounted"

Offline

#12 2024-05-25 18:14:15

magnicu
Member
Registered: 2024-05-25
Posts: 18

Re: [SOLVED] Disk is read-only after formatting

The first time I did the formatting I'm 100% sure it was unmounted. The second time I'm not so sure, but I think I did unmount it.

Offline

#13 2024-05-25 18:33:25

cryptearth
Member
Registered: 2024-02-03
Posts: 2,186

Re: [SOLVED] Disk is read-only after formatting

have you tried a full system reboot (which usually fixes such instability issues)?
a mounted filesystem and the device it's on usually get locked so stuff like zeroing or repartition should at least raise warnings or are just not possible and error out - so usually I would expect that already the DD would had failed with some error like "device busy" or such but I'm not sure

Offline

#14 2024-05-25 19:11:58

loqs
Member
Registered: 2014-03-06
Posts: 18,911

Re: [SOLVED] Disk is read-only after formatting

cryptearth wrote:

have you tried a full system reboot (which usually fixes such instability issues)?
a mounted filesystem and the device it's on usually get locked so stuff like zeroing or repartition should at least raise warnings or are just not possible and error out - so usually I would expect that already the DD would had failed with some error like "device busy" or such but I'm not sure

Please see post #10.  How could chown fix the issue and file operations work as expected after that if the file-system had been wiped by dd?

Offline

#15 2024-05-26 06:30:19

cryptearth
Member
Registered: 2024-02-03
Posts: 2,186

Re: [SOLVED] Disk is read-only after formatting

loqs wrote:
cryptearth wrote:

have you tried a full system reboot (which usually fixes such instability issues)?
a mounted filesystem and the device it's on usually get locked so stuff like zeroing or repartition should at least raise warnings or are just not possible and error out - so usually I would expect that already the DD would had failed with some error like "device busy" or such but I'm not sure

Please see post #10.  How could chown fix the issue and file operations work as expected after that if the file-system had been wiped by dd?

That's the problem with you guys: I read that OP seem to have fixed it already. My point was to figure what might happened in first place to cause this issue.
I don't know if the kernel is smart enough to error out when one tried to DD onto a disk which has partitions on it mounted or if one is free to crash a disk in a way that should not be possible - but from using fdisk on a disk which the os booted from only WARNS me about "partition mounted" but yet allows me to play around it looks like it could be possible the OP somehow sucessfully executed the DD while the partition was still mounted - which then after partioning caused some deadlock when using mkfs.
We all had our moments and went the way of the dodo and such stupid mistakes which should not be possible due to safeguards in place - and as I not yet encountered such a safety lock where the kernel prevents writing to a device with mounted partitions it's as equal a valid option that OP somehow caused some weired deadlock - which may or may not can be fixed by simple rebooting the system.

Or to put it this way: How should it be possible that mkfs errors out with write protection for a fresh partition created mere seconds ago with fdisk? In this case just rebooting (to flush the maybe forgot to unmount partition) may could had already solved the problem. Instead we get a topic "why doesn't this work?" with noone replying with one of most badic steps: "have you tried turn it off and on again?".
Sure it would be interesting to know why mkfs errored out with write protection - but the first question was: "is it mounted read-only?". Uhm, WHAT? the partition was just created via fdisk - how could it be already mounted in the first place to lock out mkfs? And this is where my question comes: "have you unmounted any partitions before DD and ave you rebooted after you got the error?". Two way more basic and important questions than "is the new partition mounted RO".

It doesn't make sense to ask for the setting of the toaster without previously checking if it's plugged in - likewise it's the wrong order to ask if a partition is mounted RO when the creation of the filesystem fails which is required for a successful mount in the first place

Offline

#16 2024-05-26 07:10:16

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,979

Re: [SOLVED] Disk is read-only after formatting

That's the problem with you guys

You mean pointing out basic facts?

My point was to figure what might happened in first place to cause this issue.

The OP created an ext4 FS and tried to write to it as regular user. It is what they initially described and it will fail for an obvious reason: the root node of the new FS belongs to the root user and nobody else initially gets to write there unless you change that.

it just sounds as: "yea, had this drive automounted - and then in some windows-fashion I zeroed it while it was still mounted"

I don't see where you're getting the automount part, but zero'ing out the drive is irrelevant to partitioning and FS creation itfp* and the OP would still have stumbled over the fdisk warning you pointed out. fdisk will then also perform a partprobe at what point the previously mounted device would disappear and trying to write to the still mounted location would get you a "Bad message" error, mkfs.ext4 will inform you that the partition is still mounted and refuse to create a FS etcetc.
None of this fits the OP description and there're so many warnings and errors along the way that they might have gotten the message that they're doing it wrong.

*except if you deal w/ a stale (typically iso9660) signature but that will cause other symptoms - and you still don't have to zero out the entire device

Offline

#17 2024-05-26 07:16:00

magnicu
Member
Registered: 2024-05-25
Posts: 18

Re: [SOLVED] Disk is read-only after formatting

as far as I got it it's because I formatted the disk as root and by default it doesn't assign(and good it isn't) permissions for other users to use it
ewaller also pointed my focus to the fact it's not automount and said how to deal with it

Offline

Board footer

Powered by FluxBB