#!/bin/sh # # HOWTO/script for creating ZFS filesystems using the same input # file format as zfsboot. ${POOL} defaults to 'home', set the POOL # environment variable as appropriate. This script is usefull if you # need to create more filesystems on the root zpool after installation # with zfsboot. Or if you create additional zpool(s) mounted on the # root zpool. # # Yarema #===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===# program=`basename $0` #===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===# if [ -f "$0.rc" ];then . "$0.rc" fi # The recommended name is simply the letter 'z' which makes output # form mount(8), zfs(8M) and zpool(8M) easy to read for us humans. : ${POOL:='home'} DESTDIR="/${POOL}" # file describing the ZFS datasets to create : ${DATASETS:="$0.fs"} #===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===# ask() { local question default answer question=$1 default=$2 read -p "${question} [${default}]? " answer if [ -z "${answer}" ]; then answer=${default} fi echo ${answer} } yesno() { local question default answer question=$1 default=$2 while :; do answer=$(ask "${question}" "${default}") case "${answer}" in [Yy]*) return 0;; [Nn]*) return 1;; esac echo "Please answer yes or no." done } #===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===# while read filesystem options; do case "${filesystem}" in /*) command="zfs create" for option in ${options};do command="${command} -o ${option}" done eval `echo "${command} ${POOL}${filesystem}" | sed -E 's/-[[:<:]]o[[:>:]][[:space:]]+-[[:<:]]V[[:>:]][[:space:]]+-[[:<:]]o[[:>:]]/-V/g'` zfs get mountpoint,compression,exec,setuid ${POOL}${filesystem} # Only set mountpoint for top level filesysytem # Let the child filesystem(s) inherit the moutpoint if echo "${filesystem}" | egrep '^/[^/]+$' > /dev/null 2>&1; then # Exclude volumes since they do not have the moutpoint property if echo "${command}" | egrep -v '[[:space:]]+-V[[:space:]]+' > /dev/null 2>&1; then mountpoints="${mountpoints} ${filesystem}" fi fi ;; *) continue ;; esac done < ${DATASETS} #===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===# for mp in ${mountpoints}; do zfs set mountpoint=${mp} ${POOL}${mp} done zfs list #===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===#===# # EOF