3

I want to move installed snap packages to home directory. Snap packages are slightly larger than .deb packages thus they take space in my root partition. I know packages are located in /var/lib/snapd/snaps and they are working with mounting the package to /snap/app_dir. I tried to simlinked, But it didn't work.

4

I finally found a way.

  • First move the snap package to desired location. Let snap_app.snap as the app you want to move. Move the package from /var/lib/snapd/snaps/snap_app.snap to ~/snaps/snap_app.snap.
  • Then you have to change mount option in /etc/systemd/system/snap-snap_app-90.mount,number in the file name may be vary. It has directive What=/snap_app_loaction under [Mount]. Change it to your new snap package location.
  • Finally you have to symlink the snap package to /var/lib/snapd/snaps/.
    Ex: ln -s /var/lib/snapd/snaps/snap_app ~/snaps/snap_app.snap

Snap package is originally mount in to /snap/snap_app directory. you can check it with mount. Reboot your machine and you are all done.

3

Change snaps installation directory

This is a common issue that many asks for it, it seems snap developers are not intended to solve it soon, so some solutions was suggested as I search.

The first solution that was strongly refused by the community,but I didn't try, is to use symbolic link to link the directories which leads to snaps, this method seems not to work as the community replies asy that apparmom not working with symbolic links.

The Second solution is mount --bind the directory /val/lib/snapd/snaps which works fine for me with the already installed applications but failed to install new applications because I was moving the directory to another partition. That gave me an error about hard linking the snap application with the cache directory which is located in /var/lib/snapd/cache. I don't know if this solution may work if the location are in the same partition or not; but this is the reason why I am moving the snap directory to free some space from partition to another one.

Third and working option is to move the /var/lib/snapd directory as a whole then mount --bind to it from another location and that worked for me and here is the steps.

Just a small note ,you already know, After the rsync is done in the below steps, you can backup the data inside /var/lib/snapd to another location until the whole process is successfully done then you can remove the backup data if you want to free more space.

##############################################################################
# Take Care this section may break the System !!!
##############################################################################
##Move snap folder to Home instead of root.
#Create the directory : you can change the location
mkdir /home/$USER/snap/snapd

#Copy the data
sudo rsync -avzP /var/lib/snapd  /home/$USER/snap/snapd

#Do backups
sudo mv /var/lib/snapd /var/lib/snapd.bak
sudo cp /etc/fstab /etc/fstab.bak

#Change fstab (Change $USER with your name or change the path totally)
echo "/home/$USER/snap/snapd /var/lib/snapd none bind 0 0" | sudo tee -a /etc/fstab

#remount fstab Or reboot.
mount -a

if ls  /var/lib/snapd/ | grep snaps
then
    echo "Re-mounting snapd folder is done successfully. !!!!"
    sudo rm -rf /var/lib/snapd.bak
else
    echo "WARNING : Re-mounting snapd folder failed, please revert !!!!! "
    echo "WARNING : Re-mounting snapd folder failed, please revert !!!!! "
    echo "WARNING : Re-mounting snapd folder failed, please revert !!!!! "
    echo "WARNING : Re-mounting snapd folder failed, please revert !!!!! "
    echo "WARNING : Re-mounting snapd folder failed, please revert !!!!! "

    # Trying to revert automatically
    sudo cp /etc/fstab.bak /etc/fstab

    sudo mount -a
    sudo umount /var/lib/snapd

    sudo mv /var/lib/snapd.bak /var/lib/snapd

    echo "Files located at ~/snap/snapd should be removed, but it keeped for
    recovery until you ,manually, reboot the system and make sure the service
    is running correctly then manually you can remove that folder ~/snap/snapd
    !!!!!!!!!!!!!!, you should do that manually."

fi
##############################################################################
# Take Care the pervious section may break the System !!!
##############################################################################

References

  1. Custom disk location for certain snaps issue
  2. ask ubuntu Question (Not best solution) Link
  3. Suggestion to use bind mount instead of symbolic links in moving snap directories Link
  4. Differences between bind mount and symbolic links Link
  5. Make bind mount permenant

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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