]>
Commit | Line | Data |
---|---|---|
eda3d4e1 ST |
1 | #!/bin/sh |
2 | ||
01d01ef0 | 3 | command -v getarg >/dev/null || . /lib/dracut-lib.sh |
d402c18d MAR |
4 | command -v getargbool >/dev/null || { |
5 | # Compatibility with older Dracut versions. | |
6 | # With apologies to the Dracut developers. | |
7 | getargbool() { | |
8 | local _b | |
9 | unset _b | |
10 | local _default | |
11 | _default="$1"; shift | |
12 | _b=$(getarg "$@") | |
13 | [ $? -ne 0 -a -z "$_b" ] && _b="$_default" | |
14 | if [ -n "$_b" ]; then | |
15 | [ $_b = "0" ] && return 1 | |
16 | [ $_b = "no" ] && return 1 | |
17 | [ $_b = "off" ] && return 1 | |
18 | fi | |
19 | return 0 | |
20 | } | |
21 | } | |
eda3d4e1 ST |
22 | |
23 | OLDIFS="${IFS}" | |
24 | NEWLINE=" | |
25 | " | |
26 | ||
27 | ZPOOL_IMPORT_OPTS="" | |
28 | if getargbool 0 zfs_force -y zfs.force -y zfsforce ; then | |
29 | warn "ZFS: Will force-import pools if necessary." | |
30 | ZPOOL_IMPORT_OPTS="${ZPOOL_IMPORT_OPTS} -f" | |
31 | fi | |
32 | ||
33 | # find_bootfs | |
34 | # returns the first dataset with the bootfs attribute. | |
35 | find_bootfs() { | |
36 | IFS="${NEWLINE}" | |
37 | for dataset in $(zpool list -H -o bootfs); do | |
38 | case "${dataset}" in | |
39 | "" | "-") | |
40 | continue | |
41 | ;; | |
42 | "no pools available") | |
43 | IFS="${OLDIFS}" | |
44 | return 1 | |
45 | ;; | |
46 | *) | |
47 | IFS="${OLDIFS}" | |
48 | echo "${dataset}" | |
49 | return 0 | |
50 | ;; | |
51 | esac | |
52 | done | |
53 | ||
54 | IFS="${OLDIFS}" | |
55 | return 1 | |
56 | } | |
57 | ||
58 | # import_pool POOL | |
59 | # imports the given zfs pool if it isn't imported already. | |
60 | import_pool() { | |
61 | local pool="${1}" | |
62 | ||
63 | if ! zpool list -H "${pool}" 2>&1 > /dev/null ; then | |
64 | info "ZFS: Importing pool ${pool}..." | |
65 | if ! zpool import -N ${ZPOOL_IMPORT_OPTS} "${pool}" ; then | |
66 | warn "ZFS: Unable to import pool ${pool}" | |
67 | return 1 | |
68 | fi | |
69 | fi | |
70 | ||
71 | return 0 | |
72 | } | |
73 | ||
74 | # mount_dataset DATASET | |
75 | # mounts the given zfs dataset. | |
76 | mount_dataset() { | |
77 | local dataset="${1}" | |
78 | local mountpoint="$(zfs get -H -o value mountpoint "${dataset}")" | |
79 | ||
80 | # We need zfsutil for non-legacy mounts and not for legacy mounts. | |
81 | if [ "${mountpoint}" = "legacy" ] ; then | |
82 | mount -t zfs "${dataset}" "${NEWROOT}" | |
83 | else | |
84 | mount -o zfsutil -t zfs "${dataset}" "${NEWROOT}" | |
85 | fi | |
86 | ||
87 | return $? | |
88 | } | |
89 | ||
90 | # export_all OPTS | |
91 | # exports all imported zfs pools. | |
92 | export_all() { | |
93 | local opts="${1}" | |
94 | local ret=0 | |
95 | ||
96 | IFS="${NEWLINE}" | |
97 | for pool in `zpool list -H -o name` ; do | |
98 | if zpool list -H "${pool}" 2>&1 > /dev/null ; then | |
99 | zpool export "${pool}" ${opts} || ret=$? | |
100 | fi | |
101 | done | |
102 | IFS="${OLDIFS}" | |
103 | ||
104 | return ${ret} | |
105 | } |