@@ -24,6 +24,8 @@ use crate::util::CommandRunExt;
24
24
25
25
/// The path to the ESP mount
26
26
pub ( crate ) const MOUNT_PATH : & str = "boot/efi" ;
27
+ /// The ESP partition label
28
+ pub ( crate ) const ESP_PART_LABEL : & str = "EFI-SYSTEM" ;
27
29
28
30
#[ derive( Default ) ]
29
31
pub ( crate ) struct EFI { }
@@ -33,16 +35,47 @@ impl EFI {
33
35
Path :: new ( MOUNT_PATH ) . join ( "EFI" )
34
36
}
35
37
38
+ fn esp_device ( & self ) -> PathBuf {
39
+ Path :: new ( "/dev/disk/by-partlabel/" ) . join ( ESP_PART_LABEL )
40
+ }
41
+
36
42
fn open_esp_optional ( & self ) -> Result < Option < openat:: Dir > > {
43
+ self . ensure_mounted_esp ( ) ?;
37
44
let sysroot = openat:: Dir :: open ( "/" ) ?;
38
45
let esp = sysroot. sub_dir_optional ( & self . esp_path ( ) ) ?;
39
46
Ok ( esp)
40
47
}
41
48
fn open_esp ( & self ) -> Result < openat:: Dir > {
49
+ self . ensure_mounted_esp ( ) ?;
42
50
let sysroot = openat:: Dir :: open ( "/" ) ?;
43
51
let esp = sysroot. sub_dir ( & self . esp_path ( ) ) ?;
44
52
Ok ( esp)
45
53
}
54
+
55
+ fn ensure_mounted_esp ( & self ) -> Result < ( ) > {
56
+ let mount_point = & Path :: new ( "/" ) . join ( MOUNT_PATH ) ;
57
+ let output = std:: process:: Command :: new ( "mountpoint" )
58
+ . arg ( mount_point)
59
+ . output ( )
60
+ . expect ( "Failed to determine if EFI mounted" ) ;
61
+ if !output. status . success ( ) {
62
+ let status = std:: process:: Command :: new ( "mkdir" )
63
+ . arg ( "-p" )
64
+ . arg ( mount_point)
65
+ . status ( ) ?;
66
+ if !status. success ( ) {
67
+ anyhow:: bail!( "Failed to create directory {:?}" , mount_point) ;
68
+ }
69
+ let status = std:: process:: Command :: new ( "mount" )
70
+ . arg ( & self . esp_device ( ) )
71
+ . arg ( mount_point)
72
+ . status ( ) ?;
73
+ if !status. success ( ) {
74
+ anyhow:: bail!( "Failed to mount {:?}" , & self . esp_device( ) ) ;
75
+ }
76
+ } ;
77
+ Ok ( ( ) )
78
+ }
46
79
}
47
80
48
81
impl Component for EFI {
@@ -112,6 +145,7 @@ impl Component for EFI {
112
145
} ;
113
146
let srcdir_name = component_updatedirname ( self ) ;
114
147
let ft = crate :: filetree:: FileTree :: new_from_dir ( & src_root. sub_dir ( & srcdir_name) ?) ?;
148
+ self . ensure_mounted_esp ( ) ?;
115
149
let destdir = Path :: new ( dest_root) . join ( MOUNT_PATH ) ;
116
150
{
117
151
let destd = openat:: Dir :: open ( & destdir)
@@ -151,6 +185,7 @@ impl Component for EFI {
151
185
. context ( "opening update dir" ) ?;
152
186
let updatef = filetree:: FileTree :: new_from_dir ( & updated) . context ( "reading update dir" ) ?;
153
187
let diff = currentf. diff ( & updatef) ?;
188
+ self . ensure_mounted_esp ( ) ?;
154
189
let destdir = openat:: Dir :: open ( & Path :: new ( "/" ) . join ( MOUNT_PATH ) . join ( "EFI" ) )
155
190
. context ( "opening EFI dir" ) ?;
156
191
validate_esp ( & destdir) ?;
@@ -178,7 +213,8 @@ impl Component for EFI {
178
213
std:: fs:: remove_dir_all ( & p) ?;
179
214
}
180
215
}
181
-
216
+
217
+ self . ensure_mounted_esp ( ) ?;
182
218
let efisrc = ostreebootdir. join ( "efi/EFI" ) ;
183
219
if !efisrc. exists ( ) {
184
220
bail ! ( "Failed to find {:?}" , & efisrc) ;
@@ -256,6 +292,7 @@ impl Component for EFI {
256
292
. filetree
257
293
. as_ref ( )
258
294
. ok_or_else ( || anyhow:: anyhow!( "No filetree for installed EFI found!" ) ) ?;
295
+ self . ensure_mounted_esp ( ) ?;
259
296
let efidir = openat:: Dir :: open ( & Path :: new ( "/" ) . join ( MOUNT_PATH ) . join ( "EFI" ) ) ?;
260
297
let diff = currentf. relative_diff_to ( & efidir) ?;
261
298
let mut errs = Vec :: new ( ) ;
0 commit comments