mirror of
https://github.com/terem42/zfs-hetzner-vm.git
synced 2025-12-23 07:18:37 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc72f24c43 | ||
|
|
f2331df185 | ||
|
|
effc9964ee | ||
|
|
c1391bb65f | ||
|
|
e322cf49b4 | ||
|
|
762993e7e8 | ||
|
|
a283542850 | ||
|
|
c23b735462 | ||
|
|
c7b8d13be8 | ||
|
|
d8f796dc38 | ||
|
|
3d93256d17 | ||
|
|
37baec84ca | ||
|
|
3b9a132a1d | ||
|
|
fecb5ca25c | ||
|
|
59e7e2352f | ||
|
|
c1122406eb | ||
|
|
40d0221d18 | ||
|
|
f41b62ad32 | ||
|
|
ccccb6f175 |
11
.github/workflows/shellcheck.yml
vendored
Normal file
11
.github/workflows/shellcheck.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
name: shellcheck
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Run shellcheck
|
||||
run: ci/run_shellcheck.sh
|
||||
@@ -1,5 +1,7 @@
|
||||
# zfs-hetzner-vm
|
||||
|
||||
[](https://github.com/terem42/zfs-hetzner-vm/actions/workflows/shellcheck.yml)
|
||||
|
||||
Scripts to install Debian 11, 10 or Ubuntu 20, 18 with ZFS root on Hetzner root servers (virtual and dedicated).<br/>
|
||||
__WARNING:__ all data on the disk will be destroyed.
|
||||
|
||||
|
||||
25
ci/run_shellcheck.sh
Executable file
25
ci/run_shellcheck.sh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -o pipefail
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o errtrace
|
||||
shopt -s inherit_errexit
|
||||
|
||||
# Always download the latest version:
|
||||
#
|
||||
# - it's fast and stable enough not to worry about it;
|
||||
# - the workflow is basically single-person, so there's no risk of a new dev encountering an error found
|
||||
# by a new shellcheck version.
|
||||
|
||||
mkdir -p /opt/shellcheck
|
||||
|
||||
wget -qO- https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz \
|
||||
| tar xJv -O shellcheck-stable/shellcheck \
|
||||
> /opt/shellcheck/shellcheck
|
||||
|
||||
chmod +x /opt/shellcheck/shellcheck
|
||||
|
||||
/opt/shellcheck/shellcheck --version
|
||||
|
||||
grep -lZP '^#!/bin/\w+sh' -R | xargs -0 /opt/shellcheck/shellcheck
|
||||
@@ -40,7 +40,7 @@ c_deb_security_repo=http://mirror.hetzner.de/debian/security
|
||||
|
||||
c_default_zfs_arc_max_mb=250
|
||||
c_default_bpool_tweaks="-o ashift=12 -O compression=lz4"
|
||||
c_default_rpool_tweaks="-o ashift=12 -O acltype=posixacl -O compression=lz4 -O dnodesize=auto -O relatime=on -O xattr=sa -O normalization=formD"
|
||||
c_default_rpool_tweaks="-o ashift=12 -O acltype=posixacl -O compression=zstd-9 -O dnodesize=auto -O relatime=on -O xattr=sa -O normalization=formD"
|
||||
c_default_hostname=terem
|
||||
c_zfs_mount_dir=/mnt
|
||||
c_log_dir=$(dirname "$(mktemp)")/zfs-hetzner-vm
|
||||
@@ -62,7 +62,9 @@ function print_step_info_header {
|
||||
###############################################################################
|
||||
# ${FUNCNAME[1]}"
|
||||
|
||||
[[ "${1:-}" != "" ]] && echo -n " $1" || true
|
||||
if [[ "${1:-}" != "" ]]; then
|
||||
echo -n " $1"
|
||||
fi
|
||||
|
||||
echo "
|
||||
###############################################################################
|
||||
@@ -141,13 +143,13 @@ function initial_load_debian_zed_cache {
|
||||
|
||||
local success=0
|
||||
|
||||
if [[ ! -e /mnt/etc/zfs/zfs-list.cache/rpool ]] || [[ -e /mnt/etc/zfs/zfs-list.cache/rpool && (( $(ls -l /mnt/etc/zfs/zfs-list.cache/rpool 2> /dev/null | cut -d ' ' -f 5) == 0 )) ]]; then
|
||||
if [[ ! -e /mnt/etc/zfs/zfs-list.cache/rpool ]] || [[ -e /mnt/etc/zfs/zfs-list.cache/rpool && (( $(find /mnt/etc/zfs/zfs-list.cache/rpool -type f -printf '%s' 2> /dev/null) == 0 )) ]]; then
|
||||
chroot_execute "zfs set canmount=noauto rpool"
|
||||
|
||||
SECONDS=0
|
||||
|
||||
while (( SECONDS++ <= 120 )); do
|
||||
if [[ -e /mnt/etc/zfs/zfs-list.cache/rpool ]] && (( "$(ls -l /mnt/etc/zfs/zfs-list.cache/rpool | cut -d ' ' -f 5)" > 0 )); then
|
||||
if [[ -e /mnt/etc/zfs/zfs-list.cache/rpool ]] && (( $(find /mnt/etc/zfs/zfs-list.cache/rpool -type f -printf '%s' 2> /dev/null) > 0 )); then
|
||||
success=1
|
||||
break
|
||||
else
|
||||
@@ -431,9 +433,8 @@ function unmount_and_export_fs {
|
||||
zpools_exported=99
|
||||
echo "===========exporting zfs pools============="
|
||||
set +e
|
||||
while (( zpools_exported == 99 )) && (( SECONDS++ <= 60 )); do
|
||||
zpool export -a 2> /dev/null
|
||||
if [[ $? == 0 ]]; then
|
||||
while (( zpools_exported == 99 )) && (( SECONDS++ <= 60 )); do
|
||||
if zpool export -a 2> /dev/null; then
|
||||
zpools_exported=1
|
||||
echo "all zfs pools were succesfully exported"
|
||||
break;
|
||||
@@ -499,7 +500,7 @@ echo "======= installing zfs on rescue system =========="
|
||||
apt install --yes zfs-dkms zfsutils-linux
|
||||
add-apt-repository -r 'deb http://ppa.launchpad.net/jonathonf/zfs/ubuntu focal main'
|
||||
apt update
|
||||
find /usr/local/sbin/ -type l | xargs rm
|
||||
find /usr/local/sbin/ -type l -exec rm {} +
|
||||
zfs --version
|
||||
|
||||
echo "======= partitioning the disk =========="
|
||||
@@ -540,12 +541,16 @@ echo "======= create zfs pools and datasets =========="
|
||||
pools_mirror_option=
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
zpool create \
|
||||
$v_bpool_tweaks -O canmount=off -O devices=off \
|
||||
"$v_bpool_tweaks" -O canmount=off -O devices=off \
|
||||
-o cachefile=/etc/zfs/zpool.cache \
|
||||
-O mountpoint=/boot -R $c_zfs_mount_dir -f \
|
||||
$v_bpool_name $pools_mirror_option "${bpool_disks_partitions[@]}"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
echo -n "$v_passphrase" | zpool create \
|
||||
-o cachefile=/etc/zfs/zpool.cache \
|
||||
$v_rpool_tweaks \
|
||||
"${encryption_options[@]}" \
|
||||
-O mountpoint=/ -R $c_zfs_mount_dir -f \
|
||||
@@ -728,25 +733,8 @@ chroot_execute "dpkg-reconfigure openssh-server -f noninteractive"
|
||||
echo "======= set root password =========="
|
||||
chroot_execute "echo root:$(printf "%q" "$v_root_password") | chpasswd"
|
||||
|
||||
echo "======= setting up zfs services =========="
|
||||
chroot_execute "cat > /etc/systemd/system/zfs-import-bpool.service <<UNIT
|
||||
[Unit]
|
||||
DefaultDependencies=no
|
||||
Before=zfs-import-scan.service
|
||||
Before=zfs-import-cache.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStartPre=/bin/sh -c '[ -f /etc/zfs/zpool.cache ] && mv /etc/zfs/zpool.cache /etc/zfs/preboot_zpool.cache || true'
|
||||
ExecStart=/sbin/zpool import -N -o cachefile=none -d /dev/disk/by-id $v_bpool_name
|
||||
ExecStartPost=/bin/sh -c '[ -f /etc/zfs/preboot_zpool.cache ] && mv /etc/zfs/preboot_zpool.cache /etc/zfs/zpool.cache || true'
|
||||
|
||||
[Install]
|
||||
WantedBy=zfs-import.target
|
||||
UNIT"
|
||||
|
||||
chroot_execute "systemctl enable zfs-import-bpool.service"
|
||||
echo "======= setting up zfs cache =========="
|
||||
cp /etc/zfs/zpool.cache /mnt/etc/zfs/zpool.cache
|
||||
|
||||
echo "========setting up zfs module parameters========"
|
||||
chroot_execute "echo options zfs zfs_arc_max=$((v_zfs_arc_max_mb * 1024 * 1024)) >> /etc/modprobe.d/zfs.conf"
|
||||
@@ -841,7 +829,7 @@ fi
|
||||
|
||||
echo "======= setting mountpoints =========="
|
||||
chroot_execute "zfs set mountpoint=legacy $v_bpool_name/BOOT/debian"
|
||||
chroot_execute "echo $v_bpool_name/BOOT/debian /boot zfs nodev,relatime,x-systemd.requires=zfs-import-bpool.service 0 0 > /etc/fstab"
|
||||
chroot_execute "echo $v_bpool_name/BOOT/debian /boot zfs nodev,relatime,x-systemd.requires=zfs-mount.service,x-systemd.device-timeout=10 0 0 > /etc/fstab"
|
||||
|
||||
chroot_execute "zfs set mountpoint=legacy $v_rpool_name/var/log"
|
||||
chroot_execute "echo $v_rpool_name/var/log /var/log zfs nodev,relatime 0 0 >> /etc/fstab"
|
||||
@@ -853,7 +841,9 @@ chroot_execute "zfs set mountpoint=legacy $v_rpool_name/tmp"
|
||||
chroot_execute "echo $v_rpool_name/tmp /tmp zfs nodev,relatime 0 0 >> /etc/fstab"
|
||||
|
||||
echo "========= add swap, if defined"
|
||||
[[ $v_swap_size -gt 0 ]] && chroot_execute "echo /dev/zvol/$v_rpool_name/swap none swap discard 0 0 >> /etc/fstab" || true
|
||||
if [[ $v_swap_size -gt 0 ]]; then
|
||||
chroot_execute "echo /dev/zvol/$v_rpool_name/swap none swap discard 0 0 >> /etc/fstab"
|
||||
fi
|
||||
chroot_execute "echo RESUME=none > /etc/initramfs-tools/conf.d/resume"
|
||||
|
||||
echo "======= unmounting filesystems and zfs pools =========="
|
||||
|
||||
@@ -62,7 +62,10 @@ function print_step_info_header {
|
||||
###############################################################################
|
||||
# ${FUNCNAME[1]}"
|
||||
|
||||
[[ "${1:-}" != "" ]] && echo -n " $1" || true
|
||||
if [[ "${1:-}" != "" ]]; then
|
||||
echo -n " $1"
|
||||
fi
|
||||
|
||||
|
||||
echo "
|
||||
###############################################################################
|
||||
@@ -141,13 +144,13 @@ function initial_load_debian_zed_cache {
|
||||
|
||||
local success=0
|
||||
|
||||
if [[ ! -e /mnt/etc/zfs/zfs-list.cache/rpool ]] || [[ -e /mnt/etc/zfs/zfs-list.cache/rpool && (( $(ls -l /mnt/etc/zfs/zfs-list.cache/rpool 2> /dev/null | cut -d ' ' -f 5) == 0 )) ]]; then
|
||||
if [[ ! -e /mnt/etc/zfs/zfs-list.cache/rpool ]] || [[ -e /mnt/etc/zfs/zfs-list.cache/rpool && (( $(find /mnt/etc/zfs/zfs-list.cache/rpool -type f -printf '%s' 2> /dev/null) == 0 )) ]]; then
|
||||
chroot_execute "zfs set canmount=noauto rpool"
|
||||
|
||||
SECONDS=0
|
||||
|
||||
while (( SECONDS++ <= 120 )); do
|
||||
if [[ -e /mnt/etc/zfs/zfs-list.cache/rpool ]] && (( "$(ls -l /mnt/etc/zfs/zfs-list.cache/rpool | cut -d ' ' -f 5)" > 0 )); then
|
||||
if [[ -e /mnt/etc/zfs/zfs-list.cache/rpool ]] && (( $(find /mnt/etc/zfs/zfs-list.cache/rpool -type f -printf '%s' 2> /dev/null) > 0 )); then
|
||||
success=1
|
||||
break
|
||||
else
|
||||
@@ -431,9 +434,8 @@ function unmount_and_export_fs {
|
||||
zpools_exported=99
|
||||
echo "===========exporting zfs pools============="
|
||||
set +e
|
||||
while (( zpools_exported == 99 )) && (( SECONDS++ <= 60 )); do
|
||||
zpool export -a 2> /dev/null
|
||||
if [[ $? == 0 ]]; then
|
||||
while (( zpools_exported == 99 )) && (( SECONDS++ <= 60 )); do
|
||||
if zpool export -a 2> /dev/null; then
|
||||
zpools_exported=1
|
||||
echo "all zfs pools were succesfully exported"
|
||||
break;
|
||||
@@ -499,7 +501,7 @@ echo "======= installing zfs on rescue system =========="
|
||||
apt install --yes zfs-dkms zfsutils-linux
|
||||
add-apt-repository -r 'deb http://ppa.launchpad.net/jonathonf/zfs/ubuntu focal main'
|
||||
apt update
|
||||
find /usr/local/sbin/ -type l | xargs rm
|
||||
find /usr/local/sbin/ -type l -exec rm {} +
|
||||
zfs --version
|
||||
|
||||
echo "======= partitioning the disk =========="
|
||||
@@ -540,13 +542,17 @@ echo "======= create zfs pools and datasets =========="
|
||||
pools_mirror_option=
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
zpool create \
|
||||
$v_bpool_tweaks -O canmount=off -O devices=off \
|
||||
-o cachefile=/etc/zfs/zpool.cache \
|
||||
-O mountpoint=/boot -R $c_zfs_mount_dir -f \
|
||||
$v_bpool_name $pools_mirror_option "${bpool_disks_partitions[@]}"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
echo -n "$v_passphrase" | zpool create \
|
||||
$v_rpool_tweaks \
|
||||
-o cachefile=/etc/zfs/zpool.cache \
|
||||
"${encryption_options[@]}" \
|
||||
-O mountpoint=/ -R $c_zfs_mount_dir -f \
|
||||
$v_rpool_name $pools_mirror_option "${rpool_disks_partitions[@]}"
|
||||
@@ -728,25 +734,9 @@ chroot_execute "dpkg-reconfigure openssh-server -f noninteractive"
|
||||
echo "======= set root password =========="
|
||||
chroot_execute "echo root:$(printf "%q" "$v_root_password") | chpasswd"
|
||||
|
||||
echo "======= setting up zfs services =========="
|
||||
chroot_execute "cat > /etc/systemd/system/zfs-import-bpool.service <<UNIT
|
||||
[Unit]
|
||||
DefaultDependencies=no
|
||||
Before=zfs-import-scan.service
|
||||
Before=zfs-import-cache.service
|
||||
echo "======= setting up zfs cache =========="
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStartPre=/bin/sh -c '[ -f /etc/zfs/zpool.cache ] && mv /etc/zfs/zpool.cache /etc/zfs/preboot_zpool.cache || true'
|
||||
ExecStart=/sbin/zpool import -N -o cachefile=none -d /dev/disk/by-id $v_bpool_name
|
||||
ExecStartPost=/bin/sh -c '[ -f /etc/zfs/preboot_zpool.cache ] && mv /etc/zfs/preboot_zpool.cache /etc/zfs/zpool.cache || true'
|
||||
|
||||
[Install]
|
||||
WantedBy=zfs-import.target
|
||||
UNIT"
|
||||
|
||||
chroot_execute "systemctl enable zfs-import-bpool.service"
|
||||
cp /etc/zfs/zpool.cache /mnt/etc/zfs/zpool.cache
|
||||
|
||||
echo "========setting up zfs module parameters========"
|
||||
chroot_execute "echo options zfs zfs_arc_max=$((v_zfs_arc_max_mb * 1024 * 1024)) >> /etc/modprobe.d/zfs.conf"
|
||||
@@ -844,7 +834,7 @@ fi
|
||||
|
||||
echo "======= setting mountpoints =========="
|
||||
chroot_execute "zfs set mountpoint=legacy $v_bpool_name/BOOT/debian"
|
||||
chroot_execute "echo $v_bpool_name/BOOT/debian /boot zfs nodev,relatime,x-systemd.requires=zfs-import-bpool.service 0 0 > /etc/fstab"
|
||||
chroot_execute "echo $v_bpool_name/BOOT/debian /boot zfs nodev,relatime,x-systemd.requires=zfs-mount.service,x-systemd.device-timeout=10 0 0 > /etc/fstab"
|
||||
|
||||
chroot_execute "zfs set mountpoint=legacy $v_rpool_name/var/log"
|
||||
chroot_execute "echo $v_rpool_name/var/log /var/log zfs nodev,relatime 0 0 >> /etc/fstab"
|
||||
@@ -856,7 +846,10 @@ chroot_execute "zfs set mountpoint=legacy $v_rpool_name/tmp"
|
||||
chroot_execute "echo $v_rpool_name/tmp /tmp zfs nodev,relatime 0 0 >> /etc/fstab"
|
||||
|
||||
echo "========= add swap, if defined"
|
||||
[[ $v_swap_size -gt 0 ]] && chroot_execute "echo /dev/zvol/$v_rpool_name/swap none swap discard 0 0 >> /etc/fstab" || true
|
||||
if [[ $v_swap_size -gt 0 ]]; then
|
||||
chroot_execute "echo /dev/zvol/$v_rpool_name/swap none swap discard 0 0 >> /etc/fstab"
|
||||
fi
|
||||
|
||||
chroot_execute "echo RESUME=none > /etc/initramfs-tools/conf.d/resume"
|
||||
|
||||
echo "======= unmounting filesystems and zfs pools =========="
|
||||
|
||||
@@ -40,7 +40,7 @@ c_deb_security_repo=http://mirror.hetzner.de/ubuntu/security
|
||||
|
||||
c_default_zfs_arc_max_mb=250
|
||||
c_default_bpool_tweaks="-o ashift=12 -O compression=lz4"
|
||||
c_default_rpool_tweaks="-o ashift=12 -O acltype=posixacl -O compression=lz4 -O dnodesize=auto -O relatime=on -O xattr=sa -O normalization=formD"
|
||||
c_default_rpool_tweaks="-o ashift=12 -O acltype=posixacl -O compression=zstd-9 -O dnodesize=auto -O relatime=on -O xattr=sa -O normalization=formD"
|
||||
c_default_hostname=terem
|
||||
c_zfs_mount_dir=/mnt
|
||||
c_log_dir=$(dirname "$(mktemp)")/zfs-hetzner-vm
|
||||
@@ -62,7 +62,9 @@ function print_step_info_header {
|
||||
###############################################################################
|
||||
# ${FUNCNAME[1]}"
|
||||
|
||||
[[ "${1:-}" != "" ]] && echo -n " $1" || true
|
||||
if [[ "${1:-}" != "" ]]; then
|
||||
echo -n " $1"
|
||||
fi
|
||||
|
||||
echo "
|
||||
###############################################################################
|
||||
@@ -399,8 +401,8 @@ function unmount_and_export_fs {
|
||||
echo "===========exporting zfs pools============="
|
||||
set +e
|
||||
while (( zpools_exported == 99 )) && (( SECONDS++ <= 60 )); do
|
||||
zpool export -a 2> /dev/null
|
||||
if [[ $? == 0 ]]; then
|
||||
|
||||
if zpool export -a 2> /dev/null; then
|
||||
zpools_exported=1
|
||||
echo "all zfs pools were succesfully exported"
|
||||
break;
|
||||
@@ -466,7 +468,7 @@ echo "======= installing zfs on rescue system =========="
|
||||
apt install --yes zfs-dkms zfsutils-linux
|
||||
add-apt-repository -r 'deb http://ppa.launchpad.net/jonathonf/zfs/ubuntu focal main'
|
||||
apt update
|
||||
find /usr/local/sbin/ -type l | xargs rm
|
||||
find /usr/local/sbin/ -type l -exec rm {} +
|
||||
zfs --version
|
||||
|
||||
echo "======= partitioning the disk =========="
|
||||
@@ -507,13 +509,17 @@ echo "======= create zfs pools and datasets =========="
|
||||
pools_mirror_option=
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
zpool create \
|
||||
$v_bpool_tweaks -O canmount=off -O devices=off \
|
||||
-o cachefile=/etc/zfs/zpool.cache \
|
||||
-O mountpoint=/boot -R $c_zfs_mount_dir -f \
|
||||
$v_bpool_name $pools_mirror_option "${bpool_disks_partitions[@]}"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
echo -n "$v_passphrase" | zpool create \
|
||||
$v_rpool_tweaks \
|
||||
-o cachefile=/etc/zfs/zpool.cache \
|
||||
"${encryption_options[@]}" \
|
||||
-O mountpoint=/ -R $c_zfs_mount_dir -f \
|
||||
$v_rpool_name $pools_mirror_option "${rpool_disks_partitions[@]}"
|
||||
@@ -710,25 +716,8 @@ chroot_execute "dpkg-reconfigure openssh-server -f noninteractive"
|
||||
echo "======= set root password =========="
|
||||
chroot_execute "echo root:$(printf "%q" "$v_root_password") | chpasswd"
|
||||
|
||||
echo "======= setting up zfs services =========="
|
||||
chroot_execute "cat > /etc/systemd/system/zfs-import-bpool.service <<UNIT
|
||||
[Unit]
|
||||
DefaultDependencies=no
|
||||
Before=zfs-import-scan.service
|
||||
Before=zfs-import-cache.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStartPre=/bin/sh -c '[ -f /etc/zfs/zpool.cache ] && mv /etc/zfs/zpool.cache /etc/zfs/preboot_zpool.cache || true'
|
||||
ExecStart=/sbin/zpool import -N -o cachefile=none $v_bpool_name
|
||||
ExecStartPost=/bin/sh -c '[ -f /etc/zfs/preboot_zpool.cache ] && mv /etc/zfs/preboot_zpool.cache /etc/zfs/zpool.cache || true'
|
||||
|
||||
[Install]
|
||||
WantedBy=zfs-import.target
|
||||
UNIT"
|
||||
|
||||
chroot_execute "systemctl enable zfs-import-bpool.service"
|
||||
echo "======= setting up zfs cache =========="
|
||||
cp /etc/zfs/zpool.cache /mnt/etc/zfs/zpool.cache
|
||||
|
||||
echo "========setting up zfs module parameters========"
|
||||
chroot_execute "echo options zfs zfs_arc_max=$((v_zfs_arc_max_mb * 1024 * 1024)) >> /etc/modprobe.d/zfs.conf"
|
||||
@@ -833,7 +822,7 @@ chroot_execute "zfs set canmount=noauto rpool"
|
||||
|
||||
echo "======= setting mountpoints =========="
|
||||
chroot_execute "zfs set mountpoint=legacy $v_bpool_name/BOOT/ubuntu"
|
||||
chroot_execute "echo $v_bpool_name/BOOT/ubuntu /boot zfs nodev,relatime,x-systemd.requires=zfs-import-bpool.service 0 0 > /etc/fstab"
|
||||
chroot_execute "echo $v_bpool_name/BOOT/ubuntu /boot zfs nodev,relatime,x-systemd.requires=zfs-mount.service,x-systemd.device-timeout=10 0 0 > /etc/fstab"
|
||||
|
||||
chroot_execute "zfs set mountpoint=legacy $v_rpool_name/var/log"
|
||||
chroot_execute "echo $v_rpool_name/var/log /var/log zfs nodev,relatime 0 0 >> /etc/fstab"
|
||||
@@ -845,7 +834,10 @@ chroot_execute "zfs set mountpoint=legacy $v_rpool_name/tmp"
|
||||
chroot_execute "echo $v_rpool_name/tmp /tmp zfs nodev,relatime 0 0 >> /etc/fstab"
|
||||
|
||||
echo "========= add swap, if defined"
|
||||
[[ $v_swap_size -gt 0 ]] && chroot_execute "echo /dev/zvol/$v_rpool_name/swap none swap discard 0 0 >> /etc/fstab" || true
|
||||
if [[ $v_swap_size -gt 0 ]]; then
|
||||
chroot_execute "echo /dev/zvol/$v_rpool_name/swap none swap discard 0 0 >> /etc/fstab"
|
||||
fi
|
||||
|
||||
chroot_execute "echo RESUME=none > /etc/initramfs-tools/conf.d/resume"
|
||||
|
||||
echo "======= unmounting filesystems and zfs pools =========="
|
||||
|
||||
@@ -40,7 +40,7 @@ c_deb_security_repo=http://mirror.hetzner.de/ubuntu/security
|
||||
|
||||
c_default_zfs_arc_max_mb=250
|
||||
c_default_bpool_tweaks="-o ashift=12 -O compression=lz4"
|
||||
c_default_rpool_tweaks="-o ashift=12 -O acltype=posixacl -O compression=lz4 -O dnodesize=auto -O relatime=on -O xattr=sa -O normalization=formD"
|
||||
c_default_rpool_tweaks="-o ashift=12 -O acltype=posixacl -O compression=zstd-9 -O dnodesize=auto -O relatime=on -O xattr=sa -O normalization=formD"
|
||||
c_default_hostname=terem
|
||||
c_zfs_mount_dir=/mnt
|
||||
c_log_dir=$(dirname "$(mktemp)")/zfs-hetzner-vm
|
||||
@@ -62,7 +62,9 @@ function print_step_info_header {
|
||||
###############################################################################
|
||||
# ${FUNCNAME[1]}"
|
||||
|
||||
[[ "${1:-}" != "" ]] && echo -n " $1" || true
|
||||
if [[ "${1:-}" != "" ]]; then
|
||||
echo -n " $1"
|
||||
fi
|
||||
|
||||
echo "
|
||||
###############################################################################
|
||||
@@ -399,8 +401,8 @@ function unmount_and_export_fs {
|
||||
echo "===========exporting zfs pools============="
|
||||
set +e
|
||||
while (( zpools_exported == 99 )) && (( SECONDS++ <= 60 )); do
|
||||
zpool export -a 2> /dev/null
|
||||
if [[ $? == 0 ]]; then
|
||||
|
||||
if zpool export -a 2> /dev/null; then
|
||||
zpools_exported=1
|
||||
echo "all zfs pools were succesfully exported"
|
||||
break;
|
||||
@@ -466,7 +468,7 @@ echo "======= installing zfs on rescue system =========="
|
||||
apt install --yes zfs-dkms zfsutils-linux
|
||||
add-apt-repository -r 'deb http://ppa.launchpad.net/jonathonf/zfs/ubuntu focal main'
|
||||
apt update
|
||||
find /usr/local/sbin/ -type l | xargs rm
|
||||
find /usr/local/sbin/ -type l -exec rm {} +
|
||||
zfs --version
|
||||
|
||||
echo "======= partitioning the disk =========="
|
||||
@@ -507,13 +509,17 @@ echo "======= create zfs pools and datasets =========="
|
||||
pools_mirror_option=
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
zpool create \
|
||||
$v_bpool_tweaks -O canmount=off -O devices=off \
|
||||
-o cachefile=/etc/zfs/zpool.cache \
|
||||
-O mountpoint=/boot -R $c_zfs_mount_dir -f \
|
||||
$v_bpool_name $pools_mirror_option "${bpool_disks_partitions[@]}"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
echo -n "$v_passphrase" | zpool create \
|
||||
$v_rpool_tweaks \
|
||||
-o cachefile=/etc/zfs/zpool.cache \
|
||||
"${encryption_options[@]}" \
|
||||
-O mountpoint=/ -R $c_zfs_mount_dir -f \
|
||||
$v_rpool_name $pools_mirror_option "${rpool_disks_partitions[@]}"
|
||||
@@ -711,25 +717,8 @@ chroot_execute "dpkg-reconfigure openssh-server -f noninteractive"
|
||||
echo "======= set root password =========="
|
||||
chroot_execute "echo root:$(printf "%q" "$v_root_password") | chpasswd"
|
||||
|
||||
echo "======= setting up zfs services =========="
|
||||
chroot_execute "cat > /etc/systemd/system/zfs-import-bpool.service <<UNIT
|
||||
[Unit]
|
||||
DefaultDependencies=no
|
||||
Before=zfs-import-scan.service
|
||||
Before=zfs-import-cache.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStartPre=/bin/sh -c '[ -f /etc/zfs/zpool.cache ] && mv /etc/zfs/zpool.cache /etc/zfs/preboot_zpool.cache || true'
|
||||
ExecStart=/sbin/zpool import -N -o cachefile=none $v_bpool_name
|
||||
ExecStartPost=/bin/sh -c '[ -f /etc/zfs/preboot_zpool.cache ] && mv /etc/zfs/preboot_zpool.cache /etc/zfs/zpool.cache || true'
|
||||
|
||||
[Install]
|
||||
WantedBy=zfs-import.target
|
||||
UNIT"
|
||||
|
||||
chroot_execute "systemctl enable zfs-import-bpool.service"
|
||||
echo "======= setting up zfs cache =========="
|
||||
cp /etc/zfs/zpool.cache /mnt/etc/zfs/zpool.cache
|
||||
|
||||
echo "========setting up zfs module parameters========"
|
||||
chroot_execute "echo options zfs zfs_arc_max=$((v_zfs_arc_max_mb * 1024 * 1024)) >> /etc/modprobe.d/zfs.conf"
|
||||
@@ -834,7 +823,7 @@ chroot_execute "zfs set canmount=noauto rpool"
|
||||
|
||||
echo "======= setting mountpoints =========="
|
||||
chroot_execute "zfs set mountpoint=legacy $v_bpool_name/BOOT/ubuntu"
|
||||
chroot_execute "echo $v_bpool_name/BOOT/ubuntu /boot zfs nodev,relatime,x-systemd.requires=zfs-import-bpool.service 0 0 > /etc/fstab"
|
||||
chroot_execute "echo $v_bpool_name/BOOT/ubuntu /boot zfs nodev,relatime,x-systemd.requires=zfs-mount.service,x-systemd.device-timeout=10 0 0 > /etc/fstab"
|
||||
|
||||
chroot_execute "zfs set mountpoint=legacy $v_rpool_name/var/log"
|
||||
chroot_execute "echo $v_rpool_name/var/log /var/log zfs nodev,relatime 0 0 >> /etc/fstab"
|
||||
@@ -846,7 +835,10 @@ chroot_execute "zfs set mountpoint=legacy $v_rpool_name/tmp"
|
||||
chroot_execute "echo $v_rpool_name/tmp /tmp zfs nodev,relatime 0 0 >> /etc/fstab"
|
||||
|
||||
echo "========= add swap, if defined"
|
||||
[[ $v_swap_size -gt 0 ]] && chroot_execute "echo /dev/zvol/$v_rpool_name/swap none swap discard 0 0 >> /etc/fstab" || true
|
||||
if [[ $v_swap_size -gt 0 ]]; then
|
||||
chroot_execute "echo /dev/zvol/$v_rpool_name/swap none swap discard 0 0 >> /etc/fstab"
|
||||
fi
|
||||
|
||||
chroot_execute "echo RESUME=none > /etc/initramfs-tools/conf.d/resume"
|
||||
|
||||
echo "======= unmounting filesystems and zfs pools =========="
|
||||
|
||||
Reference in New Issue
Block a user