]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/contrib/dracut/90zfs/parse-zfs.sh.in
MFV 2.0-rc2
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / contrib / dracut / 90zfs / parse-zfs.sh.in
1 #!/bin/bash
2
3 . /lib/dracut-lib.sh
4
5 # Let the command line override our host id.
6 spl_hostid=$(getarg spl_hostid=)
7 if [ -n "${spl_hostid}" ] ; then
8         info "ZFS: Using hostid from command line: ${spl_hostid}"
9         zgenhostid -f "${spl_hostid}"
10 elif [ -f "/etc/hostid" ] ; then
11         info "ZFS: Using hostid from /etc/hostid: $(hostid)"
12 else
13         warn "ZFS: No hostid found on kernel command line or /etc/hostid."
14         warn "ZFS: Pools may not import correctly."
15 fi
16
17 wait_for_zfs=0
18 case "${root}" in
19         ""|zfs|zfs:)
20                 # We'll take root unset, root=zfs, or root=zfs:
21                 # No root set, so we want to read the bootfs attribute.  We
22                 # can't do that until udev settles so we'll set dummy values
23                 # and hope for the best later on.
24                 root="zfs:AUTO"
25                 rootok=1
26                 wait_for_zfs=1
27
28                 info "ZFS: Enabling autodetection of bootfs after udev settles."
29                 ;;
30
31         ZFS\=*|zfs:*|zfs:FILESYSTEM\=*|FILESYSTEM\=*)
32                 # root is explicit ZFS root.  Parse it now.  We can handle
33                 # a root=... param in any of the following formats:
34                 # root=ZFS=rpool/ROOT
35                 # root=zfs:rpool/ROOT
36                 # root=zfs:FILESYSTEM=rpool/ROOT
37                 # root=FILESYSTEM=rpool/ROOT
38                 # root=ZFS=pool+with+space/ROOT+WITH+SPACE (translates to root=ZFS=pool with space/ROOT WITH SPACE)
39
40                 # Strip down to just the pool/fs
41                 root="${root#zfs:}"
42                 root="${root#FILESYSTEM=}"
43                 root="zfs:${root#ZFS=}"
44                 # switch + with spaces because kernel cmdline does not allow us to quote parameters
45                 root=$(printf '%s\n' "$root" | sed "s/+/ /g")
46                 rootok=1
47                 wait_for_zfs=1
48
49                 info "ZFS: Set ${root} as bootfs."
50                 ;;
51 esac
52
53 # Make sure Dracut is happy that we have a root and will wait for ZFS
54 # modules to settle before mounting.
55 if [ ${wait_for_zfs} -eq 1 ]; then
56         ln -s /dev/null /dev/root 2>/dev/null
57         initqueuedir="${hookdir}/initqueue/finished"
58         test -d "${initqueuedir}" || {
59                 initqueuedir="${hookdir}/initqueue-finished"
60         }
61         echo '[ -e /dev/zfs ]' > "${initqueuedir}/zfs.sh"
62 fi