在 Ubuntu 19.10 上入门 ZFS 文件系统
ZFS
![](/data/attachment/album/201911/21/081609la0a7c7kpypppkt8.jpg)


Ubuntu 19.10 的主要新特性之一就是 [ZFS](/article-10034-1.html)。现在你可以很容易的无需额外努力就可以在 Ubuntu 系统上安装 ZFS了。


一般情况下，安装 Linux 都会选择 Ext4 文件系统。但是如果是全新安装 Ubuntu 19.10，在安装的启动阶段可以看到 ZFS 选项。


![你可以在安装 Ubuntu 19.10 的时候选择 ZFS](/data/attachment/album/201911/21/081613mzv9vj4a0v790ss0.jpg)


让我们看看 ZFS 为何重要，以及如何在已经安装了 ZFS 的 Ubuntu 上使用它。


### ZFS 与其他文件系统有哪些区别？


ZFS 的设计初衷是：处理海量存储和避免数据损坏。ZFS 可以处理 256 千万亿的 ZB 数据。（这就是 ZFS 的 Z）且它可以处理最大 16 EB 的文件。


如果你仅有一个单磁盘的笔记本电脑，你可以体验 ZFS 的数据保护特性。写时复制（COW）特性确保正在使用的数据不会被覆盖，相反，新的数据会被写到一个新的块中，同时文件系统的元数据会被更新到新块中。ZFS 可容易的创建文件系统的快照。这个快照可追踪文件系统的更改，并共享数据块确保节省数据空间。


ZFS 为磁盘上的每个文件分配一个校验和。它会不断的校验文件的状态和校验和。如果发现文件被损坏了，它就会尝试修复文件。


我写过一个文章详细介绍 [什么是 ZFS以及它有哪些特性](/article-10034-1.html)。如果你感兴趣可以去阅读下。


注：请谨记 ZFS 的数据保护特性会导致性能下降。


### Ubuntu 下使用 ZFS [适用于中高级用户]


一旦你在你的主磁盘上全新安装了带有 ZFS 的 Ubuntu，你就可以开始体验它的特性。


请注意所有的 ZFS 设置过程都需要命令行。我不知道它有任何 GUI 工具。


#### 创建一个 ZFS 池


**这段仅针对拥有多个磁盘的系统。如果你只有一个磁盘，Ubuntu 会在安装的时候自动创建池。**


在创建池之前，你需要为池找到磁盘的 id。你可以用命令 `lsblk` 查询出这个信息。


为三个磁盘创建一个基础池，用以下命令：



```
sudo zpool create pool-test /dev/sdb /dev/sdc /dev/sdd
```

请记得替换 `pool-test` 为你选择的的命名。


这个命令将会设置“无冗余 RAID-0 池”。这意味着如果一个磁盘被破坏或有故障，你将会丢失数据。如果你执行以上命令，还是建议做一个常规备份。


你可以用下面命令将另一个磁盘增加到池中：



```
sudo zpool add pool-name /dev/sdx
```

#### 查看 ZFS 池的状态


你可以用这个命令查询新建池的状态：



```
sudo zpool status pool-test
```

![Zpool 状态](/data/attachment/album/201911/21/081614bkaa04jjkjgsjxyj.png)


#### 镜像一个 ZFS 池


为确保数据的安全性，你可以创建镜像。镜像意味着每个磁盘包含同样的数据。使用镜像设置，你可能会丢失三个磁盘中的两个，并且仍然拥有所有信息。


要创建镜像你可以用下面命令：



```
sudo zpool create pool-test mirror /dev/sdb /dev/sdc /dev/sdd
```

#### 创建 ZFS 用于备份恢复的快照


快照允许你创建一个后备，以防某个文件被删除或被覆盖。比如，我们创建一个快照，当在用户主目录下删除一些目录后，然后把它恢复。


首先，你需要找到你想要的快照数据集。你可以这样做：



```
zfs list
```

![Zfs List](/data/attachment/album/201911/21/081616d4qfpf5l50fwal0a.png)


你可以看到我的家目录位于 `rpool/USERDATA/johnblood_uwcjk7`。


我们用下面命令创建一个名叫 `1910` 的快照：



```
sudo zfs snapshot rpool/USERDATA/johnblood_uwcjk7@1019
```

快照很快创建完成。现在你可以删除 `Downloads` 和 `Documents` 目录。


现在你用以下命令恢复快照：



```
sudo zfs rollback rpool/USERDATA/johnblood_uwcjk7@1019
```

回滚的时间长短取决于有多少信息改变。现在你可以查看家目录，被删除的目录（和它的内容）将会被恢复过来。


### 要不要试试 ZFS ？


这篇文章仅简单介绍的 Ubuntu下 ZFS 的用法。更多的信息请参考 [Ubuntu 的 ZFS Wiki页面](https://wiki.ubuntu.com/Kernel/Reference/ZFS)。我也推荐阅读 [ArsTechnica 的精彩文章](https://arstechnica.com/information-technology/2019/10/a-detailed-look-at-ubuntus-new-experimental-zfs-installer/)。


这个是试验性的功能。如果你还不了解 ZFS，你想用一个简单稳定的系统，请安装标准文件系统 EXT4。如果你想用闲置的机器体验，可以参照上面了解 ZFS。如果你是一个“专家”，并且知道自己在做什么，则可以随时随地随意尝试ZFS。


你之前用过 ZFS 吗？请在下面留言。




---


via: <https://itsfoss.com/zfs-ubuntu/>


作者：[John Paul](https://itsfoss.com/author/john/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[guevaraya](https://github.com/guevaraya) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


know in the comments below. If you found this article interesting, please take a minute to share it on social media, Hacker News or [Reddit](https://reddit.com/r/linuxusersgroup).




---


via: <https://itsfoss.com/zfs-ubuntu/>


作者：[John Paul](https://itsfoss.com/author/john/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[译者ID](https://github.com/%E8%AF%91%E8%80%85ID) 校对：[校对者ID](https://github.com/%E6%A0%A1%E5%AF%B9%E8%80%85ID)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
One of the main [features of Ubuntu 19.10](https://itsfoss.com/ubuntu-19-04-release-features/) is support for [ZFS](https://itsfoss.com/what-is-zfs/). Now you can easily install Ubuntu with on ZFS without any extra effort.

Normally, you install Linux with Ext4 filesystem. But if you do a fresh install of Ubuntu 19.10, you’ll see the option to use ZFS on the root. You must not use it on a dual boot system though because it will erase the entire disk.

![ZFS filesystem support in Ubuntu 19.10](https://itsfoss.com/content/images/wordpress/2019/05/zfs-ubuntu-19-10.jpg)

Let’s see why ZFS matters and how to take advantage of it on ZFS install of Ubuntu.

## How ZFS is different than other filesystems?

ZFS is designed with two major goals in mind: to handle large amounts of storage and prevent data corruption. ZFS can handle up to 256 quadrillion Zettabytes of storage. (Hence the Z in ZFS.) It can also handle files up to 16 exabytes in size.

If you are limited to a single drive laptop, you can still take advantage of the data protection features in ZFS. The copy-on-write feature ensures that data that is in use is not overwritten. Instead, the new information is written to a new block and the filesystem’s metadata is updated to point to the new block. ZFS can easily create snapshots of the filesystem. These snapshots track changes made to the filesystem and share with the filesystem the data that is the same to save space.

ZFS assigned a checksum to each file on the drive. It is constantly checking the state of the file against that checksum. If it detects that the file has become corrupt, it will attempt to automatically repair that file.

I have written a detailed article about [what is ZFS and what its features are](https://itsfoss.com/what-is-zfs/). Please read it if you are interested in knowing more on this topic.

Note

Keep in mind that the data protection features of ZFS can lead to a reduction in performance.

## Using ZFS on Ubuntu [For intermediate to advanced users]

![Using ZFS on Ubuntu](https://itsfoss.com/content/images/wordpress/2019/11/Using_ZFS_Ubuntu-800x450.jpg)

Once you have a clean install of Ubuntu with ZFS on the main disk you can start [taking advantage](https://wiki.ubuntu.com/Kernel/Reference/ZFS) of the features that this filesystem has.

Please note that all setup of ZFS requires the command line. I am not aware of any GUI tools for it.

### Creating a ZFS pool

**The section only applies if you have a system with more than one drive. If you only have one drive, Ubuntu will automatically create the pool during installation.**

Before you create your pool, you need to find out the id of the drives for the pool. You can use the command ** lsblk** to show this information.

To create a basic pool with three drives, use the following command:

` sudo zpool create pool-test /dev/sdb /dev/sdc /dev/sdd. `


Remember to replace ** pool-test** with the pool name of your choice.

This command will set up “a zero redundancy RAID-0 pool”. This means that if one of the drives becomes damaged or corrupt, you will lose data. If you do use this setup, it is recommended that you do regular backups.

You can alos add another disk to the pool by using this command:

`sudo zpool add pool-name /dev/sdx`


### Check the status of your ZFS pool

You can check the status of your new pool using this command:

` sudo zpool status pool-test `


![Zpool Status](https://itsfoss.com/content/images/wordpress/2019/10/zpool-status.png)

### Mirror a ZFS pool

To ensure that your data is safe, you can instead set up mirroring. Mirroring means that each drive contains the same data. With mirroring setup, you could lose two out of three drives and still have all of your information.

To create a mirror, you can use something like this:

`sudo zpool create pool-test mirror /dev/sdb /dev/sdc /dev/sdd`


### Create ZFS Snapshots for backup and restore

Snapshots allow you to create a fall-back position in case a file gets deleted or overwritten. For example, let’s create a snapshot, delete some folder in my home directory and restore them.

First, you need to find the dataset you want to snapshot. You can do that with the

` zfs list`


![Zfs List](https://itsfoss.com/content/images/wordpress/2019/10/zfs-list.png)

You can see that my home folder is located in **rpool/USERDATA/johnblood_uwcjk7**.

Let’s create a snapshot named **1910** using this command:

`sudo zfs snapshot rpool/USERDATA/johnblood_uwcjk7@1019`


The snapshot will be created very quickly. Now, I am going to delete the *Downloads* and *Documents* directories.

Now to restore the snapshot, all you have to do is run this command:

`sudo zfs rollback rpool/USERDATA/johnblood_uwcjk7@1019. `


The length of the rollback depends on how much the information changed. Now, you can check the home folder and the deleted folders (and their content) will be returned to their correct place.

## To ZFS or not?

This is just a quick glimpse at what you can do with ZFS on Ubuntu. For more information, check out [Ubuntu’s wiki page on ZFS.](https://wiki.ubuntu.com/Kernel/Reference/ZFS) I also recommend reading this [excellent article on ArsTechnica](https://arstechnica.com/information-technology/2019/10/a-detailed-look-at-ubuntus-new-experimental-zfs-installer/).

This is an experimental feature and if you are not aware of ZFS and you want to have a simple stable system, please go with the standard install on Ext4. If you have a spare machine that you want to experiment with, then only try something like this to learn a thing or two about ZFS. If you are an ‘expert’ and you know what you are doing, you are free to experiment ZFS wherever you like.

At this time the implementation of ZFS in Ubuntu 19.10 is experimental because of the way the disk is laid out may change in the [Ubuntu 20.04 release](https://itsfoss.com/ubuntu-20-04-release-features/). They are not guaranteeing that you will be able to upgrade if you have ZFS installed.

According to the [Ubuntu podcast](https://ubuntupodcast.org/2019/10/24/s12e29-doom/), the Ubuntu desktop team is working on a tool named [zsys](https://github.com/ubuntu/zsys). It will hook into apt and grub. As you upgrade your system, zsys will take snapshots so you can boot into a previous snapshot if the upgrade fails. It will arrive in the 20.04 release.

Have you ever used ZFS? Please let us know in the comments below. If you found this article interesting, please take a minute to share it on social media, Hacker News or [Reddit](http://reddit.com/r/linuxusersgroup).