1

As you know, if there is no root_owner option, mke2fs use the user and group ID of the user running mke2fs. Let's test it on Ubuntu 22 x86_64 (mke2fs 1.46.5 (30-Dec-2021)):

  1. Generate image

    mke2fs -t ext2 -I 256 -E 'lazy_itable_init=0,lazy_journal_init=0' -O '^large_file' -O '^huge_file' -L ext2test 'diskEmpty.img' 102400k

  2. Mount image

    gnome-disk-image-mounter -w diskEmpty.img

But only root user can write to this... Why?

Let's test root_owner option:

  1. Generate image

    mke2fs -t ext2 -I 256 -E 'root_owner=1000:1000,lazy_itable_init=0,lazy_journal_init=0' -O '^large_file' -O '^huge_file' -L ext2test 'diskEmpty.img' 102400k

  2. Mount image

gnome-disk-image-mounter -w diskEmpty.img

Now I can write to my disk.

Why can't I write to disk without root_owner feature?

2 Answers2

2

The manpage you linked to explains well in fact that since 1.42 version the UID:GID of the root directory no longer default to those of the user running mke2fs.

If, under >1.42 version you want UID:GID of the root directory to be those of the user running mke2fs, you must explicitly specify root_owner as part of the feature list eventually omitting its uid:gid optional parameters.

This is a consequence of a patch from T. Ts'o (mke2fs: don't set root dir UID/GID automatically) which explicitly instructs to:

Add the "-E root_owner[=uid:gid]" option to mke2fs so that the user and group can be explicitly specified for the root directory. If the "=uid:gid" argument is not specified, the current UID and GID are extracted from the running process, as was done in the past.

MC68020
  • 6,281
  • 2
  • 13
  • 44
1

The new file-system's root is owned by root. With default permissions, only root can write to it. Your session user is most likely an ordinary user (UID 1000 probably).

Hermann
  • 5,789
  • 2
  • 17
  • 32