如何将Ubuntu 14.04配置为本机ZFS根文件系统

时间:2020-03-05 15:31:54  来源:igfitidea点击:

如何将Ubuntu设置为本地ZFS根文件,该文件是高级文件系统和逻辑卷管理器,旨在克服Sun Microsystems设计的先前设计中发现的许多主要问题。
ZFS的主要功能包括其性能和数据完整性,其中包括数据的校验和以提供保护以防止损坏。
当数据冗余可用时,ZFS自动尝试纠正错误。
ZFS通过添加到池中的物理池存储设备为高存储容量和有效的数据压缩提供支持,并从该共享池中分配存储空间。

基本系统准备工作

在此设置中,我们将在已安装的Ubuntu 14.04 64位环境中使用ZFS作为基础,并具有以下规格和版本。

  • 操作系统:Ubuntu 14.04.1 LTS x86_64
  • grub安装(GRUB)2.02~beta2-9ubuntu1.3
  • spl-dkms 0.6.4-2~utopic
  • zfs-dkms 0.6.4-3~utopic
  • zfs-initramfs 0.6.4-3~utopic
  • 可用磁盘/分区大小10GB
  • 建议使用的内存4 GB
  • 使用的核心数2 GHz

ZFS安装设置

我们将在已经安装了10 GB可用空间的Ubuntu 14.04操作系统上启动ZFS安装设置。
我们需要以root用户身份登录才能执行所有这些步骤。

添加ZFS存储库

在开始使用ZFS之前,我们需要先安装它。
只需使用以下命令将存储库添加到apt-get中:

root@ubuntu-14:~# apt-add-repository --yes ppa:zfs-native/stable

使用ZFS安装进行系统更新

其中我们需要使用新的存储库更新操作系统,然后使用apt-get开始安装它。

root@ubuntu-14:~#apt-get update
root@ubuntu-14:~#apt-get install debootstrap ubuntu-zfs

在编译内核模块时,软件包的安装将花费一些时间。

需要zfs-initramfs将用于管理ZFS文件系统的ZFS实用程序放入initramfs引导镜像中。

root@ubuntu-14:~#apt-get install zfs-initramfs

ZFS模块检查

首先使用以下命令,我们将加载zfs模块,然后检查它们是否存在。

ZFS的磁盘分区

对于单个vdev池布局,我们的分区表如下所示,其中sda2将用于zfs根目录。

创建根池

现在,我们将使用/dev/sda *创建根池,或者,我们也可以使用/dev/disk/by-id链接创建根池。

root@ubuntu-14:~# mke2fs -m 0 -L /boot/grub -j /dev/sda2
root@ubuntu-14:~# zpool create -o ashift=9 rpool /dev/sda2

我们创建了可以通过zpool list命令检查的rpool。

创建根数据集和基本系统安装

其中我们创建根数据集,然后将其导出,然后使用-d/dev/sda2再次导入

root@ubuntu-14:~# zfs create rpool/ROOT
root@ubuntu-14:~# zfs create rpool/ROOT/ubuntu-1
root@ubuntu-14:~# zfs umount -a
root@ubuntu-14:~# zfs set mountpoint=/rpool/ROOT/ubuntu-1
root@ubuntu-14:~# zpool export rpool
root@ubuntu-14:~# zpool import -d /dev/sda2 -R /mnt rpool

现在,为我们在上一步中创建的GRUB挂载引导文件系统。

root@ubuntu-14:~# mkdir -p /mnt/boot/grub
root@ubuntu-14:~# mount /dev/sda2 /mnt/boot/grub
root@ubuntu-14:~# debootstrap trusty /mnt

debootstrap命令使新系统处于未配置状态,接下来我们将对其进行最小配置。

在成功完成debootstrap之后,我们会收到有关成功安装Base系统的消息,现在在执行以下命令后,我们将在生成语言环境后更新系统,如下所示。

