add PARTLABEL and PARTUUID
[platform/upstream/dracut.git] / modules.d / 90crypt / crypt-run-generator.sh
1 #!/bin/sh
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4
5 . /lib/dracut-lib.sh
6
7 dev=$1
8 luks=$2
9
10 if [ -f /etc/crypttab ]; then
11     while read l rest; do
12         strstr "${l##luks-}" "${luks##luks-}" && exit 0
13     done < /etc/crypttab
14 fi
15
16 allowdiscards="-"
17
18 # parse for allow-discards
19 if strstr "$(cryptsetup --help)" "allow-discards"; then
20     if discarduuids=$(getargs "rd.luks.allow-discards"); then
21         discarduuids=$(str_replace "$discarduuids" 'luks-' '')
22         if strstr " $discarduuids " " ${luks##luks-}"; then
23             allowdiscards="allow-discards"
24         fi
25     elif getargbool 0 rd.luks.allow-discards; then
26         allowdiscards="allow-discards"
27     fi
28 fi
29
30 echo "$luks $dev - timeout=0,$allowdiscards" >> /etc/crypttab
31
32 if command -v systemctl >/dev/null; then
33     systemctl daemon-reload
34     systemctl start cryptsetup.target
35 fi
36 exit 0