How to set the container to can use the maximum resources of the physical machine

I already created a private image tar.gz file according to my personal lxc container yesterday. So for me, I do not really lose my data.

I met an Warning information
WARN[05-09|12:34:18] Failed settting up shared mounts: no such file or directory

It is from:

(base) admin1@admin1-S2600CO:/var/snap $ sudo lxd --debug --group lxd

INFO[05-09|12:34:18] LXD 4.0.1 is starting in normal mode path=/var/snap/lxd/common/lxd
INFO[05-09|12:34:18] Kernel uid/gid map:
INFO[05-09|12:34:18] - u 0 0 4294967295
INFO[05-09|12:34:18] - g 0 0 4294967295
INFO[05-09|12:34:18] Configured LXD uid/gid map:
INFO[05-09|12:34:18] - u 0 1000000 1000000000
INFO[05-09|12:34:18] - g 0 1000000 1000000000
INFO[05-09|12:34:18] Kernel features:
INFO[05-09|12:34:18] - netnsid-based network retrieval: no
INFO[05-09|12:34:18] - uevent injection: no
INFO[05-09|12:34:18] - seccomp listener: no
INFO[05-09|12:34:18] - seccomp listener continue syscalls: no
INFO[05-09|12:34:18] - unprivileged file capabilities: yes
INFO[05-09|12:34:18] - cgroup layout: legacy
WARN[05-09|12:34:18] - Couldn’t find the CGroup memory swap accounting, swap limits will be ignored
INFO[05-09|12:34:18] - shiftfs support: no
INFO[05-09|12:34:18] Initializing local database
DBUG[05-09|12:34:18] Initializing database gateway
DBUG[05-09|12:34:18] Start database node address= role=voter id=1
WARN[05-09|12:34:18] Failed settting up shared mounts: no such file or directory
INFO[05-09|12:34:18] Starting /dev/lxd handler:
INFO[05-09|12:34:18] - binding devlxd socket socket=/var/snap/lxd/common/lxd/devlxd/sock
INFO[05-09|12:34:18] REST API daemon:
INFO[05-09|12:34:18] - binding Unix socket socket=/var/snap/lxd/common/lxd/unix.socket
INFO[05-09|12:34:18] - binding TCP socket socket=192.168.0.30:8443
INFO[05-09|12:34:18] Initializing global database
DBUG[05-09|12:34:18] Dqlite: connected address=1 attempt=0
INFO[05-09|12:34:18] Firewall loaded driver “xtables”
INFO[05-09|12:34:18] Initializing storage pools
DBUG[05-09|12:34:18] Initializing and checking storage pool “default”
DBUG[05-09|12:34:18] Mount started driver=zfs pool=default
DBUG[05-09|12:34:18] Mount finished driver=zfs pool=default
INFO[05-09|12:34:18] Initializing daemon storage mounts
INFO[05-09|12:34:18] Initializing networks
DBUG[05-09|12:34:18] New task Operation: 4ebcf561-30f9-4eeb-8454-484e24f3df3a
INFO[05-09|12:34:18] Pruning leftover image files
DBUG[05-09|12:34:18] Started task operation: 4ebcf561-30f9-4eeb-8454-484e24f3df3a
INFO[05-09|12:34:18] Done pruning leftover image files
INFO[05-09|12:34:18] Loading daemon configuration
DBUG[05-09|12:34:18] Success for task operation: 4ebcf561-30f9-4eeb-8454-484e24f3df3a
DBUG[05-09|12:34:18] Initialized inotify with file descriptor 24
DBUG[05-09|12:34:18] New task Operation: 061b15f8-d257-4245-86b3-8b0044a62139
INFO[05-09|12:34:18] Pruning expired images
DBUG[05-09|12:34:18] Started task operation: 061b15f8-d257-4245-86b3-8b0044a62139
INFO[05-09|12:34:18] Done pruning expired images
DBUG[05-09|12:34:18] New task Operation: 0a5ff33b-2f88-4155-9f75-02e0210d1288
DBUG[05-09|12:34:18] Success for task operation: 061b15f8-d257-4245-86b3-8b0044a62139
INFO[05-09|12:34:18] Pruning expired instance backups
DBUG[05-09|12:34:18] Started task operation: 0a5ff33b-2f88-4155-9f75-02e0210d1288
INFO[05-09|12:34:18] Done pruning expired instance backups
DBUG[05-09|12:34:18] Success for task operation: 0a5ff33b-2f88-4155-9f75-02e0210d1288
DBUG[05-09|12:34:18] New task Operation: f7a132d4-d601-4f97-a2bd-12df2a8ea98d
DBUG[05-09|12:34:18] New task Operation: 20eb18a9-6320-464e-b6f6-63f0e9aeaa47
DBUG[05-09|12:34:18] New task Operation: da620b4d-a301-4a9c-aad6-d82d80ce687d
INFO[05-09|12:34:18] Updating instance types
DBUG[05-09|12:34:18] Started task operation: 20eb18a9-6320-464e-b6f6-63f0e9aeaa47
INFO[05-09|12:34:18] Updating images
DBUG[05-09|12:34:18] Started task operation: da620b4d-a301-4a9c-aad6-d82d80ce687d
INFO[05-09|12:34:18] Expiring log files
DBUG[05-09|12:34:18] Started task operation: f7a132d4-d601-4f97-a2bd-12df2a8ea98d
INFO[05-09|12:34:18] Done updating images
INFO[05-09|12:34:18] Done updating instance types
INFO[05-09|12:34:18] Done expiring log files
DBUG[05-09|12:34:18] Success for task operation: f7a132d4-d601-4f97-a2bd-12df2a8ea98d
DBUG[05-09|12:34:18] Success for task operation: da620b4d-a301-4a9c-aad6-d82d80ce687d
DBUG[05-09|12:34:30] Success for task operation: 20eb18a9-6320-464e-b6f6-63f0e9aeaa47
DBUG[05-09|12:37:37] Handling method=GET url=/1.0 ip=@ user=
DBUG[05-09|12:37:37] Handling url="/1.0/instances?recursion=2" ip=@ user= method=GET
DBUG[05-09|12:37:37] GetInstanceUsage started driver=zfs pool=default project=default instance=ubt-1
DBUG[05-09|12:37:37] GetInstanceUsage finished driver=zfs pool=default project=default instance=ubt-1

