Change lxd location with snap install

Just done a fresh install of Ubuntu 18.10 and install lxd, noticed by default with apt it was installed as a snap package. Previously on my older machines i had /var/lib/lxd bind mounted to a folder on a larger drive as my root partition is not big enough to hold images,containers, snapshots.

With the snap package install how do i achieve the same result with containers/images and snapshots in a folder on my larger drive?

I used a link. A buddy directed me through the procedure.
If you look for ‘symlink’ that’s what I am remembering. This enabled to have lots of space and keep my /var file space to something reasonable without needing to go to a 3 partition system (boot (of whatever type), root and home - - - I’m using something different).

Please advise if my idea doesn’t work.

sorry, not sure i follow, what did you symlink? as “snap package” file systems are not something i am familiar with.

Indeed, in Ubuntu 18.10, when you sudo apt install lxd, you get the snap package.
Let’s verify by launching a 18.10 container.

$ lxc launch ubuntu:18.10 mycosmic
Creating mycosmic
Starting mycosmic                           

$ lxc ubuntu mycosmic
+ exec /bin/login -p -f ubuntu
Welcome to Ubuntu 18.10 (GNU/Linux 4.15.0-38-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Fri Nov  2 14:57:49 UTC 2018

  System load:    0.42      Processes:           23
  Usage of /home: unknown   Users logged in:     0
  Memory usage:   0%        IP address for eth0: 10.52.252.146
  Swap usage:     4%

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.



The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@mycosmic:~$ apt policy lxd
lxd:
  Installed: (none)
  Candidate: 1:0.4
  Version table:
     1:0.4 500
        500 http://archive.ubuntu.com/ubuntu cosmic/main amd64 Packages
ubuntu@mycosmic:~$ sudo apt install lxd
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  libfreetype6
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
  lxd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 11.1 kB of archives.
After this operation, 75.8 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu cosmic/main amd64 lxd all 1:0.4 [11.1 kB]
Fetched 11.1 kB in 0s (53.0 kB/s)
Preconfiguring packages ...
Selecting previously unselected package lxd.
(Reading database ... 28248 files and directories currently installed.)
Preparing to unpack .../archives/lxd_1%3a0.4_all.deb ...
=> Installing the LXD snap
==> Checking connectivity with the snap store
==> Installing the LXD snap from the 3.0 track for ubuntu-18.10
snap "lxd" is already installed, see 'snap help refresh'
==> Cleaning up leftovers
Failed to stop lxd.socket: Unit lxd.socket not loaded.
Failed to stop lxd.service: Unit lxd.service not loaded.
Failed to stop lxd-containers.service: Unit lxd-containers.service not loaded.
Failed to disable unit: Unit file lxd.socket does not exist.
=> Snap installation complete
Unpacking lxd (1:0.4) ...
Setting up lxd (1:0.4) ...
ubuntu@mycosmic:~$ apt policy lxd
lxd:
  Installed: 1:0.4
  Candidate: 1:0.4
  Version table:
 *** 1:0.4 500
        500 http://archive.ubuntu.com/ubuntu cosmic/main amd64 Packages
        100 /var/lib/dpkg/status
ubuntu@mycosmic:~$ snap info lxd
name:      lxd
summary:   LXD - the container lightervisor
publisher: Canonical✓
license:   unset
description: |
  LXD is a container manager for system containers.
  
  It offers a REST API to remotely manage containers over the network,
  using an image based workflow and with support for live migration.
  
  Images are available for all Ubuntu releases and architectures as well
  as for a wide number of other Linux distributions.
  
  LXD containers are lightweight, secure by default and a great
  alternative to virtual machines.
  
  Supported configuration options (snap set lxd [<key>=<value>...]):
    - criu.enable: Enable experimental live-migration support [default=false]
    - daemon.debug: Increases logging to debug level [default=false]
    - daemon.group: Group of users that can interact with LXD [default=lxd]
    - ceph.builtin: Use snap-specific ceph configuration [default=false]
    - openvswitch.builtin: Run a snap-specific OVS daemon [default=false]
commands:
  - lxd.benchmark
  - lxd.buginfo
  - lxd.check-kernel
  - lxd.lxc
  - lxd
  - lxd.migrate
services:
  lxd.activate: oneshot, enabled, inactive
  lxd.daemon:   simple, enabled, inactive
snap-id:      J60k4JY0HppjwOjW8dZdYc8obXKxujRu
tracking:     stable/ubuntu-18.10
refresh-date: today at 14:51 UTC
channels:                                
  stable:        3.6         (9412) 53MB -
  candidate:     3.6         (9412) 53MB -
  beta:          ↑                       
  edge:          git-93b7821 (9407) 53MB -
  3.0/stable:    3.0.2       (9348) 52MB -
  3.0/candidate: 3.0.2       (9348) 52MB -
  3.0/beta:      ↑                       
  3.0/edge:      git-9ada661 (9344) 52MB -
  2.0/stable:    2.0.11      (8023) 28MB -
  2.0/candidate: 2.0.11      (8023) 28MB -
  2.0/beta:      ↑                       
  2.0/edge:      git-c7c4cc8 (9257) 26MB -
installed:       3.6         (9239) 69MB -
ubuntu@mycosmic:~$ 

What happens is that apt installs a stub lxd deb package which then installs the snap package of LXD.
The user is prompted whether (for the snap) to track the stable/3.0 channel or stable (for 3.6 currently).

To come back to your question, what storage driver do you use on this external disk? Is it just a directory with dir or something else?

yes just the dir driver, could it be that i can bind mount /var/snap/lxd/common/lxd like i did before?

This issue has been mentioned before. Googling showed this result, https://forum.snapcraft.io/t/custom-disk-location-for-certain-snaps/3022/6 which explains the perils of bind-mounting in the snap.

Ideally, you would use ZFS or btrfs which would be picked up easily by the snap.
I am not very familiar with this, therefore let’s get the thoughts of someone else (or do a better googling than me).

ok, thank you :slight_smile:

currently i have successfully bind mounted /var/snap/lxd/common
which seems to imply from the posting below that it will be consistent between snap updates, and it doesn’t seem to cause a bind-mount conflict.

I did previously play with replacing the storage pool in my default profile and that only seemed to put the container in the new pool and not the image, so i assume the same would happen even if i used zfs

What I did was link /var/snap to a directory NOT in /var - - - this meant that I could have loads of room. /var was set up for 12 GB of space (IIRC) and I was running out. So I changed things and that issue went away.
If you set up your system so that you only have 3 lowest level directories (boot, root and home) and have a huge / (root) directory all of the former is moot.

ok thankyou, I’ll give that a go if bind mounting proves to be a pain long term :slight_smile: