ubuntu-16.04 – 在Hetzner专用服务器上的ZFS根目录上获取Ubuntu 16.04

到目前为止,很有可能在ZFS root-fs上运行Ubuntu 16.04. Ubuntu 16.04在默认的包管理器中有ZFS,而像this这样的指南,它并不难开始.

但是,我看到的所有指南都需要能够从Ubuntu安装映像启动.对于Hetzner专用服务器,这是一种不常见的安装过程,因为它需要工程师访问服务器并插入远程KVM.

默认情况下,专用服务器启动到救援系统,该系统允许通过其“installiamge”脚本安装各种Linux发行版.但是,此脚本尚不支持ZFS.

如何在ZFS根目录上运行Hetzner专用服务器?

最佳答案
基本的想法是将Ubuntu安装在硬盘驱动器上的一个小分区上,对硬盘驱动器进行分区以使用剩余的空间用于ZFS,然后将安装复制过来.我主要使用this guide指令如何做到这一点.

懒惰,和Ansible一起经历?我写了一小堆脚本来自动执行这些步骤.它们可在:https://github.com/tijszwinkels/hetzner-ubuntu-16.04-zfs-root-ansible/blob/master/hetzner-ubuntu-16.04.yml获得
请注意,这些脚本假设主机已启动进入Hetzner救援系统,他们将首先擦除您的驱动器.使用风险自负!

# SSH into the host.

# Wipe the drives. Assuming SSDs on 'sda' and 'sdb'.
/sbin/blkdiscard /dev/sda
/sbin/blkdiscard /dev/sdb

# Install Ubuntu 16.04 on a 4G partition using the Hetzner 'installimage' script
/root/.oldroot/nfs/install/installimage -a -n my-hostname -r yes -l 1 -p /:ext4:4G -K /root/.ssh/robot_user_keys -i /root/.oldroot/nfs/install/../images/Ubuntu-1604-xenial-64-minimal.tar.gz

# Reboot the system.
/sbin/shutdown -r now

# Wait for the host to come back up, and SSH in.

# Install the 'parted' parition editor
apt-get update && apt-get install -y parted

# Run parted on the first drive, create a partition in all remaining space. (UNTESTED!)
sudo parted /dev/sda
(parted) mkpart primary 4097MB -1s
(parted) quit

# Run parted on the second drive, create a partition in all remaining space. (UNTESTED!)
sudo parted /dev/sdb
(parted) mkpart primary 4097MB -1s
(parted) quit

# Install required ZFS packages
apt-get install -y zfs-dkms zfs-initramfs

# Create a ZFS pool named 'tank'
# Please note that I'm using the /dev/disk/by-id interface. This is more resilient than /dev/sda and /dev/sdb
zpool create -f -o ashift=13 -O atime=off -O dedup=off -O compression=lz4  tank mirror `ls /dev/disk/by-id/ata-*-part2` 

# Create OS partiton
zfs create tank/os

# Rsync the current system to the new partition.
rsync -a --one-file-system / /tank/os/

# Chroot into the system
cd /tank/os
mount --bind /dev dev
mount --bind /proc proc
mount --bind /sys sys
mount --bind /run run
chroot .

# Install GRUB into the drives
export ZPOOL_VDEV_NAME_PATH=YES
update-grub
grub-install /dev/sda
grub-install /dev/sdb

现在,您应该拥有一个Hetzner专用服务器,可以使用ZFS根fs快乐地引导到Ubuntu 16.04.祝好运!

转载注明原文:ubuntu-16.04 – 在Hetzner专用服务器上的ZFS根目录上获取Ubuntu 16.04 - 代码日志