My /var/snap directory is

(base) admin1@admin1-S2600CO:/var/snap $ tree

.
├── core18
│   ├── 1754
│   ├── common
│   └── current -> 1754
├── lxd
│   ├── 14954
│   ├── common
│   │   ├── config
│   │   ├── lxc
│   │   │   └── local.conf
│   │   ├── lxcfs.pid
│   │   ├── lxd [error opening dir]
│   │   ├── lxd.pid
│   │   ├── mntns -> /proc/3710/root
│   │   ├── ns [error opening dir]
│   │   ├── shmounts [error opening dir]
│   │   ├── state
│   │   └── var
│   │       └── lib
│   │           └── lxcfs -> /var/snap/lxd/common/shmounts/lxcfs
│   └── current -> 14954
└── snapd
        ├── 7264
        ├── common
        └── current -> 7264

18 directories, 7 files

So what’s the problem with “shared mounts” ?

That is very good.

Have you reverted everything back?
As you can see this problem could be related to your first problem:

mv: access '/var/snap/lxd/common/ns/shmounts' error: invalid argument

Can you post the output of:
ls -aRl /var/snap/lxd/

Can you describe in detail what you did?
Both now and before.

Especially (regarding before)

  • Did you stop LXD?
  • How did you set the link exactly?

Regarding now:

  • Did you follow the steps from above?

The result of command sudo ls -aRl /var/snap/lxd is not friendly!

 (base) admin1@admin1-S2600CO:/media/admin1/work/tangmaomao $ sudo ls -aRl /var/snap/lxd/
[sudo] admin1 password: 
/var/snap/lxd/:
total 16
drwxr-xr-x 4 root root 4096 5月   9 10:45 .
drwxr-xr-x 5 root root 4096 5月   9 11:14 ..
drwxr-xr-x 2 root root 4096 5月   9 10:33 14954
drwxr-xr-x 7 root root 4096 5月   9 18:54 common
lrwxrwxrwx 1 root root    5 5月   9 10:32 current -> 14954

/var/snap/lxd/14954:
total 8
drwxr-xr-x 2 root root 4096 5月   9 10:33 .
drwxr-xr-x 4 root root 4096 5月   9 10:45 ..

