Created
February 24, 2022 18:28
-
-
Save AlexRogalskiy/3151ad1f41735ed9937ec9214634e1f7 to your computer and use it in GitHub Desktop.
install native zfs on linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# ---- may change frequently - start | |
version="0.6.0-rc8" | |
spl_tar_sha1=a3bba691e5b3b680f4cbeac70f7ea29367e6f337 | |
zfs_tar_sha1=90597083069e17cc066fa435974bcdcabebad44d | |
# ---- may change frequently - end | |
spl_version_name="spl-$version" | |
zfs_version_name="zfs-$version" | |
spl_dir="$spl_version_name" | |
zfs_dir="$zfs_version_name" | |
usage() { | |
echo "Usage: $0 build|install|check|uninstall [--dev] [--dracut]" >&2 | |
exit 1 | |
} | |
has() { | |
which $1 >/dev/null 2>&1 | |
} | |
qgrep() { | |
grep "${@}" >/dev/null 2>&1 | |
} | |
download_file() { | |
if has curl | |
then | |
curl -sL "${1}/${2}" | tee "${2}" | sha1sum | qgrep "${3}" | |
elif has wget | |
then | |
wget -qO- "${1}/${2}" | tee "${2}" | sha1sum | qgrep "${3}" | |
else | |
echo "Cannot download $1/$2, wget and curl missing." >&2 | |
exit 1 | |
fi | |
tar xf "${2}" | |
} | |
download() { | |
echo Downloading spl | |
download_file http://github.com/downloads/zfsonlinux/spl $spl_version_name.tar.gz $spl_tar_sha1 | |
echo Downloading zfs | |
download_file http://github.com/downloads/zfsonlinux/zfs $zfs_version_name.tar.gz $zfs_tar_sha1 | |
} | |
build_dep_rpm() { | |
sudo yum groupinstall -y "Development Tools" >"$log_file" 2>&1 | |
sudo yum install -y zlib-devel libuuid-devel libblkid-devel libselinux-devel parted lsscsi mdadm bc >>"$log_file" 2>&1 | |
} | |
build_dep_deb() { | |
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential gawk alien fakeroot linux-headers-$(uname -r) zlib1g-dev uuid-dev libblkid-dev libselinux-dev parted lsscsi mdadm bc >>"$log_file" 2>&1 | |
} | |
build_pkg() { | |
pushd $1 >/dev/null | |
echo Configuring $1 | |
./configure >>"$log_file" 2>&1 | |
echo Building $1 | |
make $2 >>"$log_file" 2>&1 | |
popd >/dev/null | |
} | |
install_rpms() { | |
echo Installing rpms ${@} | |
sudo rpm -Uvh "${@}" >>"$log_file" 2>&1 | |
} | |
uninstall_rpms() { | |
echo Uninstalling rpms ${@} | |
sudo rpm -e "${@}" >>"$log_file" 2>&1 | |
} | |
install_debs() { | |
echo Installing debs ${@} | |
sudo DEBIAN_FRONTEND=noninteractive dpkg -i ${@} >>"$log_file" 2>&1 | |
} | |
uninstall_debs() { | |
echo Uninstalling debs ${@} | |
sudo DEBIAN_FRONTEND=noninteractive dpkg -P ${@} >>"$log_file" 2>&1 | |
} | |
build() { | |
if has yum | |
then | |
build_dep_rpm | |
build_pkg $spl_dir rpm | |
cp $spl_dir/*.rpm "`dirname $log_file`" | |
install_rpms $spl_dir/spl-modules-devel_*.rpm | |
build_pkg $zfs_dir rpm | |
cp $zfs_dir/*.rpm "`dirname $log_file`" | |
uninstall_rpms spl-modules-devel | |
elif has dpkg | |
then | |
build_dep_deb | |
build_pkg $spl_dir deb | |
cp $spl_dir/*.deb "`dirname $log_file`" | |
install_debs $spl_dir/spl-modules-devel_*.deb | |
build_pkg $zfs_dir deb | |
cp $zfs_dir/*.deb "`dirname $log_file`" | |
uninstall_debs spl-modules-devel | |
else | |
echo "I dont know how to build zfs on this platform." >&2 | |
exit 1 | |
fi | |
popd >/dev/null | |
} | |
zfs_installed() { | |
has zpool | |
} | |
install() { | |
if zfs_installed | |
then | |
echo "error: zfs already installed" >&2 | |
exit 1 | |
fi | |
if has yum | |
then | |
install_rpms $zfs_dir/zfs_*.rpm $zfs_dir/zfs-modules_*.rpm $spl_dir/spl-modules_*.rpm $spl_dir/spl_*.rpm | |
[ -n "$dracut" ] && install_rpms $zfs_dir/zfs-dracut_*.rpm | |
elif has dpkg | |
then | |
install_debs $zfs_dir/zfs_*.deb $zfs_dir/zfs-modules_*.deb $spl_dir/spl-modules_*.deb $spl_dir/spl_*.deb | |
[ -n "$dracut" ] && install_debs $zfs_dir/zfs-dracut_*.deb | |
fi | |
} | |
uninstall_dev_pkgs() { | |
if has yum | |
then | |
uninstall_rpms zfs-test zfs-devel zfs-modules-devel spl-devel | |
elif has dpkg | |
then | |
uninstall_debs zfs-test zfs-devel zfs-modules-devel spl-devel | |
fi | |
} | |
check() { | |
if has yum | |
then | |
install_rpms $spl_dir/*devel*.rpm $zfs_dir/*devel*.rpm $zfs_dir/zfs-test*.rpm | |
elif has dpkg | |
then | |
install_debs $spl_dir/*devel*.deb $zfs_dir/*devel*.deb $zfs_dir/zfs-test*.rpm | |
fi | |
sudo /sbin/modprobe splat | |
sudo /usr/sbin/splat -a | |
sudo /sbin/rmmod splat | |
[ -z "$dev" ] && uninstall_dev_pkgs | |
} | |
uninstall() { | |
if ! zfs_installed | |
then | |
echo "zfs is not installed" >&2 | |
exit 1 | |
fi | |
if ! zpool list 2>&1 | qgrep 'no pools available' | |
then | |
echo "cannot uninstall zfs when a pool is online." >&2 | |
exit 1 | |
fi | |
/sbin/lsmod | qgrep zfs || sudo /sbin/rmmod zfs | |
/sbin/lsmod | qgrep spl || sudo /sbin/rmmod spl | |
uninstall_dev_pkgs | |
if has yum | |
then | |
uninstall_rpms zfs zfs-modules spl-modules spl | |
elif has dpkg | |
then | |
uninstall_debs zfs zfs-modules spl-modules spl | |
fi | |
} | |
exit_handler() { | |
cd | |
\rm -rf /tmp/zfs-build-root* | |
\rm -rf /tmp/spl-build-root* | |
\rm -rf /tmp/zfsbuild.$$ | |
uninstall_dev_pkgs | |
exit $1 | |
} | |
while [ ${#} -gt 0 ] | |
do | |
case "$1" in | |
uninstall) uninstall || exit 1 ; exit 0 ;; | |
download|build|install|check) command="$1" ;; | |
--dev) dev=1 ;; | |
--dracut) dracut=1 ;; | |
*) usage ;; | |
esac | |
shift | |
done | |
test -z "$command" && usage | |
log_file="`pwd`/install_zfs.log" | |
test -e "$log_file" && rm -f "$log_file" | |
trap 'exit_handler $1 >/dev/null 2>&1' EXIT ERR QUIT TERM | |
mkdir /tmp/zfsbuild.$$ | |
pushd /tmp/zfsbuild.$$ >/dev/null | |
download | |
build ; [ x"$command" = x'build' ] && exit 0 | |
install ; [ x"$command" = x'install' ] && exit 0 | |
check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment