2

This question already has an answer here:

I installed a snap package in Ubuntu 18.04 package and I want to edit one of its files using root account. First I switched to root with su, but then when I opened file in nano it tells me:

 [ File '/snap/phpstorm/36/bin/phpstorm64.vmoptions' is unwritable ]

Then I tried this:

root@elahe-VPCEA31FX:/home/elahe# sudoedit  /snap/phpstorm/36/bin/phpstorm64.vmoptions

after above command the file opened in nano, but after making changes and saving with Ctrl+O and after exiting with Ctrl+x I got this message:

sudoedit: unable to write to /snap/phpstorm/36/bin/phpstorm64.vmoptions: Read-only file system
sudoedit: contents of edit session left in /var/tmp/phpstorm64XXRCQzZi.vmoptions

I even tried to change the permissions of the file with this command:

root@elahe-VPCEA31FX:/home/elahe# chmod 755  /snap/phpstorm/36/bin/phpstorm64.vmoptions

and got this:

chmod: changing permissions of '/snap/phpstorm/36/bin/phpstorm64.vmoptions': Read-only file system

It is really amazing that the root user cannot edit a file! Is this a bug?

marked as duplicate by Jos, Fabby, Kevin Bowen, George Udosen, Zanna Jun 15 '18 at 8:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Not even root can modify a read-only file system (which is what /snap is). – Jos Jun 14 '18 at 17:02
  • Do you mean that there a no way to edit a system file?! – Mr Jan Jun 14 '18 at 17:03
5

The snap files are mounted as read-only (ro), and you can check this by using the mount command.

mount |grep snap
/var/lib/snapd/snaps/vlc_158.snap on /snap/vlc/158 type squashfs (ro,nodev,relatime,x-gdu.hide)
/var/lib/snapd/snaps/core_4486.snap on /snap/core/4486 type squashfs (ro,nodev,relatime,x-gdu.hide)
/var/lib/snapd/snaps/core_4571.snap on /snap/core/4571 type squashfs (ro,nodev,relatime,x-gdu.hide)
/var/lib/snapd/snaps/vlc_365.snap on /snap/vlc/365 type squashfs (ro,nodev,relatime,x-gdu.hide)
/var/lib/snapd/snaps/vlc_190.snap on /snap/vlc/190 type squashfs (ro,nodev,relatime,x-gdu.hide)
/var/lib/snapd/snaps/core_4650.snap on /snap/core/4650 type squashfs (ro,nodev,relatime,x-gdu.hide)

To modify files in squashfs, you need to unsquash it, modify the files and then re-make the squashfs file. E.g., if I want to modify files in /var/lib/snapd/snaps/vlc_365.snap

sudo umount /snap/vlc/365
sudo unsquashfs /var/lib/snapd/snaps/vlc_365.snap

Modify anything you want in squashfs-root (it's where all the files are unpacked into), and then repack it.

sudo mksquashfs squashfs-root vlc_365.snap

Copy it back to its original location and re-mount it.

sudo cp vlc_365.snap /var/lib/snapd/snaps/vlc_365.snap
sudo mount -t squashfs -o ro,nodev,relatime,x-gdu.hide /var/lib/snapd/snaps/vlc_365.snap /snap/vlc/365
  • Great solution. Saved my time. – Amir Forsati Jun 4 at 9:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.