/var/snap/lxd/common:
total 36
drwxr-xr-x  7 root root 4096 5月   9 18:54 .
drwxr-xr-x  4 root root 4096 5月   9 10:45 ..
-rw-r--r--  1 root root  225 5月   9 10:32 config
drwxr-xr-x  2 root root 4096 5月   9 10:33 lxc
-rw-------  1 root root    5 5月   9 18:54 lxcfs.pid
drwx--x--x 17 root root 4096 5月   9 18:54 lxd
-rw-r--r--  1 root root    5 5月   9 18:55 lxd.pid
lrwxrwxrwx  1 root root   15 5月   9 18:54 mntns -> /proc/4713/root
drwx------  2 root root   80 5月   9 18:54 ns
drwx--x--x  2 root root 4096 5月   9 10:33 shmounts
-rw-r--r--  1 root root    0 5月   9 18:54 state
drwxr-xr-x  3 root root 4096 5月   9 10:33 var

/var/snap/lxd/common/lxc:
total 8
drwxr-xr-x 2 root root 4096 5月   9 10:33 .
drwxr-xr-x 7 root root 4096 5月   9 18:54 ..
-rw-r--r-- 1 root root    0 5月   9 18:54 local.conf

/var/snap/lxd/common/lxd:
total 76
drwx--x--x 17 root root 4096 5月   9 18:54 .
drwxr-xr-x  7 root root 4096 5月   9 18:54 ..
drwx------  2 root root 4096 5月   9 10:32 backups
drwx------  2 root root 4096 5月   9 10:32 cache
drwx--x--x  2 root root 4096 5月   9 10:32 containers
drwx------  3 root root 4096 5月   9 10:32 database
drwx--x--x  3 root root 4096 5月   9 18:55 devices
drwxr-xr-x  2 root root 4096 5月   9 10:32 devlxd
drwx------  2 root root 4096 5月   9 10:32 disks
drwx------  2 root root 4096 5月   9 10:33 images
drwx------  3 root root 4096 5月   9 18:54 logs
drwx--x--x  3 root root 4096 5月   9 10:33 networks
drwx------  4 root root 4096 5月   9 10:33 security
-rw-r--r--  1 root root  790 5月   9 10:32 server.crt
-rw-------  1 root root  288 5月   9 10:32 server.key
lrwxrwxrwx  1 root root   40 5月   9 10:32 shmounts -> /var/snap/lxd/common/shmounts/containers
drwx------  2 root root 4096 5月   9 10:33 snapshots
drwx--x--x  3 root root 4096 5月   9 10:32 storage-pools
srw-rw----  1 root lxd     0 5月   9 18:54 unix.socket
drwx--x--x  2 root root 4096 5月   9 10:32 virtual-machines
drwx------  2 root root 4096 5月   9 10:33 virtual-machines-snapshots

/var/snap/lxd/common/lxd/backups:
total 8
drwx------  2 root root 4096 5月   9 10:32 .
drwx--x--x 17 root root 4096 5月   9 18:54 ..

/var/snap/lxd/common/lxd/cache:
total 16
drwx------  2 root root 4096 5月   9 10:32 .
drwx--x--x 17 root root 4096 5月   9 18:54 ..
-rw-------  1 root root 6179 5月   9 12:34 instance_types.yaml

/var/snap/lxd/common/lxd/containers:
total 12
drwx--x--x  2 root root 4096 5月   9 10:32 .
drwx--x--x 17 root root 4096 5月   9 18:54 ..
lrwxrwxrwx  1 root root   63 5月   9 10:32 ubt-1 -> /var/snap/lxd/common/lxd/storage-pools/default/containers/ubt-1

/var/snap/lxd/common/lxd/database:
total 52
drwx------  3 root root  4096 5月   9 10:32 .
drwx--x--x 17 root root  4096 5月   9 18:54 ..
drwxr-x---  2 root root  4096 5月   9 18:55 global
-rw-r--r--  1 root root 40960 5月   9 10:32 local.db

/var/snap/lxd/common/lxd/database/global:
total 30832
drwxr-x--- 2 root root    4096 5月   9 18:55 .
drwx------ 3 root root    4096 5月   9 10:32 ..
-rw------- 1 root root      64 5月   9 10:32 0000000000000001-0000000000000001
-rw------- 1 root root  653960 5月   9 10:32 0000000000000002-0000000000000021
-rw------- 1 root root 1532424 5月   9 11:35 0000000000000022-0000000000000158
-rw------- 1 root root  115752 5月   9 11:35 0000000000000159-0000000000000170
-rw------- 1 root root  124032 5月   9 11:44 0000000000000171-0000000000000183
-rw------- 1 root root  124032 5月   9 11:52 0000000000000184-0000000000000196
-rw------- 1 root root   82632 5月   9 11:59 0000000000000197-0000000000000204
-rw------- 1 root root   82632 5月   9 12:14 0000000000000205-0000000000000212
-rw------- 1 root root   82632 5月   9 12:14 0000000000000213-0000000000000220
-rw------- 1 root root  124032 5月   9 12:23 0000000000000221-0000000000000233
-rw------- 1 root root  132312 5月   9 12:32 0000000000000234-0000000000000247
-rw------- 1 root root  124032 5月   9 13:31 0000000000000248-0000000000000260
-rw------- 1 root root    4096 5月   9 13:31 db.bin
-rw------- 1 root root 3172432 5月   9 13:31 db.bin-wal
-rw------- 1 root root      32 5月   9 10:32 metadata1
-rw------- 1 root root 8388608 5月   9 19:55 open-1
-rw------- 1 root root 8388608 5月   9 18:55 open-2
-rw------- 1 root root 8388608 5月   9 18:55 open-3

/var/snap/lxd/common/lxd/devices:
total 12
drwx--x--x  3 root root 4096 5月   9 18:55 .
drwx--x--x 17 root root 4096 5月   9 18:54 ..
drwx--x--x  2 root root 4096 5月   9 10:32 ubt-1

/var/snap/lxd/common/lxd/devices/ubt-1:
total 8
drwx--x--x 2 root root 4096 5月   9 10:32 .
drwx--x--x 3 root root 4096 5月   9 18:55 ..

/var/snap/lxd/common/lxd/devlxd:
total 8
drwxr-xr-x  2 root root 4096 5月   9 10:32 .
drwx--x--x 17 root root 4096 5月   9 18:54 ..

/var/snap/lxd/common/lxd/disks:
total 4401812
drwx------  2 root root        4096 5月   9 10:32 .
drwx--x--x 17 root root        4096 5月   9 18:54 ..
-rw-------  1 root root 39000000000 5月   9 18:54 default.img

/var/snap/lxd/common/lxd/images:
total 1205780
drwx------  2 root root       4096 5月   9 10:33 .
drwx--x--x 17 root root       4096 5月   9 18:54 ..
-rw-------  1 root root 1068603176 5月   9 10:33 27e8f4351b8c9001c8115b07389f084c02730b2b0a4746af5a606a91627c0d16
-rw-------  1 root root  166099893 5月   9 10:33 872233202ebb2d16a7a0e33ec5e08183e990c5007c156b5932acd656f8875861

/var/snap/lxd/common/lxd/logs:
total 32
drwx------  3 root root  4096 5月   9 18:54 .
drwx--x--x 17 root root  4096 5月   9 18:54 ..
-rw-r--r--  1 root root  3414 5月   9 19:55 lxd.log
-rw-r--r--  1 root root 11917 5月   9 18:54 lxd.log.1
-rw-r--r--  1 root root   908 5月   9 10:32 lxd.log.2.gz
drwxr-xr-x  2 root root  4096 5月   9 10:32 ubt-1

/var/snap/lxd/common/lxd/logs/ubt-1:
total 36
drwxr-xr-x 2 root root  4096 5月   9 10:32 .
drwx------ 3 root root  4096 5月   9 18:54 ..
-rw------- 1 root root 13530 5月   9 10:32 console.log
-rw-r--r-- 1 root root     0 5月   9 10:32 forkstart.log
-rw-r----- 1 root root  2030 5月   9 10:32 lxc.conf
-rw-r----- 1 root root  2290 5月   9 13:31 lxc.log
-rw-r----- 1 root root   951 5月   9 10:32 lxc.log.old

/var/snap/lxd/common/lxd/networks:
total 12
drwx--x--x  3 root root 4096 5月   9 10:33 .
drwx--x--x 17 root root 4096 5月   9 18:54 ..
drwx--x--x  3 root root 4096 5月   9 10:33 lxdbr0

/var/snap/lxd/common/lxd/networks/lxdbr0:
total 24
drwx--x--x 3 root root 4096 5月   9 10:33 .
drwx--x--x 3 root root 4096 5月   9 10:33 ..
drwxr-xr-x 2 root root 4096 5月   9 18:55 dnsmasq.hosts
-rw-r--r-- 1 root root 1324 5月   9 20:30 dnsmasq.leases
-rw-r--r-- 1 root root  695 5月   9 18:55 dnsmasq.pid
-rw-r--r-- 1 root root    1 5月   9 18:55 dnsmasq.raw

/var/snap/lxd/common/lxd/networks/lxdbr0/dnsmasq.hosts:
total 12
drwxr-xr-x 2 root root 4096 5月   9 18:55 .
drwx--x--x 3 root root 4096 5月   9 10:33 ..
-rw-r--r-- 1 root root   24 5月   9 18:55 ubt-1

/var/snap/lxd/common/lxd/security:
total 16
drwx------  4 root root 4096 5月   9 10:33 .
drwx--x--x 17 root root 4096 5月   9 18:54 ..
drwx------  4 root root 4096 5月   9 10:33 apparmor
drwx------  2 root root 4096 5月   9 10:33 seccomp

/var/snap/lxd/common/lxd/security/apparmor:
total 16
drwx------ 4 root root 4096 5月   9 10:33 .
drwx------ 4 root root 4096 5月   9 10:33 ..
drwx------ 2 root root 4096 5月   9 10:33 cache
drwx------ 2 root root 4096 5月   9 10:33 profiles

/var/snap/lxd/common/lxd/security/apparmor/cache:
total 56
drwx------ 2 root root  4096 5月   9 10:33 .
drwx------ 4 root root  4096 5月   9 10:33 ..
-rw-r--r-- 1 root root  1391 5月   9 10:33 .features
-rw------- 1 root root 42081 5月   9 10:33 lxd-ubt-1

/var/snap/lxd/common/lxd/security/apparmor/profiles:
total 32
drwx------ 2 root root  4096 5月   9 10:33 .
drwx------ 4 root root  4096 5月   9 10:33 ..
-rw------- 1 root root 22714 5月   9 10:33 lxd-ubt-1

/var/snap/lxd/common/lxd/security/seccomp:
total 12
drwx------ 2 root root 4096 5月   9 10:33 .
drwx------ 4 root root 4096 5月   9 10:33 ..
-rw------- 1 root root  204 5月   9 10:33 ubt-1

/var/snap/lxd/common/lxd/snapshots:
total 8
drwx------  2 root root 4096 5月   9 10:33 .
drwx--x--x 17 root root 4096 5月   9 18:54 ..

/var/snap/lxd/common/lxd/storage-pools:
total 12
drwx--x--x  3 root root 4096 5月   9 10:32 .
drwx--x--x 17 root root 4096 5月   9 18:54 ..
drwx--x--x  9 root root 4096 5月   9 10:32 default

/var/snap/lxd/common/lxd/storage-pools/default:
total 36
drwx--x--x 9 root root 4096 5月   9 10:32 .
drwx--x--x 3 root root 4096 5月   9 10:32 ..
drwx--x--x 3 root root 4096 5月   9 10:32 containers
drwx--x--x 2 root root 4096 5月   9 10:32 containers-snapshots
drwx--x--x 2 root root 4096 5月   9 10:32 custom
drwx--x--x 2 root root 4096 5月   9 10:32 custom-snapshots
drwx--x--x 3 root root 4096 5月   9 10:32 images
drwx--x--x 2 root root 4096 5月   9 10:32 virtual-machines
drwx--x--x 2 root root 4096 5月   9 10:32 virtual-machines-snapshots

/var/snap/lxd/common/lxd/storage-pools/default/containers:
total 12
drwx--x--x 3 root root 4096 5月   9 10:32 .
drwx--x--x 9 root root 4096 5月   9 10:32 ..
d--x------ 2 root root 4096 5月   9 10:32 ubt-1

/var/snap/lxd/common/lxd/storage-pools/default/containers/ubt-1:
total 8
d--x------ 2 root root 4096 5月   9 10:32 .
drwx--x--x 3 root root 4096 5月   9 10:32 ..

/var/snap/lxd/common/lxd/storage-pools/default/containers-snapshots:
total 8
drwx--x--x 2 root root 4096 5月   9 10:32 .
drwx--x--x 9 root root 4096 5月   9 10:32 ..

/var/snap/lxd/common/lxd/storage-pools/default/custom:
total 8
drwx--x--x 2 root root 4096 5月   9 10:32 .
drwx--x--x 9 root root 4096 5月   9 10:32 ..

/var/snap/lxd/common/lxd/storage-pools/default/custom-snapshots:
total 8
drwx--x--x 2 root root 4096 5月   9 10:32 .
drwx--x--x 9 root root 4096 5月   9 10:32 ..

/var/snap/lxd/common/lxd/storage-pools/default/images:
total 12
drwx--x--x 3 root root 4096 5月   9 10:32 .
drwx--x--x 9 root root 4096 5月   9 10:32 ..
drwx--x--x 2 root root 4096 5月   9 10:32 872233202ebb2d16a7a0e33ec5e08183e990c5007c156b5932acd656f8875861

/var/snap/lxd/common/lxd/storage-pools/default/images/872233202ebb2d16a7a0e33ec5e08183e990c5007c156b5932acd656f8875861:
total 8
drwx--x--x 2 root root 4096 5月   9 10:32 .
drwx--x--x 3 root root 4096 5月   9 10:32 ..

/var/snap/lxd/common/lxd/storage-pools/default/virtual-machines:
total 8
drwx--x--x 2 root root 4096 5月   9 10:32 .
drwx--x--x 9 root root 4096 5月   9 10:32 ..

/var/snap/lxd/common/lxd/storage-pools/default/virtual-machines-snapshots:
total 8
drwx--x--x 2 root root 4096 5月   9 10:32 .
drwx--x--x 9 root root 4096 5月   9 10:32 ..

/var/snap/lxd/common/lxd/virtual-machines:
total 8
drwx--x--x  2 root root 4096 5月   9 10:32 .
drwx--x--x 17 root root 4096 5月   9 18:54 ..

/var/snap/lxd/common/lxd/virtual-machines-snapshots:
total 8
drwx------  2 root root 4096 5月   9 10:33 .
drwx--x--x 17 root root 4096 5月   9 18:54 ..

/var/snap/lxd/common/ns:
total 4
drwx------ 2 root root   80 5月   9 18:54 .
drwxr-xr-x 7 root root 4096 5月   9 18:54 ..
-r--r--r-- 1 root root    0 5月   9 18:54 mntns
-r--r--r-- 1 root root    0 5月   9 18:54 shmounts

/var/snap/lxd/common/shmounts:
total 8
drwx--x--x 2 root root 4096 5月   9 10:33 .
drwxr-xr-x 7 root root 4096 5月   9 18:54 ..

/var/snap/lxd/common/var:
total 12
drwxr-xr-x 3 root root 4096 5月   9 10:33 .
drwxr-xr-x 7 root root 4096 5月   9 18:54 ..
drwxr-xr-x 2 root root 4096 5月   9 10:33 lib

/var/snap/lxd/common/var/lib:
total 8
drwxr-xr-x 2 root root 4096 5月   9 10:33 .
drwxr-xr-x 3 root root 4096 5月   9 10:33 ..
lrwxrwxrwx 1 root root   35 5月   9 10:33 lxcfs -> /var/snap/lxd/common/shmounts/lxcfs

I think I did not stop lxd or lxd daemon before I move the /var/snap/lxd to other place.

Here is my command history:

1508  lxc  
 1509  lxc list 
 1510  ls /var 
 1511  ls /var/snap
 1512  ls /var/snap/lxd/
 1513  ll /var/snap/lxd/
 1514  tree -L 3 /var/snap/lxd/
 1515  sudo mv /var/snap/lxd /media/admin1/work/tangmaomao/project/linux_container/lxc_storage_source
 1516  cd /var/snap/lxd

But after reboot the whole operation system, I can run sudo lxd init !

(base) admin1@admin1-S2600CO:/var/snap $ sudo lxd init
Would you like to use LXD clustering? (yes/no) [default=no]: ^C

I think the “mount” was the main problem,
which is
WARN[05-09|12:34:18] Failed settting up shared mounts: no such file or directory

After rebooting, maybe the kernel or something can “mount” successfully.

Well:
lxd init
should not be necessary, because that will create a new setup.

Does lxc list work again?

I find another thing. When I type in lxd shutdown, I lost the connection to my server.

(base) admin1@admin1-S2600CO:/var/snap $ lxd shutdown

Socket error Event: 32 Error: 10053.
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(16S数据分析-生产-30) at 20:57:53.

I think maybe it’s due to the lxdbr0 bridge. Because I set up a bridge when issued sudo lxd init maybe 2 days ago. And the only IP address of the server is attached on the lxdbr0 bridge. So when I shutdown lxd , maybe also shutdown the lxdbr0 bridge.

5min later, I go to touch that real physical server. Issue ip a command. Right! There is no lxdbr0 section or its IP information.

I don’t immediately issue sudo lxd to recover lxd process, instead I run ps aux. I find there is still one process or command relevant with “lxd” running. It is
lxcfs /var/snap/lxd/common/var/lib/lxcfs -p /var/snap/lxd/common/lxcfs.pid

10min later I issue sudo lxd activateifneeded
then ip a
I can see the lxdbr0 section and the original IP address, and I can SSH connect to the server from another terminal too.

Running lxc list is fine.

(base) admin1@admin1-S2600CO:/media/admin1/work/tangmaomao/project/lxd/lxc_storage_source $ lxc list
    +-------+---------+------+------+-----------+-----------+
    | NAME  |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |
    +-------+---------+------+------+-----------+-----------+
    | ubt-1 | STOPPED |      |      | CONTAINER | 0         |
    +-------+---------+------+------+-----------+-----------+

Well then everything is working again?

And what is your setup right now?:
Is all LXD-Data in the original folder ( /var/snap/lxd/) again?
Or are you still using the link?

Is the container starting normal?

For the consideration about safety , I choose to set the storage pool as “dir” type and then set the storage path to be a directory in my old hard drive patition. This is mainly referencing stgraber’s advice.

:/media/admin1/work/tangmaomao/project/lxd/lxc_storage_source $ lxc delete ubt-1

:/media/admin1/work/tangmaomao/project/lxd/lxc_storage_source $ lxc profile device remove default root

Device root removed from default

:/media/admin1/work/tangmaomao/project/lxd/lxc_storage_source $ lxc storage delete default

Storage pool default deleted

:/media/admin1/work/tangmaomao/project/lxd/lxc_storage_source $ lxc storage create default dir source=/media/admin1/work/tangmaomao/project/lxd/lxc_storage_source

Storage pool default created

:/media/admin1/work/tangmaomao/project/lxd/lxc_storage_source $ lxc profile device add default root disk path=/ pool=default

Device root added to default

:/media/admin1/work/tangmaomao/project/lxd/lxc_storage_source $ ll

total 36

drwxrwxr-x 9 admin1 admin1 4096 5月   9 21:46 ./

drwxrwxr-x 4 admin1 admin1 4096 5月   9 20:46 ../

drwx--x--x 2 root   root   4096 5月   9 21:46 containers/

drwx--x--x 2 root   root   4096 5月   9 21:46 containers-snapshots/

drwx--x--x 2 root   root   4096 5月   9 21:46 custom/

drwx--x--x 2 root   root   4096 5月   9 21:46 custom-snapshots/

drwx--x--x 2 root   root   4096 5月   9 21:46 images/

drwx--x--x 2 root   root   4096 5月   9 21:46 virtual-machines/

drwx--x--x 2 root   root   4096 5月   9 21:46 virtual-machines-snapshots/


:/media/admin1/work/tangmaomao/project/lxd/lxc_storage_source $ lxc image list

+---------------------+--------------+--------+--------------------------------------+--------------+-----------+-----------+------------------------------+

|        ALIAS        | FINGERPRINT  | PUBLIC |             DESCRIPTION              | ARCHITECTURE |   TYPE    |   SIZE    |         UPLOAD DATE          |

+---------------------+--------------+--------+--------------------------------------+--------------+-----------+-----------+------------------------------+

| ubuntu18-t-20200508 | 27e8f4351b8c | no     |                                      | x86_64       | CONTAINER | 1019.10MB | May 8, 2020 at 2:43am (UTC)  |

+---------------------+--------------+--------+--------------------------------------+--------------+-----------+-----------+------------------------------+

| ubuntu-18-tang      | 872233202ebb | no     | Ubuntu bionic amd64 (20200506_07:42) | x86_64       | CONTAINER | 158.41MB  | May 7, 2020 at 12:58pm (UTC) |

+---------------------+--------------+--------+--------------------------------------+--------------+-----------+-----------+------------------------------+


