Skip to content

Commit e037ef8

Browse files
committed
Add: Setup efibootimg
1 parent b45f9ea commit e037ef8

13 files changed

Lines changed: 108 additions & 53 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
title Arch Linux install medium (x86_64, UEFI)
2+
sort-key 01
3+
linux /%INSTALL_DIR%/boot/%ARCH%/vmlinuz-linux
4+
initrd /%INSTALL_DIR%/boot/intel-ucode.img
5+
initrd /%INSTALL_DIR%/boot/amd-ucode.img
6+
initrd /%INSTALL_DIR%/boot/%ARCH%/initramfs-linux.img
7+
options archisobasedir=%INSTALL_DIR% archisolabel=%ARCHISO_LABEL%
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
timeout 15
2+
default 01-archiso.conf
3+
beep on

alteriso5/utils/exec.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

alteriso5/utils/path.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package utils
2+
3+
import (
4+
"path"
5+
"strings"
6+
)
7+
8+
func Slash(elem ...string) string {
9+
arg := []string{}
10+
for _, p := range elem {
11+
arg = append(arg, strings.Split(p, "/")...)
12+
}
13+
return path.Join(arg...)
14+
}

alteriso5/work/boot/efibootconf.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package boot
2+
3+
type EfibootConf struct {
4+
Base string
5+
}
6+
7+
func ReadEfibootConf(dir string) (*EfibootConf, error) {
8+
return &EfibootConf{
9+
Base: dir,
10+
}, nil
11+
}
12+
13+
func (e *EfibootConf) ParseAndBuild(data any, out string) error {
14+
return nil
15+
}

alteriso5/work/boot/efibootimg.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"log/slog"
66

7-
"github.com/FascodeNet/alterlinux/alteriso5/utils"
7+
"github.com/Hayao0819/nahi/exutils"
88
)
99

