Skip to content

Commit ea19f15

Browse files
frezbosmira
authored andcommitted
fix: generation of SecureBoot iso
The Secureboot ISO previously generated has just an EFI parition. Now generate iso with both the EFI partition and also having ISO filesystem having the content so *File System transposition* also works. Fixes: #9565 Signed-off-by: Noel Georgi <git@frezbo.dev> (cherry picked from commit 9db7a36)
1 parent fddaa60 commit ea19f15

File tree

1 file changed

+41
-45
lines changed

1 file changed

+41
-45
lines changed

pkg/imager/iso/uefi.go

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ package iso
66

77
import (
88
"bytes"
9-
"context"
109
_ "embed"
1110
"fmt"
1211
"os"
1312
"path/filepath"
1413
"text/template"
15-
"time"
1614

1715
"github.com/siderolabs/go-cmd/pkg/cmd"
16+
"github.com/siderolabs/go-copy/copy"
1817

1918
"github.com/siderolabs/talos/pkg/imager/utils"
2019
"github.com/siderolabs/talos/pkg/machinery/constants"
@@ -67,6 +66,8 @@ func CreateUEFI(printf func(string, ...any), options UEFIOptions) error {
6766

6867
efiBootImg := filepath.Join(options.ScratchDir, "efiboot.img")
6968

69+
isoRoot := filepath.Join(options.ScratchDir, "isoroot")
70+
7071
// initial size
7172
isoSize := int64(10 * mib)
7273

@@ -109,112 +110,107 @@ func CreateUEFI(printf func(string, ...any), options UEFIOptions) error {
109110
return err
110111
}
111112

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 {
125114
return err
126115
}
127116

128-
if _, err := cmd.Run("mmd", "-i", efiBootImg, "::loader"); err != nil {
117+
if err := os.MkdirAll(filepath.Join(isoRoot, "EFI/BOOT"), 0o755); err != nil {
129118
return err
130119
}
131120

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 {
133122
return err
134123
}
135124

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 {
137126
return err
138127
}
139128

140-
efiBootPath := "::EFI/BOOT/BOOTX64.EFI"
129+
efiBootPath := "EFI/BOOT/BOOTX64.EFI"
141130

142131
if options.Arch == "arm64" {
143-
efiBootPath = "::EFI/BOOT/BOOTAA64.EFI"
132+
efiBootPath = "EFI/BOOT/BOOTAA64.EFI"
144133
}
145134

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 {
147136
return err
148137
}
149138

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 {
151140
return err
152141
}
153142

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 {
158144
return err
159145
}
160146

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 {
162148
return err
163149
}
164150

165151
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 {
167153
return err
168154
}
169155
}
170156

171157
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 {
173159
return err
174160
}
175161
}
176162

177163
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 {
179165
return err
180166
}
181167
}
182168

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+
183184
// fixup directory timestamps recursively
184185
if err := utils.TouchFiles(printf, options.ScratchDir); err != nil {
185186
return err
186187
}
187188

188189
printf("creating ISO image")
189190

191+
// ref: https://askubuntu.com/questions/1110651/how-to-produce-an-iso-image-that-boots-only-on-uefi/1111760#1111760
190192
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
193199
"-no-emul-boot",
194200
"-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,
206202
}
207203

208204
if quirks.New(options.Version).SupportsISOLabel() {
209205
label := Label(options.Version, true)
210206

211207
args = append(args,
212208
"-volid", VolumeID(label),
213-
"-volset-id", label,
209+
"-volset", label,
214210
)
215211
}
216212

217-
if _, err := cmd.Run("xorriso", args...); err != nil {
213+
if _, err := cmd.Run("xorrisofs", args...); err != nil {
218214
return err
219215
}
220216

0 commit comments

Comments
 (0)