Skip to content

Commit 2fd09da

Browse files
committed
UKI builder
1 parent dfe9d8e commit 2fd09da

13 files changed

Lines changed: 219 additions & 152 deletions

File tree

Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ yamllint -v && yamllint -s -f colored .
1919
# =========================================================
2020
FROM golang:1.25.5-alpine AS imager-build
2121
SHELL ["/bin/ash", "-euxo", "pipefail", "-c"]
22+
RUN apk add --no-cache binutils
2223
WORKDIR /go/src
2324
COPY imager/go.mod imager/go.sum ./
2425
RUN go mod download
@@ -34,11 +35,11 @@ FROM alpine:3.23.2 AS alpine-base
3435

3536
# =========================================================
3637
FROM alpine-base AS imager
37-
# TODO: bundle objcopy (or use a golang lib) and systemd-efistub into the imager binary
38-
RUN apk add --no-cache binutils systemd-efistub
39-
COPY --from=imager-build /go/bin/imager /bin/imager
38+
# TODO: bundle systemd-efistub into the imager binary
39+
RUN apk add --no-cache systemd-efistub
40+
COPY --from=imager-build /go/bin/imager /usr/bin/imager
4041
WORKDIR /out
41-
ENTRYPOINT ["/bin/imager"]
42+
ENTRYPOINT ["/usr/bin/imager"]
4243

4344
# =========================================================
4445
FROM alpine-base AS bootable-alpine-rootfs
@@ -97,7 +98,7 @@ if [ "$UCODE" != "none" ]; then apk add --no-cache "${UCODE}-ucode"; fi;
9798
# hadolint ignore=DL3006
9899
FROM imager AS test
99100
ARG FORMAT=efi
100-
RUN --mount=from=test-rootfs,target=/system /bin/imager --format "$FORMAT"
101+
RUN --mount=from=test-rootfs,target=/system imager --format "$FORMAT"
101102

102103
# =========================================================
103104
# Generate a qemu image running our custom OS image

check_edit_pe.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/soyum2222/editPE"
8+
)
9+
10+
func main() {
11+
// open a exe file
12+
file, err := os.ReadFile("..\\hello.exe")
13+
if err != nil {
14+
panic(err)
15+
}
16+
17+
p := editPE.PE{}
18+
p.Parse(file)
19+
20+
fmt.Println(len(p.ImageSectionHeaders))
21+
22+
// add a new section size is 100 byte
23+
p.AddSection(".new", 100)
24+
25+
// save to disk
26+
f, err := os.Create("..\\hello2.exe")
27+
if err != nil {
28+
panic(err)
29+
}
30+
31+
f.Write(p.Raw)
32+
}

imager/alignaddress.go

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

imager/alignadress_test.go

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

imager/cmdline.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
package imager
22

3-
import "path/filepath"
3+
import (
4+
"os"
5+
"path/filepath"
6+
"strings"
7+
)
48

5-
func (i Image) getCmdline() string {
6-
// TODO: space-separated
7-
return filepath.Join(i.RootFsDir, "boot", "cmdline")
9+
func (i Image) getCmdline() (string, error) {
10+
path := filepath.Join(i.RootFsDir, "boot", "cmdline")
11+
data, err := os.ReadFile(path)
12+
if err != nil {
13+
return "", err
14+
}
15+
cmdline := strings.Replace(string(data), "\n", " ", -1)
16+
return cmdline, nil
817
}

imager/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.25.0
55
require (
66
github.com/cavaliergopher/cpio v1.0.1
77
github.com/otiai10/copy v1.14.1
8+
github.com/soyum2222/editPE v0.0.0-20210624070249-c6fb60af2160
89
golang.org/x/sys v0.39.0
910
)
1011

imager/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/otiai10/copy v1.14.1 h1:5/7E6qsUMBaH5AnQ0sSLzzTg1oTECmcCmT6lvF45Na8=
44
github.com/otiai10/copy v1.14.1/go.mod h1:oQwrEDDOci3IM8dJF0d8+jnbfPDllW6vUjNc3DoZm9I=
55
github.com/otiai10/mint v1.6.3 h1:87qsV/aw1F5as1eH1zS/yqHY85ANKVMgkDrf9rcxbQs=
66
github.com/otiai10/mint v1.6.3/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
7+
github.com/soyum2222/editPE v0.0.0-20210624070249-c6fb60af2160 h1:4qLL5A+f9VE4R7H5viRlBI/ax/oxkLsphN2grtAaLFY=
8+
github.com/soyum2222/editPE v0.0.0-20210624070249-c6fb60af2160/go.mod h1:++uT61R9lWv7RD8YmtMk76ck2N9FYhRkgah3bmHkSBU=
79
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
810
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
911
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=

imager/initramfs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package imager
22

33
import (
44
_ "embed"
5-
"fmt"
65
"io/fs"
76
"os"
87
"path/filepath"
@@ -110,7 +109,8 @@ func addToCpioArchive(writer *cpio.Writer, path string, fileInfo fs.FileInfo, na
110109
var err error
111110
var data []byte
112111

113-
fmt.Printf("Adding %s\n", name)
112+
// TODO: add to debug log
113+
//fmt.Printf("Adding %s\n", name)
114114

115115
mode := fileInfo.Mode()
116116

imager/kernel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package imager
33
import "path/filepath"
44

55
// Find the Linux kernel file in the root filesystem
6-
func (i Image) findKernel() (string, error) {
6+
func (i Image) findKernelPath() (string, error) {
77
pattern := filepath.Join(i.RootFsDir, "boot", "vmlinu*")
88
return findSingleFile(pattern)
99
}

imager/os.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package imager
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
)
7+
8+
// Get the kernel release information
9+
func (i Image) getOSRelease() (string, error) {
10+
path := filepath.Join(i.RootFsDir, "etc", "os-release")
11+
data, err := os.ReadFile(path)
12+
return string(data), err
13+
}

0 commit comments

Comments
 (0)