Score:0

.img file gets opened as read-only

in flag

I'm trying to create an ext4 filesystem in a .img file so that I can transfer it to other machines. Unfortunately, when I unmount and re-mount it, it gets mounted as read-only. I can reproduce the issue on two separate PCs -- a laptop running Ubuntu 20.04 and a desktop running Ubuntu 23.04 -- using the following steps:

  1. In GNOME, run Disks, select "New disk image", create a 1GB .img file in your home directory, click "Attach new image", then "Format partition" and format it as ext4. This creates device /dev/loop5, contents mounted at /media/my-username/volume-label.
  2. Open it in GNOME Files (nautilus). Copy some files into it.
  3. Unmount it using GNOME Files (nautilus).
  4. Mount it again by clicking on the .img file in GNOME Files.
  5. Try to copy some more files - you can't - it's read-only.

How can I mount it multiple times properly?

P.S. In case it's relevant, a puzzling thing is when I created the file system, a window opened very briefly asking for my password, but it closed before I had a chance to type anything, and then the new FS opened in Files seemingly without any issues.

Further info:

$ ls -l *.img;id
-rw-rw-r-- 1 k314159 k314159 1000000000 Aug 16 10:27 t.img
uid=1000(k314159) gid=1000(k314159) groups=1000(k314159),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),120(lpadmin),132(lxd),133(sambashare),136(docker)
$ grep loop5 /etc/mtab
/dev/loop5 /media/k314159/test ext4 rw,nosuid,nodev,relatime 0 0
# Then after using GNOME Files (nautilus) to dismount & remount:
$ grep loop5 /etc/mtab
/dev/loop5 /media/k314159/test ext4 ro,nosuid,nodev,relatime 0 0

waltinator avatar
it flag
What is the protection/ownership of the `.img` file? Do `ls -l *.img;id`. How is it mounted? Do: `grep img /etc/mtab`. Please [edit] your question to add whatever information you get. Do not use Add Comment.
user10489 avatar
in flag
What filesystem type is the image? Some formats (like squashfs and iso9660) do not directly support writing.
k314159 avatar
in flag
@user10489 it's ext4 (as I mentioned in bullet point 1, but easy to miss)
k314159 avatar
in flag
@waltinator requested info added to question.
user10489 avatar
in flag
Well, obviously it is read only from the second mtab line. Not sure why gnome mounted it read only. Might need to manually mount it as root.
Score:2
in flag

I found that the issue is that the GNOME Disk Image Mounter, when run from nautilus, always mounts .img files in read-only mode. There is a request to add a read-write option but this has not been implemented yet:

https://gitlab.gnome.org/GNOME/gnome-disk-utility/-/issues/126

The workaround is to start the Disks GUI and mount the .img from there, and untick the "mount read-only" check box at the bottom. Alternatively, run the disk image mounter from the command line:

gnome-disk-image-mounter --writable <container path>
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.