summarylogtreecommitdiffstats
path: root/zfs-utils.initcpio.hook
diff options
context:
space:
mode:
authorJesus Alvarez2016-09-12 22:38:18 -0700
committerJesus Alvarez2016-09-12 22:38:18 -0700
commit2748de5ec10e9675bb4816fe361bc60e2464179d (patch)
tree7865f44102850a8b4d220db91915fd21f7366ed6 /zfs-utils.initcpio.hook
parent4d0fbfa36088c15e8dbe2e6ba237b8dc8bc9ab44 (diff)
downloadaur-2748de5ec10e9675bb4816fe361bc60e2464179d.tar.gz
Semi-automated update for 4.7.2_1-6
Diffstat (limited to 'zfs-utils.initcpio.hook')
-rw-r--r--zfs-utils.initcpio.hook86
1 files changed, 51 insertions, 35 deletions
diff --git a/zfs-utils.initcpio.hook b/zfs-utils.initcpio.hook
index 57df9c168b7d..8f1d587b01ab 100644
--- a/zfs-utils.initcpio.hook
+++ b/zfs-utils.initcpio.hook
@@ -2,7 +2,7 @@ ZPOOL_FORCE=""
ZPOOL_IMPORT_FLAGS=""
zfs_get_bootfs () {
- for zfs_dataset in $(/usr/bin/zpool list -H -o bootfs); do
+ for zfs_dataset in $(zpool list -H -o bootfs); do
case ${zfs_dataset} in
"" | "-")
# skip this line/dataset
@@ -20,14 +20,12 @@ zfs_get_bootfs () {
}
zfs_mount_handler () {
- local node=$1
- if [ "$ZFS_DATASET" = "bootfs" ] ; then
+ if [ "${ZFS_DATASET}" = "bootfs" ] ; then
if ! zfs_get_bootfs ; then
# Lets import everything and try again
- /usr/bin/zpool import $ZPOOL_IMPORT_FLAGS -N -a $ZPOOL_FORCE
+ zpool import ${ZPOOL_IMPORT_FLAGS} -N -a ${ZPOOL_FORCE}
if ! zfs_get_bootfs ; then
- echo "ZFS: Cannot find bootfs."
- return 1
+ die "ZFS: Cannot find bootfs."
fi
fi
fi
@@ -35,39 +33,61 @@ zfs_mount_handler () {
local pool="${ZFS_DATASET%%/*}"
local rwopt_exp=${rwopt:-ro}
- if ! "/usr/bin/zpool" list -H $pool 2>&1 > /dev/null ; then
- if [ "$rwopt_exp" != "rw" ]; then
- msg "ZFS: Importing pool $pool readonly."
- ZPOOL_IMPORT_FLAGS="$ZPOOL_IMPORT_FLAGS -o readonly=on"
+ if ! zpool list -H ${pool} 2>1 > /dev/null ; then
+ if [ "${rwopt_exp}" != "rw" ]; then
+ msg "ZFS: Importing pool ${pool} readonly."
+ ZPOOL_IMPORT_FLAGS="${ZPOOL_IMPORT_FLAGS} -o readonly=on"
else
- msg "ZFS: Importing pool $pool."
+ msg "ZFS: Importing pool ${pool}."
fi
- if ! "/usr/bin/zpool" import $ZPOOL_IMPORT_FLAGS -N $pool $ZPOOL_FORCE ; then
- echo "ZFS: Unable to import pool $pool."
- return 1
+ if ! zpool import ${ZPOOL_IMPORT_FLAGS} -N ${pool} ${ZPOOL_FORCE} ; then
+ die "ZFS: Unable to import pool ${pool}."
fi
fi
- local mountpoint=$("/usr/bin/zfs" get -H -o value mountpoint $ZFS_DATASET)
- if [ "$mountpoint" = "legacy" ] ; then
- mount -t zfs -o ${rwopt_exp} "$ZFS_DATASET" "$node"
- else
- mount -o zfsutil,${rwopt_exp} -t zfs "$ZFS_DATASET" "$node"
- fi
+ local node=$1
+ local tab_file="$node/etc/fstab"
+ local zfs_datasets=$(zfs list -H -o name -t filesystem -r "${ZFS_DATASET}")
+
+ # Mount the root, and any child datasets
+ for dataset in ${zfs_datasets}; do
+ mountpoint=$(zfs get -H -o value mountpoint "${dataset}")
+ case ${mountpoint} in
+ "none")
+ # skip this line/dataset.
+ ;;
+ "legacy")
+ if [ -f "${tab_file}" ]; then
+ if findmnt -snero source -F "${tab_file}" -S "${dataset}" > /dev/null 2>&1; then
+ opt=$(findmnt -snero options -F "${tab_file}" -S "${dataset}")
+ mnt=$(findmnt -snero target -F "${tab_file}" -S "${dataset}")
+ mount -t zfs -o "${opt}" "${dataset}" "${node}${mnt}"
+ fi
+ fi
+ ;;
+ *)
+ mount -t zfs -o "zfsutil,${rwopt_exp}" "${dataset}" "${node}${mountpoint}"
+ ;;
+ esac
+ done
}
run_hook() {
- # Force import the pools, useful if the pool has not properly been exported
- # using 'zpool export <pool>'
- [[ $zfs_force == 1 ]] && ZPOOL_FORCE='-f'
- [[ "$zfs_import_dir" != "" ]] && ZPOOL_IMPORT_FLAGS="$ZPOOL_IMPORT_FLAGS -d $zfs_import_dir"
+ # Force import the pools, useful if the pool has not properly been exported using 'zpool export <pool>'
+ [[ ${zfs_force} == 1 ]] && ZPOOL_FORCE='-f'
+
+ # Add import directory to import command flags
+ [[ "${zfs_import_dir}" != "" ]] && ZPOOL_IMPORT_FLAGS="${ZPOOL_IMPORT_FLAGS} -d ${zfs_import_dir}"
- if [ "$root" = 'zfs' ]; then
+ # Wait 15 seconds for ZFS devices to show up
+ [[ "${zfs_wait}" == "" ]] && ZFS_WAIT="15" || ZFS_WAIT="${zfs_wait}"
+
+ if [[ "${root}" == 'zfs' ]]; then
mount_handler='zfs_mount_handler'
fi
- case $zfs in
+ case ${zfs} in
"")
# skip this line/dataset
;;
@@ -76,24 +96,20 @@ run_hook() {
mount_handler="zfs_mount_handler"
;;
*)
- ZFS_DATASET=$zfs
+ ZFS_DATASET=${zfs}
mount_handler="zfs_mount_handler"
;;
esac
- if [ ! -f "/etc/hostid" ] ; then
- echo "ZFS: No hostid found on kernel command line or /etc/hostid. ZFS pools may not import correctly."
- fi
-
- # Allow up to 10 seconds for zfs device to show up
- for i in 1 2 3 4 5 6 7 8 9 10; do
- [ -c "/dev/zfs" ] && break
+ # Allow up to n seconds for zfs device to show up
+ for i in {1..${ZFS_WAIT}}; do
+ [[ -c "/dev/zfs" ]] && break
sleep 1
done
}
run_latehook () {
- /usr/bin/zpool import -N -a $ZPOOL_FORCE
+ zpool import -N -a ${ZPOOL_FORCE}
}
# vim:set ts=4 sw=4 ft=sh et: