Cannot edit system file /snap/phpstorm... even with root account in Ubuntu 18.04 [duplicate]
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?
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