Noob question: How to create additional storage? (loop file based, dir, etc.)

This will be maybe the easiest question for anyone to answer but I am 100% stuck.

How do you create a new storage - that is NOT block based?
So basically, how do you create new storages? What are the options?

I love LXD, and I would love to learn more about it, but it is so hard to find more information about various bits… storage is one of these bits.

  • Read the doc. I did. That was about the second thing I did. First I tried to just use the command and find out myself. The doc is great on explaining small bits about how you grow an existing file based ZFS for example and that sort of thing.
  • Use the ‘lxc storage’ command and find out. I tried, but it just tells me I either use a block device or I’m not getting any storage.
  • It would be great if I could learn proper storage management. Like how do I change which storage is default, how do I move them around, that sort of thing.

Ps.: LXD is great, it’s a wonderful tech, please, keep up the great work!

To create a loop file based storage, just don’t specify a source, this works for btrfs, zfs and lvm:

  • lxc storage create NAME zfs
  • lxc storage create NAME btrfs
  • lxc storage create NAME lvm

If you just want to use an existing directory to store containers directly, you can do that with the dir backend, though this is our most limited backend feature and performance wise.

  • lxc storage create NAME dir source=/some/empty/directory

Dear stgraber!

Thank you for replying so quickly.
My original question remains - which I do realize I should have worded differently - how do I create a new, let’s say lvm storage in an empty directory? I mean, how do I create a loop file?

During the init process, I can simply say “N” to block device, then say 100GB, and it will create a loop device, with LVM, ZFS, btrfs, whatever I ask for. And that works great. But I would like to create a loop based storage elsewhere (to a VPS Volume that is mounted under /mnt/whatever/…).

Thank you!

You can’t. LXD expects all the loop files it manages to be inside /var/snap/lxd/common/lxd/disks.

If you want them somewhere else, then it’s up to you to manually create a loop file somewhere else, create the filesystem or LVM on top of it, then tell LXD to use it.

So for ZFS you could do:

  • truncate -s 50G /srv/blah.img
  • zpool create mypool /srv/blah.img -m none
  • lxc storage create mypool zfs source=mypool

But then it’s on you to make sure that the mypool zpool is online by the time LXD starts up, so you may need some init scripts and the like to ensure everything works.

Similar instructions would go for LVM (manually create a VG). For something like btrfs, you’d then want to have it be mounted somewhere through /etc/fstab and then pass that as the source when creating the LXD pool.

1 Like

Hello @stgraber Thank you for this reply. I’ve been using straight LXC (without LXD) for years, and all of my containers use simple ext4 filesystem directories, like so:

/var/lib/lxc/vps00/rootfs/...
/var/lib/lxc/vps01/rootfs/...
/var/lib/lxc/vps02/rootfs/...
etc.

Going forward I’ll use LXD, but I don’t need to clone or snapshot my containers. I manually do that once in a blue blue moon with cp -rp, to keep things simple and transparent. (I also plan on using static IP addressing, which I’d manually update after such a clone, as well).

So besides cloning and snapshotting, are there other consideration for using btrfs or zfs? Athough I’m an old hat with LXC, I’m brand new to LXD (the snap version by the way).

Remember, simple, transparent and not over-engineered is always my preference. :laughing: Still, if there’s a good reason to adopt these backends, do tell.

Thank you @stgraber and anyone else who chimes in.

Take a look at the documentation:
https://linuxcontainers.org/lxd/docs/master/storage#feature-comparison

Otherwise you might find data, such as performance tests elsewhere on the internet as well.

1 Like

How to create the loop file with 50G size?
something like this: lxc storage create NAME btrfs 50G

lxc storage create NAME btrfs size=50GiB

See Storage pools | LXD

1 Like

It works, thanks

1 Like