Перейти к основному содержимому
Категории ai career dao links media notes philosophy security systems web
  1. Гисты/

ugly hacky script to rebuild all dkms modules plus manually force zfs if it's intree for debian/ubuntu

·570 слов·3 минут· ·
Оглавление

ugly hacky script to rebuild all dkms modules plus manually force zfs if it’s intree for debian/ubuntu

reinstall-dkms-modules-pluszfs.sh
#

#!/usr/bin/env bash
# rebuild/reinstall all dkms modules.
# double check there's no others missing too afterwards.

#template(){
#KVER=x.x.x-arch
#ZVER=x.x.x.x-x
#dkms status | sed s/,//g | awk '{print "--force -m",$1,"-v",$2}' | while read line; do ls /var/lib/initramfs-tools | xargs -n 1 dkms build --force $line -k; done
#dkms status | sed s/,//g | awk '{print "--force -m",$1,"-v",$2}' | while read line; do ls /var/lib/initramfs-tools | xargs -n 1 dkms install --force $line -k; done
#dkms build --force -m spl -v $ZVER -k $KVER
#dkms build --force -m zfs -v $ZVER -k $KVER
#dkms install --force -m spl -v $ZVER -k $KVER
#dkms install --force -m zfs -v $ZVER -k $KVER
#}

if [[ "$(id -u)" -ne 0 ]]; then
    echo "Must run this script as root, or with sudo."
    exit 1
fi

echo "Listing all dkms modules currently registered"
echo "Save this list to compare to the results afterwards"
echo "$(dkms status)"
sleep "5"

echo "Uninstalling all DKMS modules"
sleep "1"
dkms status | sed s/,//g | awk '{print "--force -m",$1,"-v",$2}' | \
        while read line; do ls /var/lib/initramfs-tools | \
        xargs -n 1 dkms uninstall $line -k; done

echo "Rebuilding all DKS modules"
sleep "1"
dkms status | sed s/,//g | awk '{print "--force -m",$1,"-v",$2}' | \
        while read line; do ls /var/lib/initramfs-tools | \
        xargs -n 1 dkms build $line -k; done

echo "DKMS Modules built, now installing"
sleep "1"
dkms status | sed s/,//g | awk '{print "--force -m",$1,"-v",$2}' | \
        while read line; do ls /var/lib/initramfs-tools | \
        xargs -n 1 dkms install --force $line -k; done

# sometimes dkms is stubborn and unregisters zfs completely from dkms
# so, i just quickly whipped this up since I got tired of reinstalling it manually
# It's ugly and not well tested but seems to work. 
# could be shorter and more efficient though.

# get ARCH
if [ ! -z "$(getconf LONG_BIT)" ]; then
        ARCH="amd64"
elif [ ! -z "$(uname -r | grep pae)" ]; then
        ARCH="686-pae"
elif [ -z "$ARCH" ]; then
        ARCH="686"
else
    echo "[ERROR] Can't find your ARCH"
    exit 1
fi
# get the list of kernels we need to install zfs/spl. Yeah there's better ways of doing this, I know.
# this was scripted quickly to support more use cases where multiple source trees exist.
KVER="$(ls /usr/src/ | grep "linux-headers" | sed s/-common//g | sed s/linux-headers-//g | grep "$ARCH")"
# get the zfs version, the head -n1 is in case for some strange reason there is more than one else you're SOL
ZVER="$(ls /usr/src/ | grep zfs | sed s/zfs-//g | head -n1)"

# force build spl and zfs
for splb in $KVER; do
    dkms build --force -m spl -v "${ZVER}" -k $splb;
done
for zfsb in $KVER; do
    dkms build --force -m spl -v "${ZVER}" -k $zfsb;
done
# force install spl and zfs
for spli in $KVER; do
    dkms install --force -m spl -v "${ZVER}" -k $spli;
done
for zfsi in $KVER; do
    dkms install --force -m zfs -v "${ZVER}" -k $zfsi;
done

echo "Listing all dkms modules currently registered after rebuild"
echo "Compare them with the first list and If any are missing, they probably need manual re-installation."
echo "Read the commented template section of this script to get a rough idea of how it works"
echo "$(dkms status)"

exit 0