@@ -19,6 +19,7 @@ pub struct CryptData {
19
19
20
20
/// Extra cmdline options for the kernel
21
21
pub cmdline_opts : Vec < String > ,
22
+ pub tpm : bool ,
22
23
}
23
24
24
25
fn cryptsetup_luks_uuid ( node : & str ) -> Result < String , color_eyre:: eyre:: Error > {
@@ -119,20 +120,48 @@ impl RepartOutput {
119
120
120
121
let luks_partitions = self . partitions . iter ( ) . filter ( |part| is_luks ( & part. node ) ) ;
121
122
123
+ let mut is_tpm = false ;
124
+
122
125
let has_luks = luks_partitions. clone ( ) . count ( ) > 0 ;
123
126
for part in luks_partitions {
124
127
let uuid = cryptsetup_luks_uuid ( & part. node ) . expect ( "Failed to get LUKS UUID" ) ;
125
128
let label = & part. label ;
126
129
127
- writeln ! ( & mut crypttab, "{label}\t UUID={uuid}\t none\t luks,discard" ) ?;
130
+ let mut extra_opts = String :: new ( ) ;
131
+
132
+ let part_uses_tpm: bool = {
133
+ let file_config = std:: fs:: read_to_string ( & part. file ) ?;
134
+ let config: RepartConfig = serde_systemd_unit:: from_str ( & file_config) ?;
135
+
136
+ match config. partition . encrypt {
137
+ super :: repartcfg:: EncryptOption :: KeyFileTpm2 => true ,
138
+ super :: repartcfg:: EncryptOption :: Tpm2 => true ,
139
+ _ => false ,
140
+ }
141
+ } ;
142
+
143
+ if part_uses_tpm {
144
+ is_tpm = true ;
145
+ extra_opts. push_str ( "tpm2-device=auto," ) ;
146
+ }
147
+
148
+ writeln ! (
149
+ & mut crypttab,
150
+ "{label}\t UUID={uuid}\t none\t {extra_opts}luks,discard"
151
+ ) ?;
128
152
129
153
cmdline_opts. push ( format ! ( "rd.luks.name={uuid}={label}" ) ) ;
130
154
}
155
+
156
+ if is_tpm {
157
+ cmdline_opts. push ( "rd.luks.options=tpm2-device=auto" . to_string ( ) ) ;
158
+ }
131
159
132
160
match has_luks {
133
161
true => Ok ( Some ( CryptData {
134
162
crypttab,
135
163
cmdline_opts,
164
+ tpm : is_tpm,
136
165
} ) ) ,
137
166
false => Ok ( None ) ,
138
167
}
0 commit comments