diff --git a/zfs-install-redhat-alma.sh b/zfs-install-redhat-alma.sh index ac1a7c0..61a6e3d 100644 --- a/zfs-install-redhat-alma.sh +++ b/zfs-install-redhat-alma.sh @@ -1,22 +1,65 @@ #!/bin/bash -# tested on alma linux 8.3 // centos replacement +# tested on alma linux 8.3 // centos / RHEL replacement -# xxx EDITME +# Args/parameters to pass: +# +# upgrade = Unmount zfs datasets, export all zfs pools, unload zfs module, recompile zfs, reload module (does not re-import pools) +# fixit = just recompile zfs module for running kernel and load module + +logfile=~/zfs-install-redhat-alma.log +mv -v $logfile $logfile-old +# blankit +> $logfile +chmod 750 $logfile + +# xxx TODO EDITME zver="2.0.4" +firstrun=1 +# if set to 1, will install prereq packages - set 0 to skip + +# logecho.mrg +# Echo something to current console AND log +# Can also handle piped input ( cmd |logecho ) +# Warning: Has trouble echoing '*' even when quoted. +function logecho () { + args=$@ + + if [ -z "$args" ]; then + args='placeholder' + + while [ 1 ]; do + read -e -t2 args + + if [ -n "$args" ]; then + echo "$args" |tee -a $logfile; + else + break; + fi + done + + else + echo "$args" |tee -a $logfile; + fi +} # END FUNC + if [ "$1" = "fixit" ]; then - echo "$(date) recompiling ZFS module for new/current kernel" + logecho "$(date) - Recompiling ZFS module for new/current kernel" + cd /usr/local/src/zfs-$zver time rpm --reinstall zfs-dkms*.rpm && modprobe zfs + dmesg |grep ZFS zpool version + logecho "o $(date) + Finished run = $0 $1" + exit; fi # failexit.mrg function failexit () { - echo '! Something failed! Code: '"$1 $2" # code # (and optional description) + logecho "$(date) - Something failed! Code: $1 $2" # code # (and optional description) exit $1 } @@ -25,66 +68,72 @@ if [ "$1" = "upgrade" ]; then systemctl stop smb # TODO also do nfs if you use that with zfs - echo "! Unmounting all ZFS datasets and exporting pools..." + logecho "! $(date) - Unmounting all ZFS datasets and exporting pools..." zfs umount -a -f zpool export -a -f - [ $(df -hT |grep -c zfs) -gt 0 ] && failexit 111 "ZFS pool/dataset found still mounted, lsof may come in handy" + [ $(df -hT |grep -c zfs) -gt 0 ] && failexit 111 "! $(date) - ZFS pool/dataset found still mounted, lsof may come in handy" # handy REF if you need fuser: https://vander.host/knowledgebase/operating-systems/how-to-deal-with-fuser-command-not-found-on-centos/ # yum install -y psmisc - echo "o Unloading ZFS modules..." + logecho "o $(date) - Unloading ZFS modules..." modprobe -rv zfs zunicode zzstd zlua zcommon znvpair zavl icp spl if [ $(lsmod |grep -c zfs) -gt 0 ]; then - echo "NOTE if you get error here, ' lsof |grep zfs ' and kill the process holding it, then retry" - failexit 302 "ZFS module(s) are still loaded!" + logecho "NOTE if you get error here, ' lsof |grep zfs ' and kill the process holding it, then retry" + failexit 302 "! ($date) - ZFS module(s) are still loaded!" fi yum remove -y zfs zfs-dkms* libnvpair* libuutil* libzfs* libzpool* python3-pyzfs zfs-debug* zfs-dracut zfs-test* \ --setopt=clean_requirements_on_remove=false \ - || failexit 999 "Failed to uninstall ZFS RPMs" + || failexit 999 "! $(date) - Failed to uninstall ZFS RPMs" # REF: https://access.redhat.com/solutions/5577491 # otherwise it removes ~128 packages and is a big PITA :b + + logecho "o $(date) - TODO NOTE upgrade was called, dont forget to restart services" fi -echo "o Installing prereq pkgs..." -yum install -y epel-release +if [ "$firstrun" -gt 0 ]; then + logecho "o $(date) + Installing prereq pkgs..." + yum install -y epel-release #yum install -y https://zfsonlinux.org/epel/zfs-release.el8_3.noarch.rpm #gpg --import --import-options show-only /etc/pki/rpm-gpg/RPM-GPG-KEY-zfsonlinux # REF: https://openzfs.github.io/openzfs-docs/Developer%20Resources/Custom%20Packages.html -yum install -y kernel-devel kernel-headers wget curl lsof -yum groupinstall -y "Development Tools" + yum install -y kernel-devel kernel-headers wget curl lsof + yum groupinstall -y "Development Tools" -dnf install -y gcc make autoconf automake libtool rpm-build kernel-rpm-macros dkms libtirpc-devel \ - libblkid-devel libuuid-devel libudev-devel openssl-devel zlib-devel libaio-devel libattr-devel \ - elfutils-libelf-devel kernel-devel-$(uname -r) python3 python3-devel python3-setuptools python3-cffi libffi-devel + dnf install -y gcc make autoconf automake libtool rpm-build kernel-rpm-macros dkms libtirpc-devel \ + libblkid-devel libuuid-devel libudev-devel openssl-devel zlib-devel libaio-devel libattr-devel \ + elfutils-libelf-devel kernel-devel-$(uname -r) python3 python3-devel python3-setuptools python3-cffi libffi-devel + +fi cd /usr/local/src -echo "o Downloading ZFS source code" +logecho "o $(date) + Downloading ZFS source code" wget --no-clobber https://github.com/openzfs/zfs/releases/download/zfs-$zver/zfs-$zver.tar.gz tar xzf zfs-$zver.tar.gz -cd zfs-$zver +cd zfs-$zver || failexit 404 "! $(date) - ZFS source code not found!" +logecho "o $(date) + Compiling ZFS" # REF: https://openzfs.github.io/openzfs-docs/Developer%20Resources/Custom%20Packages.html time ./configure time make -s -j4 rpm-utils rpm-dkms && \ mv -v *.src.rpm .. -echo "$(date) + Installing ZFS RPMs" +logecho "o $(date) + Installing ZFS RPMs" time yum localinstall -y *.$(uname -p).rpm *.noarch.rpm \ - || failexit 666 "Failed to install ZFS packages" + || failexit 666 "! $(date) - Failed to install ZFS packages" modprobe zfs dmesg |grep ZFS zpool version && \ - echo "o Now you should be able to issue ' zpool import '" + logecho "o $(date) + Now you should be able to issue ' zpool import '" -date +logecho "o $(date) + Finished run = $0 $1" -exit; +exit 0; # Download and install zfs from source code, load module # 2021 Dave Bechtel