Skip to main content
32 votes

Why is a file with 400 permissions seen writable by root but read-only by user?

I think you have have misunderstood what -w does. It does not check to see if the file has "Write permissions", it checks to see if the file is writable by the invoking user. More specifically, it ...
Stephen Harris's user avatar
28 votes
Accepted

Why is a file with 400 permissions seen writable by root but read-only by user?

test -w aka [ -w doesn't check the file mode. It checks if it's writable. For root, it is. $ help test | grep '\-w' -w FILE True if the file is writable by you. The way I would test would ...
phemmer's user avatar
  • 72.1k
25 votes

Why is my file system mounted as read-only?

I had a similar issue that is not solved with the solution above. Linux may mount a drive as 'read-only' because of Fastboot on Windows 10. A shutdown with the Fastboot feature keeps the Windows ...
Diaz's user avatar
  • 351
21 votes
Accepted

Make readonly /etc writeable

squashfs is a read-only compressed file system. It has no provision to make modification to it once it's been created. So you couldn't write to it even if the underlying block device could be made ...
Stéphane Chazelas's user avatar
15 votes

Why doesn't mount respect the ro option?

It is the correct behaviour. You use the -f flag, which mean: -f, --fake: Causes everything to be done except for the actual system call; if it's not obvious, this ``fakes'' mounting the ...
Giacomo Catenazzi's user avatar
13 votes

Why does setting a variable readonly in the outer scope prevent defining a local variable with the same name?

Whether readonly in one scope will prevent a variable with the same name to be declared in child scopes (in those shells that have dynamic scoping such as bash) varies between shells¹. That came up ...
Stéphane Chazelas's user avatar
12 votes
Accepted

Bash variables do not expand inside array if declare is used

With: curl_version="$(command curl --version | awk 'NR==1 {print $2}')" declare -r curl_version within a function, you're setting the $curl_version global variable to some value and then ...
Stéphane Chazelas's user avatar
10 votes

read only TMOUT variable – workaround to disable automatically exit shell when there is no activity

Here is the thing, When the session variable is "Read Only" you have to replace the current shell process with the command by "exec" So, the Answer to your question is: $> exec env TMOUT=0 bash ...
Alper t. Turker's user avatar
8 votes
Accepted

Mount ext4 read-only

mount -oro,noload /dev/foo /mnt/disk
Ole Tange's user avatar
  • 35.7k
8 votes

HFS+ file system being mounted as read-only

You need to turn off the journaling if you want to write to it from Ubuntu. Ubuntu only has support for writing to non-journaled HFS+ volumes. Disabling journaling from HFS+ is still possible up to OS ...
Prime Optimus's user avatar
8 votes
Accepted

Why does setting a variable readonly in the outer scope prevent defining a local variable with the same name?

The underlying problem here is that the local keyword doesn't really create a local variable, or at least, not in the sense that you're expecting. Per the Bash Reference Manual: Variables local to ...
ruakh's user avatar
  • 1,702
7 votes

Linux, how to change HDD state from ReadOnly after temporarly crash?

Like Jose Luis Martin suggested use blockdev, my 2cent is to do a remount rw and forcefsck (assuming sda is your disk) blockdev --setrw /dev/sda mount /dev/sda -o remount,rw touch /forcefsck
Roberto's user avatar
  • 71
7 votes

Bash variables do not expand inside array if declare is used

The first line of the function creates a global variable. curl_version="$(command curl --version | awk 'NR==1 {print $2}')" The second line of the function creates a readonly, empty, ...
glenn jackman's user avatar
6 votes

Why does setting a variable readonly in the outer scope prevent defining a local variable with the same name?

This is documented under local in www.gnu.org/software/bash/manual/bash.html#Bash-Builtins The return status is zero unless local is used outside a function, an invalid name is supplied, or name is a ...
Paul_Pedant's user avatar
  • 8,959
5 votes
Accepted

Is `mount -o remount,ro` guaranteed to fail if there are files open for writing?

Yes. The relevant code is in sb_prepare_remount_readonly (as of Linux 4.0, the code may be organized differently on other versions). The logic is: For each instance of the mount: If that instance is ...
Gilles 'SO- stop being evil''s user avatar
5 votes

How can I filter read only file systems out of df output?

Yes, snap's intrusion into the filesystems list can be annoying... You're on the right lines with df -x - as Snapcraft says, all snaps use the read-only Squashfs filesystem, so you can filter them all ...
mwfearnley's user avatar
  • 1,126
4 votes

DHCP and read-only root filesystem

similar to Daniel Griscom Answer but a little simpler. you can add tmpfs /var/lib/dhcp/ tmpfs nodev,nosuid,size=1M,mode=1777 0 0 in /etc/fstab this creates a temporary file-system in RAM and ...
Stefan Krüger s-light's user avatar
4 votes

Remount a busy disk to read-only mode

Use mount's force option (assuming your mount has one; GNU mount does not, but BSD and macOS for example do): mount -f -o remount,ro /mount/point Of course, your mileage may vary depending on actual ...
Piotr Findeisen's user avatar
4 votes

read only TMOUT variable – workaround to disable automatically exit shell when there is no activity

I my case, it is defined in /etc/profile.d/bash_autologout.sh: TMOUT=1800 readonly TMOUT export TMOUT To find it, I did: sudo find /etc/ -name "*" | xargs sudo grep "TMOUT" 2>&1 | grep -v "...
dagos's user avatar
  • 41
4 votes

Filesystem suddenly read-only?

You're confusing cause and effect. The filesystem was most likely mounted Read Only because of the I/O error. If you look at the kernel log (either via dmesg or journalctl -k you'll probably see ...
Shadur-don't-feed-the-AI's user avatar
4 votes
Accepted

USB stick read-only in GNOME/nautilus?

Maybe it is related with this nautilus bug Nautilus says the USB stick is read only when it is not. Restarting nautilus clears the issue (at least temporally): $ killall nautilus
slamora's user avatar
  • 156
4 votes

usb read only after formatting

Was there an OS prior to the re-format?, like a Linux Live distro? If so, especially if it was GPT, the boot flag is probably set. If you moved the USB stick over to a Windows 10 PC and formatted it ...
wally johnn's user avatar
4 votes
Accepted

Device writable even after `blockdev --setro`

I guess blockdev --setro works similar to chmod: It affects only future openings of the object. But I can offer a work-around for your detection problem: The /proc/$PID/cwd value is changed to / ...
Hauke Laging's user avatar
  • 90.2k
4 votes
Accepted

How to fix read-only EFI system partition?

Note that the error message is "Could not delete variable: Read-only file system". It is actually trying to manipulate the UEFI boot variables, and failing there. The errors are actually referring to ...
telcoM's user avatar
  • 99.4k
4 votes
Accepted

Function to conditionally set a variable read-only

declare -r make a variable readonly but also declares it in the current scope and so makes it local to the current function. You'd want readonly instead that only does the former: readonly_once() { ...
Stéphane Chazelas's user avatar
4 votes
Accepted

Is it possible to remove or modify readonly variable?

This is a feature of read-only variables in bash. A read-only variable cannot be changed or unset: From the bash manual, regarding declare -r (the same as readonly): -r Make names readonly. ...
Kusalananda's user avatar
  • 338k
4 votes

Formatting a problematic USB Drive

You should write Debian ISO with dd if=/path/to/file of=/dev/sdY; sync (change the Y to the correct letter. Read carefully it is very very similar to what you did.). Not in a partition. Just do it ...
ctrl-alt-delor's user avatar
4 votes
Accepted

Why Am I able to edit /etc/resolv.conf on a read only file system?

However, I see that I am still able to change the contents of file /etc/resolv.conf How is that possible? It's either a symbolic link to a tmpfs filesystem mounted e.g. in /run or /var or you're ...
Artem S. Tashkinov's user avatar
4 votes
Accepted

Can not delete files

Here's the error you're being given: Read-only file system The filesystem is read-only and you will not be able to make any changes to it. It's nothing to do with SELinux or per-file permissions. ...
Chris Davies's user avatar
4 votes
Accepted

Mount root filesystem with user permission using sshfs

sshfs [email protected]:/ … acts on the server side as the same user you would log in with ssh [email protected], so most likely hostname (kinda misleading name, it's a user). If hostname is not ...
Kamil Maciorowski's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible