I have Ubuntu 18.04 LTS installed.
I inserted USB-flash to my laptop. It was automounted to /media/username/DISKLABEL and opened in Nautilus. I can read and write objects to it.
How can I access it from the application, which is installed as Snap?
I tried snaps of the following applications such as gedit
, arduino-mhall119
, organize-my-files
. All them show me errors if I navigate to /media folder:
Could not read the contents of Media
Error opening the directory of '/media': permission denied
Output of active Snap interfaces is below:
$ snap interfaces | grep -v ".*-$"
Slot Plug
:browser-support organize-my-files
:core-support core:core-support-plug
:cups-control gedit
:desktop gedit,organize-my-files
:desktop-legacy gedit,organize-my-files
:gsettings gedit,organize-my-files
:home arduino-mhall119,gedit,organize-my-files
:network arduino-mhall119,gedit,organize-my-files,pulsemixer
:opengl organize-my-files
:pulseaudio organize-my-files,pulsemixer
:unity7 arduino-mhall119,gedit,organize-my-files
:wayland gedit
:x11 arduino-mhall119,organize-my-files,pulsemixer
gnome-3-26-1604:gnome-3-26-1604 gedit
gtk-common-themes:gtk3-themes gedit
gtk-common-themes:icon-themes gedit
gtk-common-themes:sound-themes gedit
- arduino-mhall119:serial-port
- gedit:avahi-observe
- gedit:mount-observe
Updates:
- connecting mount-observe to Gedit with
snap connect gedit:mount-observe
does not help. - it seems that we need special Snap with support of
removable-media
interface.
So we need special prepared Snap with support of
removable-media
connector/interface/plugin.Below is a list of Snap with removable-media plug described in YAML-manifest :
One can find other Snaps released by SnapCrafters with the following GitHub search link.
So if the application does not have auto-connect of
removable-media
we need to connect it manually with:But not all applications have this plug/interface in YAML-manifest.
It is hard to find packages by supported plugs - so I created issue "Add ability for parametric Snap search with filters (plugs, such as
removable-media
and so on)" about snapcraft.io site.The bug about
snap
command named "snap
should provide functionality to find packages with needed plug or connector" was filed to launchpad as bug 1776938.The Ubuntu Software program will now show a Permissions button on the page of each Snap program you have installed.
Click on Permissions, and a pop-up window gives you the option 'Read/write files on removable storage devices', with a button to the right that you click to turn this on.
You need to activate each program one by one this way, but there is nothing special to remember, other than that the button exists.
To access USB storage from a snap, it needs a connection to
removable-media
. Some snaps are automatically connected to it. If not, you can manually connect it using the following command:Sometimes, this command fails with the following message:
This means the publisher of the package has not indicated that the application can use removable media. In this case, you should contact the publisher and ask them to add the
removable-media
interface to the plugs of the Snap.Most Snaps show how to contact the publisher; run
snap info snap-name
and look at thecontact
field for an email address or a URL.Automatically connecting
removable-media
It is possible for publishers to request that their Snap is automatically connected to the
removable-media
interface. This is allowed for applications that fall into the following categories.If an application falls into one of these categories and
removable-media
is not automatically connected to the application, please contact the publisher and ask them to request an auto-connection toremovable-media
.The interface which needs to be connected is
removable-media
.Can access files from removable media in /media and /run/media. This can be used to give an app access to mounted USB sticks and external hard drives on a desktop.
The
mount-observe
interface only lets you view what is mounted, not access mounts:Can query system mount information. This is restricted because it gives privileged read access to mount arguments and should only be used with trusted apps.
Neither of these two interfaces will auto-connect. From https://github.com/snapcore/snapd/wiki/Interfaces#removable-media
The snap app needs to have
removable-media
plug enabled in order to access USB storage and other drives. You can do this through Part 1 below.If you are unlucky enough to need a snap that does not have
removable-media
support, then you can try adding it as per the instructions below.I had to do this for the freeplane (mind-mapping app) snap and a similar process should work for other snaps as well. I will use freeplane in the instructions below - please replace it with the equivalent for your snap app.
Part 1: Check for removable-media support
snap list | grep freeplane
. This showed the snap name isfreeplane-mindmapping
with version number [1.9.7].sudo snap connect freeplane-mindmapping:removable-media
. If you do not get any error messages, then removable-media is enabled and STOP HERE: your work is done!error: snap "freeplane-mindmapping" has no plug named "removable-media"
, then emovable-media plug is not enabled in that snap app.snap connections freeplane-mindmapping
, which should result is something like:Note that the above output does not show the
removable-media
interface, but it does show a list of other interfaces started withcups-control
and ending withx11
. We will be addingremovable-media
afterx11
in the .yaml configuration file for this snap app.Part 2: Unsquash the snap file
As per Bernard Wei' answer, snap files are mounted as read-only so to modify them, you will need to unsquash it, modify the files and then re-make the squashfs file.
mount |grep freeplane
to find the snap filepath (/var/lib/snapd/snaps/freeplane-mindmapping_29.snap
) and mount point (/snap/freeplane-mindmapping/29
). Keep a note of both the filepath and the mount point as these will be needed later.sudo umount /snap/freeplane-mindmapping/29
. Typingsnap list | grep freeplane
will now show the snap as 'broken'.sudo unsquashfs /var/lib/snapd/snaps/freeplane-mindmapping_29.snap
. The snap file will be extracted to~/squashfs-root/
.~/squashfs-root/meta
(eg using Ctrl-L).Edit as Administrator
the filesnap.yaml
.plugs
and enter inremovable-media
afterx11
:Part 3: Reinsert the modified snap file
sudo mksquashfs squashfs-root freeplane-mindmapping_29.snap
. The modified snap file will be created in the Home folder.sudo cp freeplane-mindmapping_29.snap /var/lib/snapd/snaps/freeplane-mindmapping_29.snap
.sudo mount -t squashfs -o ro,nodev,relatime,x-gdu.hide /var/lib/snapd/snaps/freeplane-mindmapping_29.snap /snap/freeplane-mindmapping/29
.snap list | grep freeplane
will no longer show the snap as "broken".snap connections freeplane-mindmapping
does not showremovable-media
, then reboot.snap connections freeplane-mindmapping
should showremovable-media
.snap connect freeplane-mindmapping:removable-media
. You should now have access to removable media!squashfs-root
folder usingsudo rm -r ~/squashfs-root
.ln -s /path/to/folder ~/snap/freeplane-mindmapping/29/
.Good luck!