Commit a4ad04e3 authored by Benjamin Slade's avatar Benjamin Slade

removed need for installing `bc` to limit ARC

- refactored: uses `bash` and `(g)awk` for calculations

- other minor clean-up
parent 89c4313b
......@@ -65,6 +65,13 @@ read -p "The following will take some time - you may want to go and put the kett
# install crucial packages, including zfs, which will trigger DKMS ZFS module creation for each kernel
xbps-install -S linux cryptsetup grub zfs
# disable resume functionality from dracut
echo "omit_dracutmodules+=\" resume \"" > /etc/dracut.conf.d/omit-resume-for-zvol-swap.conf
# inform user about resume
echo "[Resume functionality has been disabled from dracut. Otherwise future kernels which are installed will take 2-3 minutes to boot while dracut searches for the swap partition to initialise resume. This issue will be investigated, but disabling resume from dracut prevents the delayed boot.]"
# dracut
sed -i 's/--force/--force --hostonly --include \/boot\/rootkey.bin \/rootkey.bin/' /etc/kernel.d/post-install/20-dracut
......@@ -95,12 +102,6 @@ mkswap -f /dev/zvol/${ZPOOLNAME}/swap
echo "# zol swap vol" >> /etc/fstab
echo "/dev/zvol/${ZPOOLNAME}/swap none swap sw 0 0" >> /etc/fstab
# disable resume functionality from dracut
echo "omit_dracutmodules+=\" resume \"" > /etc/dracut.conf.d/omit-resume-for-zvol-swap.conf
# inform user about resume
echo "[Resume functionality has been disabled from dracut. Otherwise future kernels which are installed will take 2-3 minutes to boot while dracut searches for the swap partition to initialise resume. This issue will be investigated, but disabling resume from dracut prevents the delayed boot.]"
# Setting zfs cache
echo "Setting zpool cachefile for ${ZPOOLNAME}."
zpool set cachefile=/etc/zfs/zpool.cache ${ZPOOLNAME} # IMPORTANT
......@@ -114,26 +115,23 @@ until passwd ${USERNAME}; do echo "Confirmation didn't match. Please try again.
read -p "Would you like to set limit ARC size? (By default it will default to half available memory; if you're running a desktop/laptop, you may want to set it lower; if you're running a file-server, you may want to set it higher.) [Y/n]: " ARCSET
ARCSET=${ARCSET:-Y}
if [ ${ARCSET} == "Y" ]
if [ ${ARCSET} == "Y" ] || [ ${ARCSET} == "y" ]
then
echo "Installing bc for calculations..."
xbps-install -S bc
RAWMEM=`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`
MEMAVAIL=`echo "${RAWMEM}*1.025/1024/1024" | bc`
# MEMAVAIL=`echo $(((${RAWMEM}*1.025)/1024)/1024)`
MEMAVAIL=`awk -v RAWMEM=$RAWMEM 'BEGIN {printf "%.0f\n", (((RAWMEM * 1.025)/1024) / 1024) }'`
echo "You have ${MEMAVAIL}Gb available. How much memory would you like to reserve for ARC? "
until [[ "${ARCREZ}" =~ ^[0-9.]+$ ]] && [[ `echo "${ARCREZ} > 0" | bc` == 1 ]] && [[ `echo "${ARCREZ} < ${RAWMEM}" | bc` == 1 ]]
do read -p "Enter a number in Gb (e.g. \"4\", \"1.7125\" &c.): " ARCREZ
until [[ "${ARCREZ}" =~ ^[0-9]+(\.[0-9]+)?$ ]] && [[ $largerthanzero == 1 ]] && [[ $biggerthanram == 1 ]]
do read -p "Enter a number in Gb that is larger than 0 and less than ${MEMAVAIL}, (e.g. \"4\", \"1.76\"): " ARCREZ
largerthanzero=`awk -v ARCREZ="$ARCREZ" 'BEGIN { print (ARCREZ > 0) }'`
biggerthanram=`awk -v ARCREZ="$ARCREZ" -v MEMAVAIL="$MEMAVAIL" 'BEGIN { print (ARCREZ<MEMAVAIL) }'`
done
MEMINBYTES=`echo "${ARCREZ}*1024*1024*1024" | bc | awk '{printf("%d\n",$1 + 0.5)}'`
ARCREZINT=${ARCREZ%.*}
MEMINBYTES=`echo "$((ARCREZINT*1024*1024*1024))"`
echo "
# Limit ZFS ARC to ${ARCREZ}Gb
echo ${MEMINBYTES} >> /sys/module/zfs/parameters/zfs_arc_max" >> /etc/rc.local
echo "ARC size specified in /etc/rc.local"
echo "Removing bc package"
xbps-remove -R bc
fi
......@@ -163,7 +161,7 @@ echo "export NETWORKMAN=${NETWORKMAN}" >> /root/importvars.sh
mv 08-post-installation-setup.sh /root/08-post-installation-setup.sh
# message to user
echo "You have successfully configured Void Linux. The next step is leaving the chroot, unmounting bind mounts and exporting the ZFS pool. After exiting the chroot, please execute the following in the terminal:"
echo "You have successfully configured Void Linux. The next step is leaving the chroot, unmounting bind mounts and exporting the ZFS pool. These actions will be performed by the next script. After exiting the chroot, please execute the following in the terminal:"
echo ". 07-umount-reboot.sh"
read -p "Press <return> to exit chroot." exitchroot
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment