Is it possible to run lxd/lxc on a secondary, non operating system hdd?

Hello and congratulations for the forum!
I was wondering if it’s possible to run lxd on a secondary hdd, this which is not my OS.
I want this so to not mess up with my booting hdd which is lvm/Luks. The secondary I can have zfs on easyily.
Thnank you :slight_smile:

Sure is. If you run “lxd init”, you should be able to create a new storage pool using one HDD2 (/dev/sdb). This is what I did for my btrfs partition. (you must be running LXD 2.12 or later for this option).

If you want to run all of LXD to your second drive: boot into a rescue session, move /var/lib/lxd to /dev/sdb (or zfs partition), then create a symlink of /var/lib/lxd to your second drive.

-Ron

Well thanx a lot for your time. I will try later and see how it goes and if I need further assistance I will write. Thanx :slight_smile:

If you want to run all of LXD to your second drive: boot into a rescue session, move /var/lib/lxd to /dev/sdb (or zfs partition), then create a symlink of /var/lib/lxd to your second drive.

Please don’t use symlinks if you want to do that. This is inherently unsafe and might mess with your setup. Use bind-mounts instead:

mount --bind /dev/sdb /var/lib/lxd
1 Like

Can you explain why symlinks would be unsafe and/or mess up the setup?
I am also using a symlink although I point it to a ZFS dataset instead of a device.

Symlinks aren’t ideal for a couple of reasons. Some LSM modules like AppArmor will resolve symlinks before denying or allowing mounts and they might deny mounts based on that which will leave you with a non-functional LXD. In the same manner low-level liblxc will try to resolve symlinks and ensure that noone is tricking it into mounting stuff outside the rootfs of the container. Furthermore, when you update LXD you might see serious problems. Especially, when we try to apply on-disk changes on update.
It’s better to use a bind-mount because for LXD and most other programs they will be indistinguishable to a normal directory or file.

2 Likes

I was able to accomplish/test this I asked with
mount --bind /dev/sdb /var/lib/lxd

everything went so well…

1 Like