root@ubuntu-14:~# cp /etc/hostname /mnt/etc/
root@ubuntu-14:~# cp /etc/hosts /mnt/etc/
root@ubuntu-14:~# mount --bind /dev /mnt/dev
root@ubuntu-14:~# mount --bind /proc /mnt/proc
root@ubuntu-14:~# mount --bind /sys /mnt/sys
root@ubuntu-14:~# chroot /mnt /bin/bash --login
root@ubuntu-14:/# locale-gen en_US.UTF-8

因此,我们在新系统可见的环境中使用了虚拟文件系统,并使用chroot命令在chroot环境中安装了PPA支持。

安装Ubuntu和Native软件包

要在Linux上使用PPA中打包的ZFS,需要ubuntu-minimal软件包。
通过执行以下命令,在新系统的chroot环境中安装ZFS。

root@ubuntu-14:/# apt-get install ubuntu-minimal software-properties-common
root@ubuntu-14:/# apt-add-repository --yes ppa:zfs-native/stable
root@ubuntu-14:/# apt-add-repository --yes ppa:zfs-native/grub < - See below note on this command
root@ubuntu-14:/# apt-get update
root@ubuntu-14:/# apt-get install --no-install-recommends linux-image-generic linux-headers-generic
root@ubuntu-14:/# apt-get dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

生成新的grub配置

root@ubuntu-14:/# grub-probe /
zfs
root@ubuntu-14:~# ls /boot/grub/i386-pc/zfs*
/boot/grub/i386-pc/zfs.mod /boot/grub/i386-pc/zfscrypt.mod /boot/grub/i386-pc/zfsinfo.mod
root@ubuntu-14:~#
root@ubuntu-14:~# update-initramfs -c -k all
update-initramfs: Generating /boot/initrd.img-3.13.0-24-generic

验证正确的根条目

root@ubuntu-14:~# grep "boot=zfs" /boot/grub/grub.cfg
linux /ROOT/ubuntu-1@/boot/vmlinuz-3.13.0-24-generic root=ZFS=rpool/ROOT/ubuntu-1 ro boot=zfs
linux /ROOT/ubuntu-1@/boot/vmlinuz-3.13.0-24-generic root=ZFS=rpool/ROOT/ubuntu-1 ro boot=zfs
root@ubuntu-14:~# grep zfs /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="boot=zfs"

更新G

使用update-grub命令更新grub以允许自动生成的zfs引导菜单。

root@ubuntu-14:~# update-grub
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-3.13.0-24-generic
Found initrd image: /boot/initrd.img-3.13.0-24-generic
done

使用以下命令将引导加载程序安装到MBR,并确保获得完整的安装消息。
必须使用readlink,因为最近的GRUB版本没有引用符号链接。

root@ubuntu-14:~# grub-install $(readlink -f /dev/sda)
Installing for i386-pc platform.
Installation finished. No error reported.

现在,从chroot环境退出回到基本环境,并从所有文件系统卸下(如果已连接)。

ZFS确认

我们已经完成了所有设置,现在使用df命令检查以确认rpool。

一些已知问题

在此安装过程中,我们可能会遇到ZFS启动问题,可以通过使用以下过程来避免这些问题。

创建快照

我们必须创建ZFS快照,该快照在首次引导后可用作救援环境。
我们可以使用以下命令将ZFS快照作为。

root@ubuntu-14:~# apt-get clean
root@ubuntu-14:~# zfs snapshot rpool/ROOT/ubuntu1

Grub 问题

有时Grub不显示启动菜单,或者显示错误“未知文件系统”。
这可能是因为grub无法读取zfs池,或者其可能的原因是我们先前使某些vdev脱机。
为了从中恢复过来,我们需要做以下两件事。

  • 删除/断开脱机磁盘
  • 我们可以使用Live CD方法从ext4安装启动
  • 或者通过使磁盘联机来执行此操作,或者删除脱机磁盘,然后再次添加它们