mirror of
https://github.com/bashclub/proxmox-zfs-postinstall.git
synced 2025-08-03 14:05:00 +02:00
Mutliple fixexs and enhancements
This commit is contained in:
48
README.md
48
README.md
@@ -1,24 +1,44 @@
|
|||||||
# proxmox-zfs-postinstall
|
# proxmox-zfs-postinstall
|
||||||
|
|
||||||
This script installs and configures basic tools for running a new Proxmox Server (Version 8+).
|
This script installs and configures essential and advanced tools for a new Proxmox Server (Version 8+), with ZFS storage. All settings are made interactively via Dialog/Whiptail.
|
||||||
Following settings are made:
|
|
||||||
- Install and configure zfs-auto-snapshot
|
> [!IMPORTANT]
|
||||||
- Switch pve-enterprise/pve-no-subscription/pvetest repo
|
> Please download the updated version of this script and re-run, if your Proxmox WebUI doesn't show up after update to 8.4.5 or 9.0.0 beta
|
||||||
- Switch ceph repo between quincy/reef and enterprise/no-subscription/test or remove it
|
|
||||||
- Disable "No subscription message" in webinterface in no-subscription mode
|
## Features
|
||||||
- Add pve-enterprise subscription key
|
- Configure ZFS ARC Cache (optimizes RAM usage for ZFS)
|
||||||
|
- Configure vm.swappiness (kernel swap behavior)
|
||||||
|
- Install and configure zfs-auto-snapshot (automatic ZFS snapshots, individually configurable)
|
||||||
|
- Switch between pve-enterprise, pve-no-subscription, pvetest repositories
|
||||||
|
- Switch Ceph repo between quincy/reef and enterprise/no-subscription/test or remove it
|
||||||
|
- Disable "No subscription message" in web interface (for no-subscription)
|
||||||
|
- Add pve-enterprise subscription key (optional)
|
||||||
- Update system to the latest version
|
- Update system to the latest version
|
||||||
- Install common tools
|
- Install common tools (curl, git, htop, etc.)
|
||||||
- Install Proxmox SDN Extensions
|
- Install Proxmox SDN Extensions
|
||||||
- Configure automatic backup of /etc Folder
|
- Configure automatic backup of /etc folder (ZFS + cron)
|
||||||
- Configure locales
|
- Configure locales (language and region settings)
|
||||||
- SSH server hardening
|
- SSH server hardening (new host keys, restrictive algorithms, disable root login with password)
|
||||||
- Install checkzfs
|
- Install checkzfs
|
||||||
- Install bashclub-zsync
|
- Install bashclub-zsync
|
||||||
- Install virtio-win ISO
|
- Install virtio-win ISO (including automatic cleanup of old versions)
|
||||||
- Create zfspool storage for swap disks if not exists
|
- Create zfspool storage for swap disks if not exists
|
||||||
- Adjust default volblocksize for Proxmox zfspool storage
|
- Adjust default volblocksize for Proxmox zfspool storages
|
||||||
- Configure proxmox mail delivery proxmox notifications (pve8)
|
- Configure Proxmox mail delivery and notifications (SMTP, Auth, TLS/StartTLS)
|
||||||
|
- Remove old virtio-win-updater
|
||||||
|
- Set content of proxmox storage "local" (remove ability to save backups)
|
||||||
|
- Enable autotrim on all supported ZFS pools
|
||||||
|
- Enable autoexpand on all ZFS pools
|
||||||
|
|
||||||
|
## Workflow
|
||||||
|
- The script guides you step by step through all important configurations.
|
||||||
|
- All settings are queried interactively and can be customized.
|
||||||
|
- After the summary, all selected options are automatically applied.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
- Proxmox VE 8.x (tested with Bookworm)
|
||||||
|
- Root privileges required
|
||||||
|
- Internet connection for package installation
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
|
104
postinstall
104
postinstall
@@ -24,7 +24,7 @@
|
|||||||
# + Daily check (and download) for new stable virtio-win iso and prune old (unused) versions
|
# + Daily check (and download) for new stable virtio-win iso and prune old (unused) versions
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Author: (C) 2023 Thorsten Spille <thorsten@bashclub.org>
|
# Author: (C) 2025 Thorsten Spille <thorsten@bashclub.org>
|
||||||
|
|
||||||
set -uo pipefail
|
set -uo pipefail
|
||||||
|
|
||||||
@@ -75,6 +75,13 @@ sub_status=$(pvesubscription get | grep status | cut -d' ' -f2)
|
|||||||
# get notification address
|
# get notification address
|
||||||
recipientaddress=$(pvesh get access/users/root@pam --output-format yaml| grep email | cut -d' ' -f2)
|
recipientaddress=$(pvesh get access/users/root@pam --output-format yaml| grep email | cut -d' ' -f2)
|
||||||
|
|
||||||
|
# Default content for local storage
|
||||||
|
content="vztmpl,import,iso"
|
||||||
|
|
||||||
|
ask_local_content(){
|
||||||
|
if ! content=$(whiptail --title "SET LOCAL STORAGE CONTENT" --backtitle "$PROG" --inputbox "Please enter the content types for local storage (comma separated, allowed values: images,rootdir,vztmpl,backup,iso,import,snippets):" 9 76 "$content" 3>&1 1>&2 2>&3); then cancel_dialog ; fi
|
||||||
|
}
|
||||||
|
|
||||||
#### FUNCTIONS ####
|
#### FUNCTIONS ####
|
||||||
|
|
||||||
log(){
|
log(){
|
||||||
@@ -201,8 +208,8 @@ select_subscription(){
|
|||||||
if whiptail --title "NO PROXMOX SUBSCRIPTION FOUND" \
|
if whiptail --title "NO PROXMOX SUBSCRIPTION FOUND" \
|
||||||
--backtitle $PROG \
|
--backtitle $PROG \
|
||||||
--yes-button "SUPPRESS WARNING" \
|
--yes-button "SUPPRESS WARNING" \
|
||||||
--no-button "SKIP" \
|
--no-button "REMOVE HACK" \
|
||||||
--yesno "Do you want to suppress the no subscription warning in WebGUI?" 9 76 ; then
|
--yesno "Do you want to suppress the no subscription warning in WebUI?" 9 76 ; then
|
||||||
suppress_warning=1
|
suppress_warning=1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -249,18 +256,46 @@ set_subscription(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
suppress_no_subscription_warning(){
|
suppress_no_subscription_warning(){
|
||||||
|
# remove old no-sub-hack
|
||||||
|
if [ -f /opt/bashclub/no-sub-hack.sh ] ; then rm -r /opt/bashclub ; fi
|
||||||
|
if [ -f /etc/apt/apt.conf.d/80bashclubapthook ] ; then rm /etc/apt/apt.conf.d/80bashclubapthook ; fi
|
||||||
if [ $suppress_warning -gt 0 ]; then
|
if [ $suppress_warning -gt 0 ]; then
|
||||||
# remove old no-sub-hack
|
cat << EOF > /usr/local/bin/suppress_no_subscription_warning
|
||||||
if [ -f /opt/bashclub/no-sub-hack.sh ] ; then rm -r /opt/bashclub ; fi
|
#!/bin/bash
|
||||||
if [ -f /etc/apt/apt.conf.d/80bashclubapthook ] ; then rm /etc/apt/apt.conf.d/80bashclubapthook ; fi
|
# Proxmox no-subsscription hack
|
||||||
|
|
||||||
wget -q --no-cache -O /usr/local/bin/suppress_no_subscription_warning https://github.com/bashclub/no-sub-hack/raw/main/no-sub-hack.sh
|
filename=/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
|
||||||
|
|
||||||
|
# Finde die erste Zeile mit checked_command
|
||||||
|
first_line=\$(grep -n -m1 'checked_command' "\$filename" | cut -d':' -f1)
|
||||||
|
# Hole die Einrückung der Startzeile
|
||||||
|
indent=\$(sed -n "\${first_line}p" "\$filename" | grep -o '^[[:space:]]*')
|
||||||
|
# Suche ab first_line die erste Zeile, die mit identischer Einrückung und '},' endet
|
||||||
|
last_line=\$(( \$(tail -n "+\${first_line}" "\$filename" | grep -nxm1 "^\${indent}},\$" | cut -d':' -f1) + first_line - 1 ))
|
||||||
|
|
||||||
|
# Entferne den Block
|
||||||
|
sed -i "\${first_line},\${last_line}d" "\$filename"
|
||||||
|
|
||||||
|
# Füge die neue checked_command-Funktion an der richtigen Stelle ein
|
||||||
|
insert_line=\$(( first_line - 1 ))
|
||||||
|
ex "\$filename" <<eof
|
||||||
|
\${insert_line} insert
|
||||||
|
\${indent}checked_command: function(orig_cmd) { orig_cmd(); },
|
||||||
|
.
|
||||||
|
xit
|
||||||
|
eof
|
||||||
|
EOF
|
||||||
chmod +x /usr/local/bin/suppress_no_subscription_warning
|
chmod +x /usr/local/bin/suppress_no_subscription_warning
|
||||||
/usr/local/bin/suppress_no_subscription_warning
|
|
||||||
cat << EOF > /etc/apt/apt.conf.d/80-suppress_no_subscription_warning
|
cat << EOF > /etc/apt/apt.conf.d/80-suppress_no_subscription_warning
|
||||||
DPkg::Post-Invoke {"/usr/local/bin/suppress_no_subscription_warning";};
|
DPkg::Post-Invoke {"/usr/local/bin/suppress_no_subscription_warning";};
|
||||||
EOF
|
EOF
|
||||||
|
/usr/local/bin/suppress_no_subscription_warning
|
||||||
|
else
|
||||||
|
if [ -f /usr/local/bin/suppress_no_subscription_warning ] ; then rm /usr/local/bin/suppress_no_subscription_warning ; fi
|
||||||
|
if [ -f /etc/apt/apt.conf.d/80-suppress_no_subscription_warning ] ; then rm /etc/apt/apt.conf.d/80-suppress_no_subscription_warning ; fi
|
||||||
fi
|
fi
|
||||||
|
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt install --reinstall -y -qq proxmox-widget-toolkit > /dev/null 2>&1
|
||||||
|
systemctl restart pveproxy.service
|
||||||
}
|
}
|
||||||
|
|
||||||
select_pve_repo(){
|
select_pve_repo(){
|
||||||
@@ -655,6 +690,21 @@ remove_virtiowin_updater() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_autotrim=0
|
||||||
|
set_autoexpand=0
|
||||||
|
|
||||||
|
ask_autotrim(){
|
||||||
|
if whiptail --title "ENABLE AUTOTRIM" --backtitle "$PROG" --yes-button "ENABLE" --no-button "SKIP" --yesno "Enable autotrim on all supported zpools?" 9 76 ; then
|
||||||
|
set_autotrim=1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ask_autoexpand(){
|
||||||
|
if whiptail --title "ENABLE AUTOEXPAND" --backtitle "$PROG" --yes-button "ENABLE" --no-button "SKIP" --yesno "Enable autoexpand on all zpools?" 9 76 ; then
|
||||||
|
set_autoexpand=1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
installation_task(){
|
installation_task(){
|
||||||
log "Starting Installation"
|
log "Starting Installation"
|
||||||
|
|
||||||
@@ -676,9 +726,26 @@ installation_task(){
|
|||||||
set_default_volblocksize
|
set_default_volblocksize
|
||||||
remove_virtiowin_updater
|
remove_virtiowin_updater
|
||||||
|
|
||||||
|
if [ $set_autotrim -gt 0 ]; then
|
||||||
|
log "Enabling autotrim on all supported zpools"
|
||||||
|
for p in $(zpool list -H -o name); do
|
||||||
|
if ! zpool status -t $p | grep -q "trim unsupported"; then
|
||||||
|
zpool set autotrim=on $p
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if [ $set_autoexpand -gt 0 ]; then
|
||||||
|
log "Enabling autoexpand on all zpools"
|
||||||
|
for p in $(zpool list -H -o name); do
|
||||||
|
zpool set autoexpand=on $p
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "Setting local storage content to: $content"
|
||||||
|
pvesm set local --content ${content}
|
||||||
|
|
||||||
log "Updating initramfs - This will take some time..."
|
log "Updating initramfs - This will take some time..."
|
||||||
update-initramfs -u -k all > /dev/null 2>&1
|
update-initramfs -u -k all > /dev/null 2>&1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
summary(){
|
summary(){
|
||||||
@@ -709,8 +776,16 @@ summary(){
|
|||||||
smarthost mode: $smtpmode
|
smarthost mode: $smtpmode
|
||||||
smarthost auth: $smtpauth
|
smarthost auth: $smtpauth
|
||||||
smarthost username: $username
|
smarthost username: $username
|
||||||
set blocksize: $setblocksize
|
set blocksize: $setblocksize\n\
|
||||||
volblocksize: $volblocksize
|
volblocksize: $volblocksize\n\
|
||||||
|
local storage content: $content\n\
|
||||||
|
ceph repository: $ceph_repo_selection\n\
|
||||||
|
bashclub repository: $bashclub_repo\n\
|
||||||
|
virtio-win iso: $install_virtio\n\
|
||||||
|
zsync: $install_zsync\n\
|
||||||
|
autotrim: $set_autotrim\n\
|
||||||
|
autoexpand: $set_autoexpand\n\
|
||||||
|
Do you want to continue?
|
||||||
" 30 76 ; then
|
" 30 76 ; then
|
||||||
installation_task
|
installation_task
|
||||||
else
|
else
|
||||||
@@ -753,6 +828,13 @@ ask_mail_config
|
|||||||
# set volblocksize
|
# set volblocksize
|
||||||
ask_volblocksize
|
ask_volblocksize
|
||||||
|
|
||||||
|
# ask for local storage content
|
||||||
|
ask_local_content
|
||||||
|
|
||||||
|
# ask for autotrim/autoexpand
|
||||||
|
ask_autotrim
|
||||||
|
ask_autoexpand
|
||||||
|
|
||||||
summary
|
summary
|
||||||
|
|
||||||
log "Proxmox postinstallation finished!"
|
log "Proxmox postinstallation finished!"
|
||||||
|
Reference in New Issue
Block a user