Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compilation of ARCHZFS on ALARMPI1
#!/bin/bash
### This can be run as:
### bash -i -c "source <(curl -L 'https://gist.githubusercontent.com/tsjk/4b387dd685b9942bcc23497fd3345b99/raw')"
### This script aims to upgrade your kernel packages, and then install ArchZFS the kernel packages installed.
declare -g -i COMPILE_LOCALLY=0
[[ "${1}" != "--compile-locally" ]] || { COMPILE_LOCALLY=1; shift 1; }
[[ -z "${*}" ]] || exit 1
unalias mkpkg-distcc &> /dev/null
unalias mkpkg &> /dev/null
unalias pcmn-distcc &> /dev/null
unalias pcmn &> /dev/null
unalias __mkpkg &> /dev/null
unalias regen-initrd &> /dev/null
set -e -u
echo; echo "This is archzfs-alarmpi1-compile.sh revision 43."; echo
[[ -d ~/"cower" && -f "/etc/makepkg-distcc.conf" && -f "/etc/makepkg-local.conf" ]] || return 254
MKINITCPIO_TMP="/var/tmp"
[[ -d "${MKINITCPIO_TMP}" ]] || return 253
function distcc_hosts_ping() {
for i in $(grep -oP '^([0-9]+\.){3}[0-9]+:[0-9]+' /etc/distcc/hosts); do \
H_=$(echo "${i}" | awk -F ':' '{ print $1 }'); P_=$(echo "${i}" | awk -F ':' '{ print $2 }'); \
if ! ping -c 1 -W 1 "${H_}" &> /dev/null || ! nc -w 3 -z -v "${H_}" "${P_}" &> /dev/null; then return 1; fi; \
done; \
return 0; \
}
function mkpkg-distcc() { export MAKEPKG_CONF="/etc/makepkg-distcc.conf"; GNUPGHOME=/etc/pacman.d/gnupg ionice -c 2 -n 7 nice -19 makepkg "${@}" ;}
#function mkpkg-distcc() { export MAKEPKG_CONF="/etc/makepkg-distcc.conf"; export PATH="/usr/lib/distcc/bin:${PATH}"; GNUPGHOME=/etc/pacman.d/gnupg ionice -c 2 -n 7 nice -19 makepkg "${@}"; export PATH="${PATH#/usr/lib/distcc/bin:}" ;}
function mkpkg() { export MAKEPKG_CONF="/etc/makepkg-local.conf"; GNUPGHOME=/etc/pacman.d/gnupg ionice -c 2 -n 7 nice -19 makepkg "${@}" ;}
function pcmn-distcc() { export MAKEPKG_CONF="/etc/makepkg-distcc.conf"; GNUPGHOME=/etc/pacman.d/gnupg ionice -c 2 -n 7 nice -19 sudo pacman "${@}" ;}
function pcmn() { export MAKEPKG_CONF="/etc/makepkg-local.conf"; GNUPGHOME=/etc/pacman.d/gnupg ionice -c 2 -n 7 nice -19 sudo pacman "${@}" ;}
function __mkpkg() { [[ ${COMPILE_LOCALLY} -eq 0 ]] && mkpkg-distcc "${@}" || mkpkg "${@}" ;}
function regen-initrd() {
set +u; if [[ -n "${1}" ]]; then KERNEL_VERSION="${1}"; \
else KERNEL_VERSION="$(pacman -Qi linux-raspberrypi | grep -oP '(?<=^Version : )[0-9\.-]+$')-ARCH"; fi; set -u; \
[[ -d "/lib/modules/${KERNEL_VERSION}" ]] && \
( sudo rm -fv /boot/initramfs-linux.img; \
sudo mkinitcpio -k "${KERNEL_VERSION}" -c /etc/mkinitcpio.conf -g /boot/initramfs-linux.img -t "${MKINITCPIO_TMP}"; \
sudo cp -av /boot/initramfs-linux.img /boot/initramfs-linux.img-${KERNEL_VERSION}; \
sudo cp -av /boot/kernel.img /boot/kernel.img-${KERNEL_VERSION} ); \
}
[[ ${COMPILE_LOCALLY} -eq 1 ]] || distcc_hosts_ping || return 252
# Refresh pacman's database
eval pcmn -Syy
# Remove current ZFS installation to allow for kernel update and upgrade of ZFS packages, if any
eval $(eval pcmn -Q | egrep '(spl|zfs)' | awk -F ' ' '{ print $1 }' | xargs -r echo eval pcmn -R --noconfirm)
echo
# Check if kernel is to be upgraded
if pacman -Qu linux-raspberrypi; then
# Upgrade kernel packages
if [[ "$(findmnt -n -o FSTYPE '/tmp')" == "tmpfs" ]]; then
TMPFS_SIZE="$(df --output=size -h '/tmp' | tail -n 1 | sed -E 's@^\s*@@g;s@\s*$@@g')";
if [[ ${TMPFS_SIZE} -lt $[192*1024] ]]; then
sudo mount /tmp/ -o remount,defaults,noatime,rw,nosuid,nodev,size=192M,mode=1777,uid=0,gid=0; fi
fi
echo; eval pcmn -S --noconfirm linux-raspberrypi linux-raspberrypi-headers
sudo sed -i -E 's@^#default_options=.*$@default_options="-t '\'"${MKINITCPIO_TMP}"\''"@' /etc/mkinitcpio.d/linux-raspberrypi.preset;
if [[ "$(findmnt -n -o FSTYPE '/tmp')" == "tmpfs" ]]; then
if [[ ${TMPFS_SIZE} -lt $[192*1024] ]]; then
sudo mount /tmp/ -o remount,defaults,rw,noatime,nosuid,nodev,size=${TMPFS_SIZE},mode=1777,uid=0,gid=0; fi
fi
fi
# Install ArchZFS
LTS_KERNEL_VERSION=$(wget -qO- 'https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=zfs-linux-lts' | \
grep -oP '(?<=_kernelver=")[0-9\.-]+(?=")' | head -n 1 | sed -E 's@-[0-9]+$@@')
LTS_KERNEL_VERSION_ESCAPED=$(echo "${LTS_KERNEL_VERSION}" | sed 's@\.@\\\.@g')
LTS_KERNEL_REVISION=$(wget -qO- 'https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=zfs-linux-lts' | \
grep -oP '(?<=_extramodules=")[0-9\.-]+(?=-lts")' | grep -oP '(?<=-)[0-9]+(?=$)' | head -n 1)
echo "zfs-linux-lts: Originally for linux-lts-${LTS_KERNEL_VERSION}-${LTS_KERNEL_REVISION}."
RASPBERRYPI_KERNEL_VERSION=$(pacman -Qi linux-raspberrypi | egrep '^Version\s+' | grep -oP '[0-9\.]+(?=-)')
RASPBERRYPI_KERNEL_VERSION_ESCAPED=$(echo "${RASPBERRYPI_KERNEL_VERSION}" | sed 's@\.@\\\.@g')
RASPBERRYPI_KERNEL_REVISION=$(pacman -Qi linux-raspberrypi | egrep '^Version\s+' | grep -oP '(?<=-)[0-9]+(?=$)')
echo "Modifying to build against: linux-raspberrypi-${RASPBERRYPI_KERNEL_VERSION}-${RASPBERRYPI_KERNEL_REVISION}."
[[ -n "${LTS_KERNEL_VERSION_ESCAPED}" && -n "${RASPBERRYPI_KERNEL_VERSION_ESCAPED}" ]] || return 251
[[ -n "${LTS_KERNEL_REVISION}" && -n "${RASPBERRYPI_KERNEL_REVISION}" ]] || return 250
{ cd ~/cower && { [[ ! -d zfs-utils ]] || find zfs-utils/ -mindepth 1 ! -name '*.pkg.tar.xz' -delete; } && \
wget -qO- 'https://aur.archlinux.org/cgit/aur.git/snapshot/zfs-utils.tar.gz' | bsdtar -xzpvf -; } && \
{ cd ~/cower/zfs-utils && sed -i -E 's@^arch=\(\s*"([^\)]*)"\s*\)$@arch=\("\1" "armv6h"\)@' PKGBUILD && \
eval __mkpkg --noconfirm -Ccsi; [[ ${?} -eq 0 || ${?} -eq 13 ]]; } || return 3
{ cd ~/cower && { [[ ! -d zfs-linux-lts ]] || find zfs-linux-lts/ -mindepth 1 ! -name '*.pkg.tar.xz' -delete; } && \
wget -qO- 'https://aur.archlinux.org/cgit/aur.git/snapshot/zfs-linux-lts.tar.gz' | bsdtar -xzpvf -; } && \
{ cd ~/cower/zfs-linux-lts && sed -i -E 's@^arch=\(\s*"([^\)]*)"\s*\)$@arch=\("\1" "armv6h"\)@' PKGBUILD && \
sed -i -E 's@"linux-lts@"linux-raspberrypi@g' PKGBUILD && \
sed -i -E 's@'"${LTS_KERNEL_VERSION_ESCAPED}"'([\.-])'"${LTS_KERNEL_REVISION}"'@'"${RASPBERRYPI_KERNEL_VERSION_ESCAPED}"'\1'"${RASPBERRYPI_KERNEL_REVISION}"'@g' PKGBUILD && \
sed -i -E 's@='"${LTS_KERNEL_VERSION_ESCAPED}"'"@='"${RASPBERRYPI_KERNEL_VERSION_ESCAPED}"'"@g' PKGBUILD && \
sed -i -E 's@'"${RASPBERRYPI_KERNEL_VERSION_ESCAPED}"'-'"${RASPBERRYPI_KERNEL_REVISION}"'-lts@'"${RASPBERRYPI_KERNEL_VERSION_ESCAPED}"'-'"${RASPBERRYPI_KERNEL_REVISION}"'-ARCH@g' PKGBUILD && \
sed -i -E 's@'"${LTS_KERNEL_VERSION_ESCAPED}"'-'"${LTS_KERNEL_REVISION}"'-lts@'"${RASPBERRYPI_KERNEL_VERSION_ESCAPED}"'-'"${RASPBERRYPI_KERNEL_REVISION}"'-ARCH@g' zfs.install && \
eval __mkpkg --noconfirm -Ccsi; [[ ${?} -eq 0 || ${?} -eq 13 ]]; } || return 4
# Set ZFS parameters aimed at aiding operation on systems with low memory
mkdir -m0755 -p "/etc/modprobe.d"
echo "options zfs zfs_arc_max=$[80*1024*1024] zfs_arc_min=$[16*1024*1024] zfs_dirty_data_sync=$[12*1024*1024] zfs_dirty_data_max=$[12*1024*1024] zfs_dirty_data_max_max=$[80*1024*1024] zfs_resilver_delay=0 zfs_scrub_delay=0" | sudo tee "/etc/modprobe.d/zfs.conf.new" > /dev/null
[[ -e "/etc/modprobe.d/zfs.conf" ]] && ! diff "/etc/modprobe.d/zfs.conf.new" "/etc/modprobe.d/zfs.conf" &> /dev/null && sudo mv "/etc/modprobe.d/zfs.conf" "/etc/modprobe.d/zfs.conf.$(date '+%Y%m%d%H%M%S')"
sudo mv "/etc/modprobe.d/zfs.conf.new" "/etc/modprobe.d/zfs.conf"
echo; echo; eval regen-initrd; echo; echo
echo -en "Advice: Don't forget to update the partition the system boots from,\n"
echo -en " if you have a setup where that partition is accessible in other ways than via the /boot directory!\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.