@@ -6,15 +6,14 @@ package iso
6
6
7
7
import (
8
8
"bytes"
9
- "context"
10
9
_ "embed"
11
10
"fmt"
12
11
"os"
13
12
"path/filepath"
14
13
"text/template"
15
- "time"
16
14
17
15
"github.com/siderolabs/go-cmd/pkg/cmd"
16
+ "github.com/siderolabs/go-copy/copy"
18
17
19
18
"github.com/siderolabs/talos/pkg/imager/utils"
20
19
"github.com/siderolabs/talos/pkg/machinery/constants"
@@ -67,6 +66,8 @@ func CreateUEFI(printf func(string, ...any), options UEFIOptions) error {
67
66
68
67
efiBootImg := filepath .Join (options .ScratchDir , "efiboot.img" )
69
68
69
+ isoRoot := filepath .Join (options .ScratchDir , "isoroot" )
70
+
70
71
// initial size
71
72
isoSize := int64 (10 * mib )
72
73
@@ -109,112 +110,107 @@ func CreateUEFI(printf func(string, ...any), options UEFIOptions) error {
109
110
return err
110
111
}
111
112
112
- if _ , err := cmd .Run ("mmd" , "-i" , efiBootImg , "::EFI" ); err != nil {
113
- return err
114
- }
115
-
116
- if _ , err := cmd .Run ("mmd" , "-i" , efiBootImg , "::EFI/BOOT" ); err != nil {
117
- return err
118
- }
119
-
120
- if _ , err := cmd .Run ("mmd" , "-i" , efiBootImg , "::EFI/Linux" ); err != nil {
121
- return err
122
- }
123
-
124
- if _ , err := cmd .Run ("mmd" , "-i" , efiBootImg , "::EFI/keys" ); err != nil {
113
+ if err := os .MkdirAll (filepath .Join (isoRoot , "EFI/Linux" ), 0o755 ); err != nil {
125
114
return err
126
115
}
127
116
128
- if _ , err := cmd . Run ( "mmd" , "-i" , efiBootImg , "::loader" ); err != nil {
117
+ if err := os . MkdirAll ( filepath . Join ( isoRoot , "EFI/BOOT" ), 0o755 ); err != nil {
129
118
return err
130
119
}
131
120
132
- if _ , err := cmd . Run ( "mmd" , "-i" , efiBootImg , "::loader /keys" ); err != nil {
121
+ if err := os . MkdirAll ( filepath . Join ( isoRoot , "EFI /keys" ), 0o755 ); err != nil {
133
122
return err
134
123
}
135
124
136
- if _ , err := cmd . Run ( "mmd" , "-i" , efiBootImg , ":: loader/keys/auto" ); err != nil {
125
+ if err := os . MkdirAll ( filepath . Join ( isoRoot , "loader/keys/auto" ), 0o755 ); err != nil {
137
126
return err
138
127
}
139
128
140
- efiBootPath := ":: EFI/BOOT/BOOTX64.EFI"
129
+ efiBootPath := "EFI/BOOT/BOOTX64.EFI"
141
130
142
131
if options .Arch == "arm64" {
143
- efiBootPath = ":: EFI/BOOT/BOOTAA64.EFI"
132
+ efiBootPath = "EFI/BOOT/BOOTAA64.EFI"
144
133
}
145
134
146
- if _ , err := cmd . Run ( "mcopy" , "-i" , efiBootImg , options .SDBootPath , efiBootPath ); err != nil {
135
+ if err := copy . File ( options .SDBootPath , filepath . Join ( isoRoot , efiBootPath ) ); err != nil {
147
136
return err
148
137
}
149
138
150
- if _ , err := cmd . Run ( "mcopy" , "-i" , efiBootImg , options .UKIPath , fmt .Sprintf (":: EFI/Linux/Talos-%s.efi" , options .Version )); err != nil {
139
+ if err := copy . File ( options .UKIPath , filepath . Join ( isoRoot , fmt .Sprintf ("EFI/Linux/Talos-%s.efi" , options .Version ) )); err != nil {
151
140
return err
152
141
}
153
142
154
- if _ , err := cmd .RunContext (
155
- cmd .WithStdin (context .Background (), & loaderConfigOut ),
156
- "mcopy" , "-i" , efiBootImg , "-" , "::loader/loader.conf" ,
157
- ); err != nil {
143
+ if err := os .WriteFile (filepath .Join (isoRoot , "loader/loader.conf" ), loaderConfigOut .Bytes (), 0o644 ); err != nil {
158
144
return err
159
145
}
160
146
161
- if _ , err := cmd . Run ( "mcopy" , "-i" , efiBootImg , options .UKISigningCertDerPath , ":: EFI/keys/uki-signing-cert.der" ); err != nil {
147
+ if err := copy . File ( options .UKISigningCertDerPath , filepath . Join ( isoRoot , " EFI/keys/uki-signing-cert.der") ); err != nil {
162
148
return err
163
149
}
164
150
165
151
if options .PlatformKeyPath != "" {
166
- if _ , err := cmd . Run ( "mcopy" , "-i" , efiBootImg , options .PlatformKeyPath , filepath .Join (":: loader/keys/auto" , constants .PlatformKeyAsset )); err != nil {
152
+ if err := copy . File ( options .PlatformKeyPath , filepath .Join (isoRoot , " loader/keys/auto" , constants .PlatformKeyAsset )); err != nil {
167
153
return err
168
154
}
169
155
}
170
156
171
157
if options .KeyExchangeKeyPath != "" {
172
- if _ , err := cmd . Run ( "mcopy" , "-i" , efiBootImg , options .KeyExchangeKeyPath , filepath .Join (":: loader/keys/auto" , constants .KeyExchangeKeyAsset )); err != nil {
158
+ if err := copy . File ( options .KeyExchangeKeyPath , filepath .Join (isoRoot , " loader/keys/auto" , constants .KeyExchangeKeyAsset )); err != nil {
173
159
return err
174
160
}
175
161
}
176
162
177
163
if options .SignatureKeyPath != "" {
178
- if _ , err := cmd . Run ( "mcopy" , "-i" , efiBootImg , options .SignatureKeyPath , filepath .Join (":: loader/keys/auto" , constants .SignatureKeyAsset )); err != nil {
164
+ if err := copy . File ( options .SignatureKeyPath , filepath .Join (isoRoot , " loader/keys/auto" , constants .SignatureKeyAsset )); err != nil {
179
165
return err
180
166
}
181
167
}
182
168
169
+ if _ , err := cmd .Run (
170
+ "mcopy" ,
171
+ "-s" , // recursive
172
+ "-p" , // preserve attributes
173
+ "-Q" , // quit on error
174
+ "-m" , // preserve modification time
175
+ "-i" ,
176
+ efiBootImg ,
177
+ filepath .Join (isoRoot , "EFI" ),
178
+ filepath .Join (isoRoot , "loader" ),
179
+ "::" ,
180
+ ); err != nil {
181
+ return err
182
+ }
183
+
183
184
// fixup directory timestamps recursively
184
185
if err := utils .TouchFiles (printf , options .ScratchDir ); err != nil {
185
186
return err
186
187
}
187
188
188
189
printf ("creating ISO image" )
189
190
191
+ // ref: https://askubuntu.com/questions/1110651/how-to-produce-an-iso-image-that-boots-only-on-uefi/1111760#1111760
190
192
args := []string {
191
- "-as" , "mkisofs" ,
192
- "-e" , "efiboot.img" ,
193
+ "-e" , "--interval:appended_partition_2:all::" , // use appended partition 2 for EFI
194
+ "-append_partition" , "2" , "0xef" , efiBootImg ,
195
+ "-partition_cyl_align" , // pad partition to cylinder boundary
196
+ "all" ,
197
+ "-partition_offset" , "16" , // support booting from USB
198
+ "-iso_mbr_part_type" , "0x83" , // just to have more clear info when doing a fdisk -l
193
199
"-no-emul-boot" ,
194
200
"-o" , options .OutPath ,
195
- options .ScratchDir ,
196
- "--" ,
197
- }
198
-
199
- if epoch , ok , err := utils .SourceDateEpoch (); err != nil {
200
- return err
201
- } else if ok {
202
- args = append (args ,
203
- "-volume_date" , "all_file_dates" , fmt .Sprintf ("=%d" , epoch ),
204
- "-volume_date" , "uuid" , time .Unix (epoch , 0 ).Format ("2006010215040500" ),
205
- )
201
+ isoRoot ,
206
202
}
207
203
208
204
if quirks .New (options .Version ).SupportsISOLabel () {
209
205
label := Label (options .Version , true )
210
206
211
207
args = append (args ,
212
208
"-volid" , VolumeID (label ),
213
- "-volset-id " , label ,
209
+ "-volset" , label ,
214
210
)
215
211
}
216
212
217
- if _ , err := cmd .Run ("xorriso " , args ... ); err != nil {
213
+ if _ , err := cmd .Run ("xorrisofs " , args ... ); err != nil {
218
214
return err
219
215
}
220
216
0 commit comments