mirror of
https://github.com/terem42/zfs-hetzner-vm.git
synced 2025-12-22 23:08:36 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8858afa4a3 | ||
|
|
d11cae2671 | ||
|
|
373f77fa73 | ||
|
|
587d3a1f4f | ||
|
|
556157ed33 | ||
|
|
56e36a0987 | ||
|
|
d5b4bf3034 | ||
|
|
f79b735143 |
@@ -399,7 +399,7 @@ function determine_kernel_variant {
|
||||
}
|
||||
|
||||
function chroot_execute {
|
||||
chroot $c_zfs_mount_dir bash -c "$1"
|
||||
chroot $c_zfs_mount_dir bash -c "DEBIAN_FRONTEND=noninteractive $1"
|
||||
}
|
||||
|
||||
function unmount_and_export_fs {
|
||||
@@ -750,8 +750,10 @@ chroot_execute "echo options zfs zfs_arc_max=$((v_zfs_arc_max_mb * 1024 * 1024))
|
||||
|
||||
echo "======= setting up grub =========="
|
||||
chroot_execute "echo 'grub-pc grub-pc/install_devices_empty boolean true' | debconf-set-selections"
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes grub-pc"
|
||||
chroot_execute "grub-install ${v_selected_disks[0]}"
|
||||
chroot_execute "apt install --yes grub-pc"
|
||||
for disk in ${v_selected_disks[@]}; do
|
||||
chroot_execute "grub-install $disk"
|
||||
done
|
||||
|
||||
chroot_execute "sed -i 's/#GRUB_TERMINAL=console/GRUB_TERMINAL=console/g' /etc/default/grub"
|
||||
chroot_execute "sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT=\"net.ifnames=0\"|' /etc/default/grub"
|
||||
|
||||
@@ -400,7 +400,7 @@ function determine_kernel_variant {
|
||||
}
|
||||
|
||||
function chroot_execute {
|
||||
chroot $c_zfs_mount_dir bash -c "$1"
|
||||
chroot $c_zfs_mount_dir bash -c "DEBIAN_FRONTEND=noninteractive $1"
|
||||
}
|
||||
|
||||
function unmount_and_export_fs {
|
||||
@@ -754,9 +754,11 @@ chroot_execute "echo options zfs zfs_arc_max=$((v_zfs_arc_max_mb * 1024 * 1024))
|
||||
|
||||
echo "======= setting up grub =========="
|
||||
chroot_execute "echo 'grub-pc grub-pc/install_devices_empty boolean true' | debconf-set-selections"
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes grub-legacy"
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes grub-pc"
|
||||
chroot_execute "grub-install --recheck ${v_selected_disks[0]}"
|
||||
chroot_execute "apt install --yes grub-legacy"
|
||||
chroot_execute "apt install --yes grub-pc"
|
||||
for disk in ${v_selected_disks[@]}; do
|
||||
chroot_execute "grub-install --recheck $disk"
|
||||
done
|
||||
|
||||
chroot_execute "sed -i 's/#GRUB_TERMINAL=console/GRUB_TERMINAL=console/g' /etc/default/grub"
|
||||
chroot_execute "sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT=\"net.ifnames=0\"|' /etc/default/grub"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
: <<'end_header_info'
|
||||
(c) Andrey Prokopenko job@terem.fr
|
||||
fully automatic script to install Debian 11 with ZFS root on Hetzner VPS
|
||||
fully automatic script to install Debian 12 with ZFS root on Hetzner VPS
|
||||
WARNING: all data on the disk will be destroyed
|
||||
How to use: add SSH key to the rescue console, set it OS to linux64, then press "mount rescue and power cycle" button
|
||||
Next, connect via SSH to console, and run the script
|
||||
@@ -49,6 +49,7 @@ c_log_dir=$(dirname "$(mktemp)")/zfs-hetzner-vm
|
||||
c_install_log=$c_log_dir/install.log
|
||||
c_lsb_release_log=$c_log_dir/lsb_release.log
|
||||
c_disks_log=$c_log_dir/disks.log
|
||||
c_efimode_enabled="$(if [[ -d /sys/firmware/efi/efivars ]]; then echo 1; else echo 0; fi)"
|
||||
|
||||
function activate_debug {
|
||||
mkdir -p "$c_log_dir"
|
||||
@@ -107,7 +108,7 @@ function display_intro_banner {
|
||||
print_step_info_header
|
||||
|
||||
local dialog_message='Hello!
|
||||
This script will prepare the ZFS pools, then install and configure minimal Debian 11 with ZFS root on Hetzner hosting VPS instance
|
||||
This script will prepare the ZFS pools, then install and configure minimal Debian 12 with ZFS root on Hetzner hosting VPS instance
|
||||
The script with minimal changes may be used on any other hosting provider supporting KVM virtualization and offering Debian-based rescue system.
|
||||
In order to stop the procedure, hit Esc twice during dialogs (excluding yes/no ones), or Ctrl+C while any operation is running.
|
||||
'
|
||||
@@ -400,7 +401,7 @@ function determine_kernel_variant {
|
||||
}
|
||||
|
||||
function chroot_execute {
|
||||
chroot $c_zfs_mount_dir bash -c "$1"
|
||||
chroot $c_zfs_mount_dir bash -c "DEBIAN_FRONTEND=noninteractive $1"
|
||||
}
|
||||
|
||||
function unmount_and_export_fs {
|
||||
@@ -522,7 +523,11 @@ echo "======= partitioning the disk =========="
|
||||
|
||||
for selected_disk in "${v_selected_disks[@]}"; do
|
||||
wipefs --all --force "$selected_disk"
|
||||
sgdisk -a1 -n1:24K:+1000K -t1:EF02 "$selected_disk"
|
||||
if (( c_efimode_enabled == 1 )); then
|
||||
sgdisk -a1 -n1:24K:+1G -t1:EF00 "$selected_disk" # EFI partition
|
||||
else
|
||||
sgdisk -a1 -n1:24K:+1000K -t1:EF02 "$selected_disk"
|
||||
fi
|
||||
sgdisk -n2:0:+2G -t2:BF01 "$selected_disk" # Boot pool
|
||||
sgdisk -n3:0:"$tail_space_parameter" -t3:BF01 "$selected_disk" # Root pool
|
||||
done
|
||||
@@ -553,8 +558,8 @@ echo "======= create zfs pools and datasets =========="
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
zpool create \
|
||||
$v_bpool_tweaks -O canmount=off -O devices=off \
|
||||
-o cachefile=/etc/zpool.cache \
|
||||
-o compatibility=grub2 \
|
||||
-O mountpoint=/boot -R $c_zfs_mount_dir -f \
|
||||
$v_bpool_name $pools_mirror_option "${bpool_disks_partitions[@]}"
|
||||
|
||||
@@ -606,6 +611,16 @@ if [[ $v_swap_size -gt 0 ]]; then
|
||||
mkswap -f "/dev/zvol/$v_rpool_name/swap"
|
||||
fi
|
||||
|
||||
if (( c_efimode_enabled == 1 )); then
|
||||
echo "======= create filesystem on EFI partition(s) =========="
|
||||
|
||||
for selected_disk in "${v_selected_disks[@]}"; do
|
||||
mkfs.fat -F32 "${selected_disk}-part1"
|
||||
done
|
||||
mkdir -p "$c_zfs_mount_dir/boot/efi"
|
||||
mount "${v_selected_disks[0]}-part1" "$c_zfs_mount_dir/boot/efi"
|
||||
fi
|
||||
|
||||
echo "======= setting up initial system packages =========="
|
||||
debootstrap --arch=amd64 bookworm "$c_zfs_mount_dir" "$c_deb_packages_repo"
|
||||
|
||||
@@ -694,7 +709,6 @@ console-setup console-setup/fontsize-text47 select 8x16
|
||||
console-setup console-setup/codesetcode string Lat15
|
||||
tzdata tzdata/Areas select Europe
|
||||
tzdata tzdata/Zones/Europe select Vienna
|
||||
grub-pc grub-pc/install_devices_empty boolean true
|
||||
CONF'
|
||||
|
||||
chroot_execute "dpkg-reconfigure locales -f noninteractive"
|
||||
@@ -752,10 +766,22 @@ 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"
|
||||
|
||||
echo "======= setting up grub =========="
|
||||
chroot_execute "echo 'grub-pc grub-pc/install_devices_empty boolean true' | debconf-set-selections"
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes grub-legacy"
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes grub-pc"
|
||||
chroot_execute "grub-install --recheck ${v_selected_disks[0]}"
|
||||
if (( c_efimode_enabled == 1 )); then
|
||||
chroot_execute "apt install --yes grub-efi-amd64"
|
||||
else
|
||||
chroot_execute "echo 'grub-pc grub-pc/install_devices_empty boolean true' | debconf-set-selections"
|
||||
chroot_execute "apt install --yes grub-legacy"
|
||||
chroot_execute "apt install --yes grub-pc"
|
||||
fi
|
||||
|
||||
if (( c_efimode_enabled == 1 )); then
|
||||
#chroot_execute grub-probe /boot
|
||||
chroot_execute grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian --recheck
|
||||
else
|
||||
for disk in ${v_selected_disks[@]}; do
|
||||
chroot_execute "grub-install --recheck $disk"
|
||||
done
|
||||
fi
|
||||
|
||||
chroot_execute "sed -i 's/#GRUB_TERMINAL=console/GRUB_TERMINAL=console/g' /etc/default/grub"
|
||||
chroot_execute "sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT=\"net.ifnames=0\"|' /etc/default/grub"
|
||||
@@ -853,6 +879,10 @@ else
|
||||
fi
|
||||
|
||||
echo "======= setting mountpoints =========="
|
||||
if (( c_efimode_enabled == 1 )); then
|
||||
umount "$c_zfs_mount_dir/boot/efi"
|
||||
fi
|
||||
|
||||
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-mount.service,x-systemd.device-timeout=10 0 0 > /etc/fstab"
|
||||
|
||||
|
||||
@@ -366,7 +366,7 @@ function determine_kernel_variant {
|
||||
}
|
||||
|
||||
function chroot_execute {
|
||||
chroot $c_zfs_mount_dir bash -c "$1"
|
||||
chroot $c_zfs_mount_dir bash -c "DEBIAN_FRONTEND=noninteractive $1"
|
||||
}
|
||||
|
||||
function unmount_and_export_fs {
|
||||
@@ -685,10 +685,10 @@ chroot_execute "rm -f /etc/localtime /etc/timezone"
|
||||
chroot_execute "dpkg-reconfigure tzdata -f noninteractive "
|
||||
|
||||
echo "======= installing latest kernel============="
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes linux-headers${v_kernel_variant}-hwe-18.04 linux-image${v_kernel_variant}-hwe-18.04"
|
||||
chroot_execute "apt install --yes linux-headers${v_kernel_variant}-hwe-18.04 linux-image${v_kernel_variant}-hwe-18.04"
|
||||
if [[ $v_kernel_variant == "-virtual" ]]; then
|
||||
# linux-image-extra is only available for virtual hosts
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes linux-image-extra-virtual-hwe-18.04"
|
||||
chroot_execute "apt install --yes linux-image-extra-virtual-hwe-18.04"
|
||||
fi
|
||||
|
||||
echo "======= installing aux packages =========="
|
||||
@@ -736,8 +736,10 @@ chroot_execute "echo options zfs zfs_arc_max=$((v_zfs_arc_max_mb * 1024 * 1024))
|
||||
|
||||
echo "======= setting up grub =========="
|
||||
chroot_execute "echo 'grub-pc grub-pc/install_devices_empty boolean true' | debconf-set-selections"
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes grub-pc"
|
||||
chroot_execute "grub-install ${v_selected_disks[0]}"
|
||||
chroot_execute "apt install --yes grub-pc"
|
||||
for disk in ${v_selected_disks[@]}; do
|
||||
chroot_execute "grub-install $disk"
|
||||
done
|
||||
|
||||
chroot_execute "sed -i 's/#GRUB_TERMINAL=console/GRUB_TERMINAL=console/g' /etc/default/grub"
|
||||
chroot_execute "sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT=\"net.ifnames=0\"|' /etc/default/grub"
|
||||
|
||||
@@ -366,7 +366,7 @@ function determine_kernel_variant {
|
||||
}
|
||||
|
||||
function chroot_execute {
|
||||
chroot $c_zfs_mount_dir bash -c "$1"
|
||||
chroot $c_zfs_mount_dir bash -c "DEBIAN_FRONTEND=noninteractive $1"
|
||||
}
|
||||
|
||||
function unmount_and_export_fs {
|
||||
@@ -685,10 +685,10 @@ chroot_execute "rm -f /etc/localtime /etc/timezone"
|
||||
chroot_execute "dpkg-reconfigure tzdata -f noninteractive "
|
||||
|
||||
echo "======= installing latest kernel============="
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes linux-headers${v_kernel_variant} linux-image${v_kernel_variant}"
|
||||
chroot_execute "apt install --yes linux-headers${v_kernel_variant} linux-image${v_kernel_variant}"
|
||||
if [[ $v_kernel_variant == "-virtual" ]]; then
|
||||
# linux-image-extra is only available for virtual hosts
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes linux-image-extra-virtual"
|
||||
chroot_execute "apt install --yes linux-image-extra-virtual"
|
||||
fi
|
||||
|
||||
|
||||
@@ -737,8 +737,10 @@ chroot_execute "echo options zfs zfs_arc_max=$((v_zfs_arc_max_mb * 1024 * 1024))
|
||||
|
||||
echo "======= setting up grub =========="
|
||||
chroot_execute "echo 'grub-pc grub-pc/install_devices_empty boolean true' | debconf-set-selections"
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes grub-pc"
|
||||
chroot_execute "grub-install ${v_selected_disks[0]}"
|
||||
chroot_execute "apt install --yes grub-pc"
|
||||
for disk in ${v_selected_disks[@]}; do
|
||||
chroot_execute "grub-install $disk"
|
||||
done
|
||||
|
||||
chroot_execute "sed -i 's/#GRUB_TERMINAL=console/GRUB_TERMINAL=console/g' /etc/default/grub"
|
||||
chroot_execute "sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT=\"net.ifnames=0\"|' /etc/default/grub"
|
||||
|
||||
@@ -366,7 +366,7 @@ function determine_kernel_variant {
|
||||
}
|
||||
|
||||
function chroot_execute {
|
||||
chroot $c_zfs_mount_dir bash -c "$1"
|
||||
chroot $c_zfs_mount_dir bash -c "DEBIAN_FRONTEND=noninteractive $1"
|
||||
}
|
||||
|
||||
function unmount_and_export_fs {
|
||||
@@ -685,10 +685,10 @@ chroot_execute "rm -f /etc/localtime /etc/timezone"
|
||||
chroot_execute "dpkg-reconfigure tzdata -f noninteractive "
|
||||
|
||||
echo "======= installing latest kernel============="
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes linux-headers${v_kernel_variant} linux-image${v_kernel_variant}"
|
||||
chroot_execute "apt install --yes linux-headers${v_kernel_variant} linux-image${v_kernel_variant}"
|
||||
if [[ $v_kernel_variant == "-virtual" ]]; then
|
||||
# linux-image-extra is only available for virtual hosts
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes linux-image-extra-virtual"
|
||||
chroot_execute "apt install --yes linux-image-extra-virtual"
|
||||
fi
|
||||
|
||||
|
||||
@@ -737,8 +737,10 @@ chroot_execute "echo options zfs zfs_arc_max=$((v_zfs_arc_max_mb * 1024 * 1024))
|
||||
|
||||
echo "======= setting up grub =========="
|
||||
chroot_execute "echo 'grub-pc grub-pc/install_devices_empty boolean true' | debconf-set-selections"
|
||||
chroot_execute "DEBIAN_FRONTEND=noninteractive apt install --yes grub-pc"
|
||||
chroot_execute "grub-install ${v_selected_disks[0]}"
|
||||
chroot_execute "apt install --yes grub-pc"
|
||||
for disk in ${v_selected_disks[@]}; do
|
||||
chroot_execute "grub-install $disk"
|
||||
done
|
||||
|
||||
chroot_execute "sed -i 's/#GRUB_TERMINAL=console/GRUB_TERMINAL=console/g' /etc/default/grub"
|
||||
chroot_execute "sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT=\"net.ifnames=0\"|' /etc/default/grub"
|
||||
|
||||
Reference in New Issue
Block a user