2

To be able to test out of disk situations I tried to set up a file-based size-limited file system like this:

$ dd if=/dev/zero of=file.fs bs=1MiB count=1
$ mkfs.ext4 file.fs
$ udisksctl loop-setup -f file.fs
  Mapped file file.fs as /dev/loop1.
$ udisksctl mount --options rw -b /dev/loop1
  Mounted /dev/loop1 at /media/myuser/29877abe-283b-4345-a48d-d172b7252e39
$ ls -l /media/myuser/29877abe-283b-4345-a48d-d172b7252e39/
  total 16
  drwx------ 2 root root 16384 Dec  2 22:08 lost+found

But as can be seen, it's made writable only for root. How do I make it writable for the user that is running the commands?

I can't chown or chmod it since that also gives "Operation not permitted".

I tried with some options to udisksctl like -o uid=<id> but then I get an error about that mount option not being allowed.

Since this should be able to run for normal users I can't use root or sudo.

I am on Ubuntu 22.04.1.

don_crissti
  • 82,805
Zitrax
  • 274

1 Answers1

3

Yeah, that's kind of mean :) But you can work around:

mkfs.ext4 takes a -d directory/ option with which you can specify a directory containing an initial content for the file system; if you already know which directories you'll later want to populate, that would be a good place to start.

mkfs.xfs supports -p protofile; that probably does exactly what you want to do. A file myprotofile containing naught but:

thislinejustforbackwardscompatibility/samefornextline
1337 42
d--777 1234 5678

where the first line is just a single string for backwards compatibility, which will be ignored; the second line must contain two numbers that will be ignored. (See man mkfs.xfs for more details than I remember from the top of my head.)

The third line contains a filemode uid gid tuple, describing the root directory. Replace 1234 with your user id of choice, and 5678 with the group id of your choice.

A subsequent

mkfs.xfs -p myprotofile -f file.fs

should do (but your image file needs to be at least 16 MB in size for a default-configure mkfs.xfs), so

dd if=/dev/zero of=file.fs bs=1MiB count=16 
mkfs.xfs -p myprotofile -f file.fs
udisksctl loop-setup -f file.fs

works and automounts the filesystem rw on my system (but that's not necessarily the case on your system – your mount thing should work; but --options rw seems a bit superfluous).

  • Thanks! I was not aware of the -d option to mkfs.ext4 and with that it worked fine, I just pre-created an empty directory with the permissions I want and pointed to that. – Zitrax Dec 02 '22 at 22:17
  • Glad to hear it works. I find it a bit sad that makes.ext4 would use that directory's owner as owner of its top directory, to be honest (the mkfs.xfs method allowed me to do that) – Marcus Müller Dec 03 '22 at 08:11