意外重启后LXD容器处于ERROR状态无法启动/删除的恢复求助
Hey there, let's work through this issue where your LXD containers got stuck in ERROR state after an unexpected system reset. The core problem here is that LXD can't access its underlying ZFS pool, so we'll focus on fixing that first to get your containers back up.
Step 1: Check and import the ZFS pool
First, let's confirm the current state of your ZFS pools:
zpool list
If the lxd pool doesn't show up in the output, list all pools that are available for import:
zpool import
If you see the lxd pool listed here, try importing it directly:
zpool import lxd
If you get an error about the pool being busy or already mounted, unmount the LXD storage directory first (if it's mounted):
umount /var/lib/lxd
Then retry the import command.
Step 2: Locate and import the pool from raw storage device
If zpool import doesn't detect the lxd pool, we need to check your disk partitions for ZFS metadata. Run this command against your storage partition (replace /dev/sdXn with your actual device path, e.g., /dev/sda2):
zdb -l /dev/sdXn
If this command returns metadata for the lxd pool, import it by specifying the device path:
zpool import -d /dev/sdXn lxd
Step 3: Restore LXD container state after pool import
Once the ZFS pool is successfully imported, restart the LXD service to refresh its connection to the pool:
service lxd restart # Ubuntu 16.04 uses this legacy command; systemctl restart lxd works too
Now try starting one of your containers to test:
lxc start cups-lxc
If the container still fails to start, check its logs for specific error details:
lxc info cups-lxc --show-log
Common issues here might be corrupted container configs or minor ZFS dataset inconsistencies. If logs point to config problems, you can try restoring from a backup (if you have one) or manually editing the config file located at /var/lib/lxd/containers/cups-lxc/config.
Step 4: Recover data if the pool is corrupted
If the ZFS pool is irreparably damaged, you can still rescue your container data:
- List any existing ZFS snapshots for your containers:
zfs list -t snapshot - If you have a snapshot, roll back to it to restore the container's state:
zfs rollback lxd/containers/cups-lxc@<snapshot-name> - If no snapshots exist, mount the container's ZFS dataset to a temporary directory to extract data:
You can then create a new container and copy the recovered data into it.zfs mount lxd/containers/cups-lxc /tmp/cups-recover cp -r /tmp/cups-recover/* /path/to/your/backup/folder zfs unmount /tmp/cups-recover
内容的提问来源于stack exchange,提问作者nacho

