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