:/media/admin1/work/tangmaomao/project/lxd/lxd_images $ lxc launch ubuntu18-t-20200508 ubt-1

Creating ubt-1

Starting ubt-1  

## Maybe cost 10 seconds for this 1GB image to create a container instance


:/media/admin1/work/tangmaomao/project/lxd/lxd_images $ lxc list

+-------+---------+----------------------+-----------------------------------------------+-----------+-----------+

| NAME  |  STATE  |         IPV4         |                     IPV6                      |   TYPE    | SNAPSHOTS |

+-------+---------+----------------------+-----------------------------------------------+-----------+-----------+

| ubt-1 | RUNNING | 192.168.0.131 (eth0) | fd42:fd4c:da8f:ea0f:216:3eff:feb6:aa24 (eth0) | CONTAINER | 0         |

+-------+---------+----------------------+-----------------------------------------------+-----------+-----------+

Because my old image ubuntu18-t-20200508 was from a container which I installed ssh in. When I launch (create and run in the background) a new container from that image, I do not need to run command lxc exec ubt-1(container) – /bin/bash to go inside the container.
Very conviniently, I can just SSH connet to that container! Yeah, I treat it as a virtual machine – what I want primarily. But it is really a container whcih is fast and tiny and less harmful to the physical host machine.

Thank you! Warm heart.

Thank you! Stgraber

You can specify an existing zfs dataset in lxd init, without a dedicated partition… I typically create a single zpool with the biggest partition of the disk, then create an “lxd” zfs dataset in that zpool and use it as the LXD default storage. I also have other zfs datasets in the same zpool, so they share the same partition with LXD.

Interesting :thinking:.

So one can create a zpool on a second harddrive and use that inside lxd, which is installed on the first harddrive?

But why Big Brother Stgraber doesn’t recommend this practice? He recommends that set the pool type as dir instead of zfs inside an already existing directory.

Well, I guess @stgraber might give us an answer next week (don’t know in which timezone you are though :smile: ).

In the meantime; the explaination could be that there might be a difference between:

  1. creating a zfs pool with lxd
  2. creating a zfs pool by hand and creating a zfs dataset for lxd inside it

So option 2 seems possible according to @votsalo.
While option 1 is maybe not.

But if option 1 is possible (I doubt it):
The reason stgraber recommended a dir-pool might also be related to your question about using the maximum ressources of the system.
With “dir” all available space is used.

Anyway, I guess in a few days we know more :slightly_smiling_face:.

Edit:
Hmm maybe this is against the rules,
FAQ states:
Don’t divert a topic by changing it midstream.

I guess if stgraber or someone else doesn’t answer, we might have to ask the question in a seperate new topic…
though that would also be against the rules:
Don’t cross-post the same thing in multiple topics.
:sweat_smile:

@stgraber
For convenience a short summary, so you don’t need to read the whole discussion:

  1. Is it possible to create a storage pool (with some other backend than “dir”) on a second harddrive?
    a) with LXD
    or
    b) manually (e.g. like @votsalo’s post suggests)

  2. Can one change the path of the LXD-folder?
    And if yes, how to do that?

a) I found this variable:
LXD_DIR - The LXD data directory
How do you set it?
via snap?:
sudo snap set lxd LXD_DIR=/media/example/lxd

b) Can the path be set to a folder in a second harddrive?

I understand that the OP does not have a free partition to allocate to zfs. That’s why the recommendation was to use a “dir” backend within the existing filesystem. My earlier comment was to point out that you don’t need a dedicated partition for LXD. LXD will be happy to use the filesystem that you already have. If you have a zfs filesystem, you can allocate a new clean zfs dataset to LXD. If you have an ext3, ext4, or other filesystem, I have the impression that you can allocate a new empty directory to LXD.

Thanks for the clarification.

But only with “dir” backend right?
You know the thing I wonder about is, why can LXD create new storage pools with all backends on the harddrive that LXD is installed on, but it seems it can only create a “dir” backend storage pool on additional harddrives.

Now one could say “just test it”, but I can’t because I have a different setup here, so I would need to create a different partition etc. which I don’t want right now.

Yes, of course. You need a zfs filesystem for a zfs backend, a btrfs filesystem for the btrfs backend, and so on. Dir is the most general backend that can be used with all filesystems.

In my system(s), LXD (via snap) is installed in the ext4 OS partition. My LXD storage is on a ZFS dataset on other partition(s).