LXD Init从已有ZFS池迁移数据路径及挂载点差异问题咨询
Hey there, let's tackle your two core questions about LXD and ZFS— I’ve spent plenty of time troubleshooting these exact kinds of mismatches, so I can walk you through what’s going on.
1. Where does lxd init migrate data from when using an existing ZFS pool?
When you run lxd init and choose to use an existing ZFS pool, LXD doesn’t randomly scan the entire pool. It specifically targets pre-existing LXD-managed ZFS datasets in that pool.
By default, LXD structures its ZFS storage under a top-level dataset named lxd within your pool (e.g., your_pool/lxd). Under that, it creates sub-datasets like containers, images, snapshots, and custom for different storage needs.
If your existing pool already has this your_pool/lxd hierarchy (from a previous LXD setup), lxd init will take over all data within those sub-datasets. Any non-LXD datasets you created manually for other purposes will be completely ignored— LXD won’t touch them at all.
To confirm what’s in your pool, run this command to list all datasets recursively:
zfs list -r your_pool_name
Look for entries starting with your_pool_name/lxd— those are the ones LXD will target during initialization.
2. Why do mount point mismatches between LXD and ZFS happen, and what are the impacts?
Mount point mismatches are common when you’ve customized ZFS settings or reused a pool not originally set up for LXD. Here’s the breakdown:
Common Causes
- Manual ZFS mount point edits: If you manually changed the
mountpointproperty of any LXD-managed datasets (e.g., withzfs set mountpoint=/some/other/path), LXD will still try to use its default or configured mount path (usually under/var/lib/lxd/storage-pools/your_pool/). - Custom storage paths during
lxd init: If you specified a non-default storage directory when runninglxd init, LXD will expect datasets to be mounted there, but ZFS might still have the old default mountpoint set. - Configuration drift after updates: Rarely, major LXD or ZFS updates can overwrite or reset mount point configurations, creating a mismatch between what ZFS has set and what LXD expects.
Potential Impacts
- Container startup failures: LXD won’t find the container’s filesystem if the ZFS dataset isn’t mounted at the path it’s looking for.
- Data persistence issues: Changes made in the container might not save to the ZFS dataset, or could be written to the wrong location entirely.
- Resource waste: You might end up with duplicate mounts (ZFS mounting the dataset at one path, LXD trying to use another), which eats up unnecessary system resources.
- Backup/migration headaches: When backing up or migrating containers, the path mismatch can cause tools to fail or pick up the wrong data.
Quick Fix Tip
First, check what mount point LXD expects for your pool:
lxc storage show your_pool_name
Look for the config.mount_point line— that’s the path LXD uses.
Then, set the ZFS dataset’s mount point to match that path (replace your_pool_name/lxd with your top-level LXD dataset):
zfs set mountpoint=/var/lib/lxd/storage-pools/your_pool_name your_pool_name/lxd
Unmount any existing mounts of that dataset first if it’s already mounted elsewhere.
内容的提问来源于stack exchange,提问作者code_dredd

