m/n/b/mkcpio: work around lib symlink bug
The library we're using to write these, github.com/cavaliergopher/cpio,
does not handle writing symlinks. It does provide a field to put a
symlink target, but it only reads into it and ignores it while writing.
This causes symlinks in our initramfs to be broken. Work around this for
the time being by manually emitting the correct content.
Change-Id: I3e78572d122e802d4a02b48bc87dab5152b2b913
Reviewed-on: https://review.monogon.dev/c/monogon/+/1552
Tested-by: Jenkins CI
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
diff --git a/metropolis/node/build/mkcpio/main.go b/metropolis/node/build/mkcpio/main.go
index bde7082..1c9b39f 100644
--- a/metropolis/node/build/mkcpio/main.go
+++ b/metropolis/node/build/mkcpio/main.go
@@ -182,12 +182,15 @@
case *fsspec.SymbolicLink:
if err := cpioWriter.WriteHeader(&cpio.Header{
// Symlinks are 0777 by definition (from man 7 symlink on Linux)
- Mode: 0777 | cpio.TypeSymlink,
- Name: strings.TrimPrefix(i.Path, "/"),
- Linkname: i.TargetPath,
+ Mode: 0777 | cpio.TypeSymlink,
+ Name: strings.TrimPrefix(i.Path, "/"),
+ Size: int64(len(i.TargetPath)),
}); err != nil {
log.Fatalf("Failed to write cpio header for symlink %q: %v", i.Path, err)
}
+ if _, err := cpioWriter.Write([]byte(i.TargetPath)); err != nil {
+ log.Fatalf("Failed to write cpio symlink %q: %v", i.Path, err)
+ }
case *fsspec.SpecialFile:
mode := cpio.FileMode(i.Mode)
switch i.Type {