I am not going to start yet another debate about whether snaps are good or bad and if you should use it. For me snaps are solving a lot of problems. Yes, they might be not ideal but they work and they work well (both from a developer and a user perspective).
I recently heard someone’s claim that once application is packed as a snap you cannot modify it. For example, you cannot edit a Python file (related to a deployed snap) and thus you cannot quickly add more logging which could help troubleshooting and hotfixing various issues, because the whole snap is read-only.
Indeed, you cannot change a file belonging to a snap, but unfortunately people are taking first answers (from LLMs or search engines) as gospel.
But what if I told you that there is a way how you can edit a file without rebuilding the snap? Just use a mount
bind. It’s a quick and dirty trick that works well for hotfixing, debugging or just hacking around.
- Make a copy of your existing file
cp /snap/whatever/current/script.py /tmp/script.py
- Modify your newly created copy
- Use
mount
to apply changes
mount -o ro,bind /tmp/script.py /snap/whatever/current/script.py
If you want to persist this change as a permanent solution, you will need to figure out how to make this mount
to survive reboots and disable snap refreshes. You might want to check the docs for snap refresh --hold=
Another way to persist your changes is to re-pack and re-build the snap:
❯ root@ubuntu:/var/lib/snapd/snaps$ snap install maas
❯ root@ubuntu:/var/lib/snapd/snaps$ unsquashfs maas_26661.snap
❯ root@ubuntu:/var/lib/snapd/snaps$ snap pack ./squashfs-root
❯ root@ubuntu:/var/lib/snapd/snaps$ sudo snap install --dangerous maas_3.3.1-13169-g.94920eb1e_arm64.snap
It’s not pretty, but it works – and sometimes that’s all you need.