Move snap packages to another location/directory












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.










share|improve this question



























    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.










    share|improve this question

























      3












      3








      3


      2






      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.










      share|improve this question














      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.







      snap 18.04






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 29 '18 at 7:17









      ultimatexultimatex

      390121




      390121






















          2 Answers
          2






          active

          oldest

          votes


















          5














          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.
          sudo 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






          share|improve this answer

































            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.






            share|improve this answer


























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "89"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1029562%2fmove-snap-packages-to-another-location-directory%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              5














              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.
              sudo 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






              share|improve this answer






























                5














                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.
                sudo 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






                share|improve this answer




























                  5












                  5








                  5







                  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.
                  sudo 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






                  share|improve this answer















                  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.
                  sudo 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







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 19 at 12:48

























                  answered Aug 30 '18 at 20:40









                  Muhammad YusufMuhammad Yusuf

                  5115




                  5115

























                      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.






                      share|improve this answer






























                        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.






                        share|improve this answer




























                          4












                          4








                          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.






                          share|improve this answer















                          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.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited May 13 '18 at 17:43







                          user829468

















                          answered Apr 30 '18 at 5:13









                          ultimatexultimatex

                          390121




                          390121






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Ask Ubuntu!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1029562%2fmove-snap-packages-to-another-location-directory%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              How did Captain America manage to do this?

                              迪纳利

                              南乌拉尔铁路局