mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-09-06 17:32:26 +00:00
erofs output (#4162)
* add erofs as output option Signed-off-by: Avi Deitcher <avi@deitcher.net> * unify nearly identical functions Signed-off-by: Avi Deitcher <avi@deitcher.net> --------- Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
raw-bios: linuxkit/mkimage-raw-bios:42706053b66824d430e59edd7c195ee9b66493f4
|
raw-bios: linuxkit/mkimage-raw-bios:42706053b66824d430e59edd7c195ee9b66493f4
|
||||||
raw-efi: linuxkit/mkimage-raw-efi:eac58d3efbfe1324fc9dbdd836e44fd6cd48f93c
|
raw-efi: linuxkit/mkimage-raw-efi:eac58d3efbfe1324fc9dbdd836e44fd6cd48f93c
|
||||||
squashfs: linuxkit/mkimage-squashfs:6908664b03dc38a5ad4381a2451c7a55ae32210f
|
squashfs: linuxkit/mkimage-squashfs:6908664b03dc38a5ad4381a2451c7a55ae32210f
|
||||||
|
erofs: linuxkit/mkimage-erofs:cb41abbb3684773b14f51ab6649b2050d1241747
|
||||||
gcp: linuxkit/mkimage-gcp:7f220881aed6336708b62afea9820e436b573cea
|
gcp: linuxkit/mkimage-gcp:7f220881aed6336708b62afea9820e436b573cea
|
||||||
qcow2-efi: linuxkit/mkimage-qcow2-efi:dbabe68ec09490b5ac44bd26962d848a33e0777d
|
qcow2-efi: linuxkit/mkimage-qcow2-efi:dbabe68ec09490b5ac44bd26962d848a33e0777d
|
||||||
vhd: linuxkit/mkimage-vhd:c6f7696575081986bdda9a6b48ead70498e2aeee
|
vhd: linuxkit/mkimage-vhd:c6f7696575081986bdda9a6b48ead70498e2aeee
|
||||||
|
@@ -102,6 +102,13 @@ var outFuns = map[string]func(base string, ir io.Reader, size int, arch string)
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
"kernel+erofs": func(base string, image io.Reader, size int, arch string) error {
|
||||||
|
err := outputKernelEroFS(outputImages["erofs"], base, image, arch)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error writing kernel+erofs output: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
"kernel+iso": func(base string, image io.Reader, size int, arch string) error {
|
"kernel+iso": func(base string, image io.Reader, size int, arch string) error {
|
||||||
err := outputKernelISO(outputImages["iso"], base, image, arch)
|
err := outputKernelISO(outputImages["iso"], base, image, arch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -503,9 +510,10 @@ func outputKernelInitrdTarball(base string, kernel []byte, initrd []byte, cmdlin
|
|||||||
return tw.Close()
|
return tw.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func outputKernelSquashFS(image, base string, filesystem io.Reader, arch string) error {
|
// outputKernelImage is a unified function for ISO, SquashFS, and EroFS kernel image outputs
|
||||||
log.Debugf("output kernel/squashfs: %s %s", image, base)
|
func outputKernelImage(image, base, format, outfile string, filesystem io.Reader, arch string) error {
|
||||||
log.Infof(" %s-squashfs.img", base)
|
log.Debugf("output kernel/%s: %s %s", format, image, base)
|
||||||
|
log.Infof(" %s", outfile)
|
||||||
|
|
||||||
tr := tar.NewReader(filesystem)
|
tr := tar.NewReader(filesystem)
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
@@ -549,7 +557,7 @@ func outputKernelSquashFS(image, base string, filesystem io.Reader, arch string)
|
|||||||
}
|
}
|
||||||
_ = rootfs.Close()
|
_ = rootfs.Close()
|
||||||
|
|
||||||
output, err := os.Create(base + "-squashfs.img")
|
output, err := os.Create(outfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -562,61 +570,14 @@ func outputKernelSquashFS(image, base string, filesystem io.Reader, arch string)
|
|||||||
return dockerRun(buf, output, image, []string{fmt.Sprintf("TARGETARCH=%s", march)})
|
return dockerRun(buf, output, image, []string{fmt.Sprintf("TARGETARCH=%s", march)})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func outputKernelSquashFS(image, base string, filesystem io.Reader, arch string) error {
|
||||||
|
return outputKernelImage(image, base, "squashfs", base+"-squashfs.img", filesystem, arch)
|
||||||
|
}
|
||||||
|
|
||||||
|
func outputKernelEroFS(image, base string, filesystem io.Reader, arch string) error {
|
||||||
|
return outputKernelImage(image, base, "erofs", base+"-erofs.img", filesystem, arch)
|
||||||
|
}
|
||||||
|
|
||||||
func outputKernelISO(image, base string, filesystem io.Reader, arch string) error {
|
func outputKernelISO(image, base string, filesystem io.Reader, arch string) error {
|
||||||
log.Debugf("output kernel/iso: %s %s", image, base)
|
return outputKernelImage(image, base, "iso", base+".iso", filesystem, arch)
|
||||||
log.Infof(" %s.iso", base)
|
|
||||||
|
|
||||||
tr := tar.NewReader(filesystem)
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
rootfs := tar.NewWriter(buf)
|
|
||||||
|
|
||||||
for {
|
|
||||||
var thdr *tar.Header
|
|
||||||
thdr, err := tr.Next()
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
thdr.Format = tar.FormatPAX
|
|
||||||
switch {
|
|
||||||
case thdr.Name == "boot/kernel":
|
|
||||||
kernel, err := io.ReadAll(tr)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := os.WriteFile(base+"-kernel", kernel, os.FileMode(0644)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case thdr.Name == "boot/cmdline":
|
|
||||||
cmdline, err := io.ReadAll(tr)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := os.WriteFile(base+"-cmdline", cmdline, os.FileMode(0644)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case strings.HasPrefix(thdr.Name, "boot/"):
|
|
||||||
// skip the rest of boot/
|
|
||||||
default:
|
|
||||||
_ = rootfs.WriteHeader(thdr)
|
|
||||||
if _, err := io.Copy(rootfs, tr); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ = rootfs.Close()
|
|
||||||
|
|
||||||
output, err := os.Create(base + ".iso")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() { _ = output.Close() }()
|
|
||||||
|
|
||||||
march, err := util.MArch(arch)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return dockerRun(buf, output, image, []string{fmt.Sprintf("TARGETARCH=%s", march)})
|
|
||||||
}
|
}
|
||||||
|
24
test/cases/000_build/000_formats/014_kernel+erofs/test.sh
Normal file
24
test/cases/000_build/000_formats/014_kernel+erofs/test.sh
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# SUMMARY: Check that kernel+squashfs output format is generated
|
||||||
|
# LABELS:
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Source libraries. Uncomment if needed/defined
|
||||||
|
#. "${RT_LIB}"
|
||||||
|
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
|
||||||
|
|
||||||
|
NAME=check
|
||||||
|
|
||||||
|
clean_up() {
|
||||||
|
rm -f ${NAME}*
|
||||||
|
}
|
||||||
|
|
||||||
|
trap clean_up EXIT
|
||||||
|
|
||||||
|
linuxkit build --format kernel+erofs --name "${NAME}" ../test.yml
|
||||||
|
[ -f "${NAME}-kernel" ] || exit 1
|
||||||
|
[ -f "${NAME}-erofs.img" ] || exit 1
|
||||||
|
[ -f "${NAME}-cmdline" ] || exit 1
|
||||||
|
|
||||||
|
exit 0
|
15
tools/mkimage-erofs/Dockerfile
Normal file
15
tools/mkimage-erofs/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
FROM linuxkit/alpine:6090baae063eb5023c9601966e88df831f789a70 AS mirror
|
||||||
|
RUN mkdir -p /out/etc/apk && cp -r /etc/apk/* /out/etc/apk/
|
||||||
|
RUN apk add --no-cache --initdb -p /out \
|
||||||
|
alpine-baselayout \
|
||||||
|
busybox \
|
||||||
|
libarchive-tools \
|
||||||
|
erofs-utils \
|
||||||
|
&& true
|
||||||
|
RUN mv /out/etc/apk/repositories.upstream /out/etc/apk/repositories
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
WORKDIR /
|
||||||
|
COPY --from=mirror /out/ /
|
||||||
|
COPY . .
|
||||||
|
ENTRYPOINT [ "/make-erofs" ]
|
1
tools/mkimage-erofs/build.yml
Normal file
1
tools/mkimage-erofs/build.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
image: mkimage-erofs
|
22
tools/mkimage-erofs/make-erofs
Executable file
22
tools/mkimage-erofs/make-erofs
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
mkdir -p /tmp/rootfs
|
||||||
|
cd /tmp/rootfs
|
||||||
|
|
||||||
|
# input is a tarball of filesystem on stdin with the root filesytem
|
||||||
|
# output is a squashfs image on stdout
|
||||||
|
|
||||||
|
# extract. BSD tar auto recognises compression, unlike GNU tar
|
||||||
|
# only if stdin is a tty, if so need files volume mounted...
|
||||||
|
[ -t 0 ] || bsdtar xzf -
|
||||||
|
cd /tmp
|
||||||
|
|
||||||
|
# we want everything except the final result to stderr
|
||||||
|
(
|
||||||
|
exec 1>&2;
|
||||||
|
|
||||||
|
mkfs.erofs ./rootfs.img rootfs
|
||||||
|
)
|
||||||
|
cat rootfs.img
|
Reference in New Issue
Block a user