#!/bin/bash # # zfs-speedmount # # Parallel mounting of all available zfs filesystems # # Author: Mikael Haglund # ###### export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin fs_raw="" fs_ordered="" function get_pool_filesystems() { IFS=" " tmp_fs=$(zfs list -r -t filesystem -H -o name,mountpoint $1 | awk '{print $1":"$2}') fs_raw="$fs_raw $tmp_fs" } function get_pools() { pools=$(zpool list -H -o name) echo $pools } function orderfs() { fs_ordered=$(echo "$fs_raw" | awk -F":" '{print gsub(/\//,"/",$2)":"$1}' ) } function mountfs() { for i in $(echo "$fs_ordered" | awk -F":" '{print $1}' | sort | uniq ); do echo "$fs_ordered" | grep -E "^$i:" | cut -f 2 -d ":" | sed -e "s/[[:blank:]]//g" | /usr/local/bin/parallel --will-cite -j 40 zfs mount {} sleep 5 done } get_all_filesystems() { fs="" for pool in $(get_pools); do get_pool_filesystems $pool done orderfs mountfs } get_all_filesystems