-
Notifications
You must be signed in to change notification settings - Fork 0
/
mount_zfs_vhd
executable file
·73 lines (51 loc) · 1.83 KB
/
mount_zfs_vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/local/bin/cbsd
#v10.3.0
MYARG="jname dsk mnt"
MYOPTARG=""
MYDESC="Import and mount ZFS-based storage to specified mount point"
CBSDMODULE="convectix"
EXTHELP="wf_bhyve"
. ${subr}
. ${cbsdinit}
. ${system}
. ${subrdir}/bhyve.subr
dsk_sql=$( cbsdsqlro ${jailsysdir}/${jname}/local.sqlite "SELECT dsk_path FROM bhyvedsk WHERE jname='${jname}' AND dsk_path='${dsk}'" 2>/dev/null );
[ -z "${dsk_sql}" ] && err 1 "${N1_COLOR}No such SQL records for: ${N2_COLOR}${dsk}${N1_COLOR} storage for ${N2_COLOR}${jname}${N0_COLOR}"
dsk_fullpath="${jaildatadir}/${jname}-${jaildatapref}/${dsk}"
[ ! -r "${dsk_fullpath}" ] && err 1 "${N1_COLOR}No such image: ${N2_COLOR}${dsk_fullpath}${N0_COLOR}"
. ${mdtools}
mddev=$( eval find_md_by_img ${dsk_fullpath} )
if [ -z "${mddev}" ]; then
set -e
mddev=$( /sbin/mdconfig -a -t vnode -f "${dsk_fullpath}" 2>/dev/null )
set +u
fi
[ -z "${mddev}" ] && err 1 "${N1_COLOR}Error mdconfig for: ${N2_COLOR}${dsk_fullpath}${N0_COLOR}"
#echo $mddev
[ ! -d "${mnt}" ] && /bin/mkdir -p ${mnt}
zfsdev=
pool=
eval $( /sbin/zpool import -N |${EGREP_CMD} -E "(pool: )|(md0.*ONLINE$)" | ${AWK_CMD} '{printf $1" "$2"\n"}' |while read _x _y; do
[ -z "${_x}" -o -z "${_y}" ] && continue
[ "${_x}" = "pool:" ] && echo "pool=${_y}"
[ "${_y}" = "ONLINE" ] && echo "zfsdev=${_x}"
unset _x _y
done )
#/sbin/zpool import -f -R ${mnt} tank
if [ -z "${pool}" ]; then
/sbin/mdconfig -d -u ${mddev}
err 1 "Unable to determine ZFS pool for ${dsk_fullpath}"
fi
if [ -z "${zfsdev}" ]; then
/sbin/mdconfig -d -u ${mddev}
err 1 "Unable to determine ZFS disk for pool ${pool} on ${dsk_fullpath}"
fi
res=$( /sbin/zpool import -f -R ${mnt} ${pool} 2>&1 )
if [ $? -ne 0 ]; then
mdconfig -d -u ${mddev}
err 1 "$res"
fi
echo "Done"
/sbin/zfs unmount ${mnt} || /sbin/umount -f ${mnt}
/sbin/zpool export ${pool}
/sbin/mdconfig -d -u ${mddev}