1010
func byteToKib(b int64) int64 {
@@ -20,12 +20,12 @@ func MakeEfiBootImg(dest string, size int64) error {
2020
sizeMib := mibToKiB((byteToKib(size) + 1024) / 1024)
2121
slog.Debug("Creating EFI boot image...", "dest", dest, "size", sizeMib)
2222

23-
mkfs := utils.CommandWithStdio("mkfs.fat", "-C", "-n", "ALTERISOEFI", dest, fmt.Sprint(sizeMib))
23+
mkfs := exutils.CommandWithStdio("mkfs.fat", "-C", "-n", "ALTERISOEFI", dest, fmt.Sprint(sizeMib))
2424
if err := mkfs.Run(); err != nil {
2525
return err
2626
}
2727

28-
mmd := utils.CommandWithStdio("mmd", "-i", dest, "::/EFI", "::/EFI/BOOT")
28+
mmd := exutils.CommandWithStdio("mmd", "-i", dest, "::/EFI", "::/EFI/BOOT")
2929
if err := mmd.Run(); err != nil {
3030
return err
3131
}

alteriso5/work/build.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ func (work Work) Build(p config.Profile, t config.Target, c *cobra.Command) erro
1717
}
1818
work.Dirs = dirs
1919

20+
files, err := work.GetFiles()
21+
if err != nil {
22+
return err
23+
}
24+
work.Files = files
25+
2026
tasks := []*BuildTask{
2127
validate,
2228
makeBaseDirs,

alteriso5/work/task-bootmode-uefi-systemd.go

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import (
55
"os"
66
"path"
77

8+
"github.com/FascodeNet/alterlinux/alteriso5/utils"
89
"github.com/FascodeNet/alterlinux/alteriso5/work/boot"
910
"github.com/Hayao0819/nahi/cputils"
11+
"github.com/Hayao0819/nahi/exutils"
1012
osutils "github.com/Hayao0819/nahi/futils"
1113
)
1214

@@ -23,18 +25,18 @@ var makeCommonSystemdBoot *BuildTask = NewBuildTask("makeCommonSystemdBoot", fun
2325
// For UEFI x64
2426
if w.profile.HasBootMode(boot.UefiX64SystemdBootEsp) || w.profile.HasBootMode(boot.UefiX64SystemdBootElTorito) {
2527
efiboot_files = append(efiboot_files,
26-
path.Join(w.Dirs.Pacstrap, "usr", "lib", "systemd", "boot", "efi", "systemd-bootx64.efi"),
27-
path.Join(w.Dirs.Pacstrap, "usr", "share", "edk2-shell", "x64", "Shell_Full.efi"),
28-
path.Join(w.Dirs.Pacstrap, "boot", "memtest86+", "memtest.efi"),
29-
path.Join(w.Dirs.Pacstrap, "usr", "share", "licenses", "spdx", "GPL-2.0-only.txt"),
28+
utils.Slash(w.Dirs.Pacstrap, "/usr/lib/systemd/boot/efi/systemd-bootx64.efi"),
29+
utils.Slash(w.Dirs.Pacstrap, "/usr/share/edk2-shell/x64/Shell_Full.efi"),
30+
utils.Slash(w.Dirs.Pacstrap, "/boot/memtest86+/memtest.efi"),
31+
utils.Slash(w.Dirs.Pacstrap, "/usr/share/licenses/spdx/GPL-2.0-only.txt"),
3032
)
3133
}
3234

3335
// For UEFI ia32
3436
if w.profile.HasBootMode(boot.UefiIa32SystemdBootEsp) || w.profile.HasBootMode(boot.UefiIa32SystemdBootElTorito) {
3537
efiboot_files = append(efiboot_files,
36-
path.Join(w.Dirs.Pacstrap, "usr", "lib", "systemd", "boot", "efi", "systemd-bootia32.efi"),
37-
path.Join(w.Dirs.Pacstrap, "usr", "share", "edk2-shell", "ia32", "Shell_Full.efi"),
38+
utils.Slash(w.Dirs.Pacstrap, "/usr/lib/systemd/boot/efi/systemd-bootia32.efi"),
39+
utils.Slash(w.Dirs.Pacstrap, "/usr/share/edk2-shell/ia32/Shell_Full.efi"),
3840
)
3941
}
4042

@@ -70,10 +72,10 @@ var makeCommonSystemdBoot *BuildTask = NewBuildTask("makeCommonSystemdBoot", fun
7072
}
7173

7274
// For efiboot files
73-
if err := os.MkdirAll(path.Join(w.Base, w.target.Arch, "efiboot"), 0755); err != nil {
75+
if err := os.MkdirAll(w.Dirs.Efiboot, 0755); err != nil {
7476
return err
7577
}
76-
sizes, err := osutils.GetFileSizesInDir(path.Join(w.Base, w.target.Arch, "efiboot"))
78+
sizes, err := osutils.GetFileSizesInDir(w.Dirs.Efiboot)
7779
if err != nil {
7880
return err
7981
}
@@ -118,7 +120,8 @@ var makeCommonSystemdBootConfigIsofs *BuildTask = NewBuildTask("makeCommonSystem
118120
var makeCommonSystemdBootConfigEsp *BuildTask = NewBuildTask("makeCommonSystemdBootConfigEsp", func(w Work) error {
119121

120122
// mcopy -i "${efibootimg}" -s "${work_dir}/loader" ::/
121-
return nil
123+
cmd := exutils.CommandWithStdio("mcopy", "-i", w.Files.EfibootImg, "-s", path.Join(w.Dirs.WorkArch, "loader"), "::/")
124+
return cmd.Run()
122125
})
123126

124127
var makeUefiX64SystemdBootEsp *BuildTask = NewBuildTask("makeUefiX64SystemdBootEsp", func(w Work) error {
@@ -135,15 +138,27 @@ var makeUefiX64SystemdBootEsp *BuildTask = NewBuildTask("makeUefiX64SystemdBootE
135138
}
136139

137140
// Copy systemd-boot EFI binary to the default/fallback boot path
138-
// mcopy -i "${efibootimg}" \
139-
// "${pacstrap_dir}/usr/lib/systemd/boot/efi/systemd-bootx64.efi" ::/EFI/BOOT/BOOTx64.EFI
141+
{
142+
systemdBootEfi := utils.Slash(w.Dirs.Pacstrap, "/usr/lib/systemd/boot/efi/systemd-bootx64.efi")
143+
err := exutils.CommandWithStdio("mcopy", "-i", w.Files.EfibootImg, systemdBootEfi, "::/EFI/BOOT/BOOTx64.EFI").Run()
144+
if err != nil {
145+
return err
146+
}
147+
}
140148

141149
// Copy systemd-boot configuration files
142150
if err := w.RunOnce(makeCommonSystemdBootConfigEsp); err != nil {
143151
return err
144152
}
145153

146154
// shellx64.efi is picked up automatically when on /
155+
{
156+
shellEfi := utils.Slash(w.Dirs.Pacstrap, "/usr/share/edk2-shell/x64/Shell_Full.efi")
157+
err := exutils.CommandWithStdio("mcopy", "-i", w.Files.EfibootImg, shellEfi, "::/shellx64.efi").Run()
158+
if err != nil {
159+
return err
160+
}
161+
}
147162

148163
return nil
149164
})
@@ -158,14 +173,23 @@ var makeUefiX64SystemdBootElTorito *BuildTask = NewBuildTask("makeUefiX64Systemd
158173
}
159174

160175
// Additionally set up systemd-boot in ISO 9660. This allows creating a medium for the live environment by using
161-
// manual partitioning and simply copying the ISO 9660 file system contents.
162-
// This is not related to El Torito booting and no firmware uses these files.
163-
// _msg_info "Preparing an /EFI directory for the ISO 9660 file system..."
164-
// install -d -m 0755 -- "${isofs_dir}/EFI/BOOT"
165-
166-
// Copy systemd-boot EFI binary to the default/fallback boot path
167-
// install -m 0644 -- "${pacstrap_dir}/usr/lib/systemd/boot/efi/systemd-bootx64.efi" \
168-
// "${isofs_dir}/EFI/BOOT/BOOTx64.EFI"
176+
// manual partitioning and simply copying the ISO 9660 file system contents.
177+
// This is not related to El Torito booting and no firmware uses these files.
178+
slog.Info("Preparing an /EFI directory for the ISO 9660 file system...")
179+
if err := os.MkdirAll(path.Join(w.Dirs.Iso, "EFI", "BOOT"), 0755); err != nil {
180+
return err
181+
}
182+
183+
// Copy systemd-boot EFI binary to the default/fallback boot path
184+
systemdBootEfi := utils.Slash(w.Dirs.Pacstrap, "/usr/lib/systemd/boot/efi/systemd-bootx64.efi")
185+
t := cputils.CopyTask{
186+
Source: systemdBootEfi,
187+
Dest: path.Join(w.Dirs.Iso, "EFI", "BOOT", "BOOTx64.EFI"),
188+
Perm: 0644,
189+
}
190+
if err := cputils.CopyAll(t); err != nil {
191+
return err
192+
}
169193

170194
if err := w.RunOnce(makeCommonSystemdBootConfigIsofs); err != nil {
171195
return err

alteriso5/work/work.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Work struct {
1717
target *config.Target
1818
Cmd *cobra.Command
1919
Dirs *dirs
20+
Files *files
2021
}
2122

2223
type dirs struct {
@@ -25,6 +26,12 @@ type dirs struct {
2526
Work string
2627
Pacstrap string
2728
Iso string
29+
WorkArch string
30+
Efiboot string
31+
}
32+
33+
type files struct {
34+
EfibootImg string
2835
}
2936

3037
type configValues struct {
@@ -33,7 +40,6 @@ type configValues struct {
3340
}
3441

3542
func New(dir string) *Work {
36-
3743
w := Work{
3844
Base: dir,
3945
}
@@ -52,11 +58,21 @@ func (w *Work) GetDirs() (*dirs, error) {
5258
Work: w.Base,
5359
Pacstrap: path.Join(w.Base, w.target.Arch, "airootfs"),
5460
Iso: path.Join(w.Base, "iso"),
61+
WorkArch: path.Join(w.Base, w.target.Arch),
62+
Efiboot: path.Join(w.Base, w.target.Arch, "efiboot"),
5563
}
5664

5765
return &dv, nil
5866
}
5967

68+
func (w *Work) GetFiles() (*files, error) {
69+
fv := files{
70+
EfibootImg: path.Join(w.Dirs.Iso, "efiboot.img"),
71+
}
72+
73+
return &fv, nil
74+
}
75+
6076
func (w *Work) GetChroot() (*airootfs.Chroot, error) {
6177
return airootfs.GetChrootDir(w.Dirs.Pacstrap, w.target.Arch, path.Join(w.profile.Base, "pacman.conf"))
6278
}

profile/efiboot/loader/entries/01-archiso-x86_64-linux.conf

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)