ZFS is a popular file system and volume manager that offers many features such as snapshots, compression, encryption, deduplication, and RAID-Z. However, sometimes ZFS pools can become corrupted or inaccessible due to various reasons, such as hardware failures, power outages, or software bugs. In this article, we will show you how to recover from a partial ZFS pool loss after upgrading to Ubuntu 22.04, using the zfs send and zfs receive commands.
Table of Contents
The Problem
Users reported that they had a long-running ZFS pool under Ubuntu, which had been through many upgrades. After upgrading from Ubuntu 20.04 to 22.04, the encrypted file systems in the pool refused to mount, though the rest seemed OK. The zpool status command reported a permanent error ZFS-8000-8A at the root of the encrypted file system. The user also noted that there was a big jump in the package version of zfsutils-linux from 0.8.3 to 2.1.5.
The user was able to import the pool to an Ubuntu 20.04 system, and mount the encrypted file system there. It looked OK. The user also tried to zfs send the pool from Ubuntu 20.04 and zfs receive it on Ubuntu 22.04, with apparent success. However, the user was not sure if this would create a pool free of upgrade problems, or if the compatibility issues would persist.
The Solution
The zfs send and zfs receive commands are useful tools for backing up and restoring ZFS pools and file systems. They create a stream representation of a snapshot that can be written to a file or piped to another system. The zfs receive command creates a snapshot or a file system whose contents are specified by the stream provided on standard input.
The advantage of using these commands is that they preserve all the ZFS properties and features, such as compression, encryption, deduplication, etc. They also allow for incremental backups and restores, by specifying the source and destination snapshots.
However, there are some caveats to be aware of when using these commands:
- The zfs send and zfs receive commands require that both systems have the same or compatible versions of ZFS. If the source system has a newer version of ZFS than the destination system, some features may not be supported or may cause errors.
- The zfs send and zfs receive commands do not check for errors or corruption in the source pool or file system. If the source pool or file system is damaged, the destination pool or file system may also be damaged.
- The zfs send and zfs receive commands do not preserve the pool layout or configuration. They only operate on individual file systems or snapshots within a pool. If the source pool has multiple vdevs or RAID-Z levels, they will not be replicated on the destination pool.
Therefore, in order to recover from a partial ZFS pool loss after upgrading to Ubuntu 22.04, we recommend the following steps:
Step 1: Make sure you have a backup of your data on another device or location.
Step 2: Boot your system with Ubuntu 20.04 and import your ZFS pool.
Step 3: Create snapshots of your file systems with zfs snapshot -r pool@backup, where pool is the name of your pool.
Step 4: Boot your system with Ubuntu 22.04 and create a new ZFS pool with zpool create newpool …, where … are the options and devices you want to use for your new pool.
Step 5: Receive your file systems from Ubuntu 20.04 with zfs receive -F newpool/fs < stream, where newpool/fs is the name of your new file system and stream is the output of zfs send pool/fs@backup from Ubuntu 20.04.
Step 6: Repeat step 5 for each file system you want to restore.
Step 7: Destroy your old pool with zpool destroy pool.
Step 8: Rename your new pool with zpool export newpool and zpool import newpool pool.
FAQ
Here are some frequently asked questions related to this topic:
Question: How can I check if my ZFS pool or file system is corrupted?
Answer: You can use the zpool scrub command to scan your pool for errors and repair them if possible. You can also use the zpool status -v command to see if there are any errors or checksum failures reported.
Question: How can I encrypt my ZFS file system?
Answer: You can use the -o encryption=on option when creating a new file system with zfs create. You will also need to specify a passphrase or a key file with -o keylocation=prompt or -o keylocation=file://path. You can also enable encryption on an existing file system with zfs set encryption=on fs, but you will need to re-write all the data to encrypt it.
Question: How can I compress my ZFS file system?
Answer: You can use the -o compression=on option when creating a new file system with zfs create. You can also enable compression on an existing file system with zfs set compression=on fs. You can choose different compression algorithms with -o compression=algo, where algo can be lz4, gzip, zstd, etc.
Disclaimer
This article is for informational purposes only and does not constitute professional advice. We are not responsible for any data loss or damage that may result from following the instructions in this article. Always backup your data before performing any operations on your ZFS pool or file system.