mirror of
https://github.com/kairos-io/immucore.git
synced 2025-09-15 14:41:08 +00:00
Move to Kairos logger (#474)
This commit is contained in:
14
go.mod
14
go.mod
@@ -22,7 +22,6 @@ require (
|
||||
github.com/spectrocloud-labs/herd v0.4.2
|
||||
github.com/twpayne/go-vfs/v4 v4.3.0 // v5 requires a bump to go1.20
|
||||
github.com/urfave/cli/v2 v2.27.6
|
||||
golang.org/x/sys v0.32.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
@@ -153,12 +152,13 @@ require (
|
||||
go.opentelemetry.io/otel/metric v1.34.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.34.0 // indirect
|
||||
go.uber.org/automaxprocs v1.6.0 // indirect
|
||||
golang.org/x/crypto v0.36.0 // indirect
|
||||
golang.org/x/net v0.38.0 // indirect
|
||||
golang.org/x/sync v0.12.0 // indirect
|
||||
golang.org/x/term v0.30.0 // indirect
|
||||
golang.org/x/text v0.23.0 // indirect
|
||||
golang.org/x/tools v0.31.0 // indirect
|
||||
golang.org/x/crypto v0.38.0 // indirect
|
||||
golang.org/x/net v0.40.0 // indirect
|
||||
golang.org/x/sync v0.14.0 // indirect
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/term v0.32.0 // indirect
|
||||
golang.org/x/text v0.25.0 // indirect
|
||||
golang.org/x/tools v0.33.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250212204824-5a70512c5d8b // indirect
|
||||
google.golang.org/grpc v1.70.0 // indirect
|
||||
google.golang.org/protobuf v1.36.5 // indirect
|
||||
|
32
go.sum
32
go.sum
@@ -269,10 +269,6 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/go-containerregistry v0.20.3 h1:oNx7IdTI936V8CQRveCjaxOiegWwvM7kqkbXTpyiovI=
|
||||
github.com/google/go-containerregistry v0.20.3/go.mod h1:w00pIgBRDVUDFM6bq+Qx8lwNWK+cxgCuX1vd3PIBDNI=
|
||||
github.com/google/go-tpm v0.9.3 h1:+yx0/anQuGzi+ssRqeD6WpXjW2L/V0dItUayO0i9sRc=
|
||||
github.com/google/go-tpm v0.9.3/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
|
||||
github.com/google/go-tpm v0.9.4 h1:awZRf9FwOeTunQmHoDYSHJps3ie6f1UlhS1fOdPEt1I=
|
||||
github.com/google/go-tpm v0.9.4/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
|
||||
github.com/google/go-tpm v0.9.5 h1:ocUmnDebX54dnW+MQWGQRbdaAcJELsa6PqZhJ48KwVU=
|
||||
github.com/google/go-tpm v0.9.5/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
|
||||
github.com/google/go-tpm-tools v0.3.13-0.20230620182252-4639ecce2aba h1:qJEJcuLzH5KDR0gKc0zcktin6KSAwL7+jWKBYceddTc=
|
||||
@@ -590,8 +586,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
|
||||
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
|
||||
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
|
||||
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
@@ -667,8 +663,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
|
||||
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
|
||||
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
|
||||
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
@@ -690,8 +686,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
|
||||
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
|
||||
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -750,15 +746,15 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
|
||||
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
|
||||
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
|
||||
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
|
||||
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@@ -769,8 +765,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
||||
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
||||
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
|
||||
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
@@ -827,8 +823,8 @@ golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4f
|
||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=
|
||||
golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ=
|
||||
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
|
||||
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
@@ -56,13 +56,13 @@ func (c *Chroot) Prepare() error {
|
||||
mountPoint := filepath.Join(c.path, mnt)
|
||||
if _, err := os.Stat(mnt); os.IsNotExist(err) {
|
||||
// Source doesnt exist, skip it
|
||||
Log.Debug().Str("what", mnt).Msg("Source does not exists, not mounting in chroot")
|
||||
KLog.Logger.Debug().Str("what", mnt).Msg("Source does not exists, not mounting in chroot")
|
||||
continue
|
||||
}
|
||||
|
||||
err = CreateIfNotExists(mountPoint)
|
||||
if err != nil {
|
||||
Log.Err(err).Str("what", mountPoint).Msg("Creating dir")
|
||||
KLog.Logger.Err(err).Str("what", mountPoint).Msg("Creating dir")
|
||||
return err
|
||||
}
|
||||
// Don't mount /sys, /dev or /run as MS_REC as this brings a lot of submounts for cgroups and such and those are not needed
|
||||
@@ -76,13 +76,13 @@ func (c *Chroot) Prepare() error {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
Log.Err(err).Str("where", mountPoint).Str("what", mnt).Msg("Mounting chroot bind")
|
||||
KLog.Logger.Err(err).Str("where", mountPoint).Str("what", mnt).Msg("Mounting chroot bind")
|
||||
return err
|
||||
}
|
||||
// "remount" with private so unmount events do not propagate
|
||||
err = Mount("", mountPoint, "", syscall.MS_PRIVATE, "")
|
||||
if err != nil {
|
||||
Log.Err(err).Str("where", mountPoint).Str("what", mnt).Msg("Mounting chroot bind")
|
||||
KLog.Logger.Err(err).Str("where", mountPoint).Str("what", mnt).Msg("Mounting chroot bind")
|
||||
return err
|
||||
}
|
||||
c.activeMounts = append(c.activeMounts, mountPoint)
|
||||
@@ -94,16 +94,16 @@ func (c *Chroot) Prepare() error {
|
||||
// Close will unmount all active mounts created in Prepare on reverse order.
|
||||
func (c *Chroot) Close() error {
|
||||
failures := []string{}
|
||||
Log.Debug().Strs("activeMounts", c.activeMounts).Msg("Closing chroot")
|
||||
KLog.Logger.Debug().Strs("activeMounts", c.activeMounts).Msg("Closing chroot")
|
||||
// Something mounts this due to selinux, so we need to try to manually unmount and ignore any errors
|
||||
_ = syscall.Unmount(filepath.Join(c.path, "/sys/fs/selinux"), 0)
|
||||
for len(c.activeMounts) > 0 {
|
||||
curr := c.activeMounts[len(c.activeMounts)-1]
|
||||
Log.Debug().Str("what", curr).Msg("Unmounting from chroot")
|
||||
KLog.Logger.Debug().Str("what", curr).Msg("Unmounting from chroot")
|
||||
c.activeMounts = c.activeMounts[:len(c.activeMounts)-1]
|
||||
err := syscall.Unmount(curr, 0)
|
||||
if err != nil {
|
||||
Log.Err(err).Str("what", curr).Msg("Error unmounting")
|
||||
KLog.Logger.Err(err).Str("what", curr).Msg("Error unmounting")
|
||||
failures = append(failures, curr)
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func (c *Chroot) RunCallback(callback func() error) (err error) {
|
||||
// Store current path
|
||||
currentPath, err = os.Getwd()
|
||||
if err != nil {
|
||||
Log.Err(err).Msg("Failed to get current path")
|
||||
KLog.Logger.Err(err).Msg("Failed to get current path")
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
@@ -135,7 +135,7 @@ func (c *Chroot) RunCallback(callback func() error) (err error) {
|
||||
// Store current root
|
||||
oldRootF, err = os.Open("/")
|
||||
if err != nil {
|
||||
Log.Err(err).Msg("Can't open current root")
|
||||
KLog.Logger.Err(err).Msg("Can't open current root")
|
||||
return err
|
||||
}
|
||||
defer oldRootF.Close()
|
||||
@@ -143,7 +143,7 @@ func (c *Chroot) RunCallback(callback func() error) (err error) {
|
||||
if len(c.activeMounts) == 0 {
|
||||
err = c.Prepare()
|
||||
if err != nil {
|
||||
Log.Err(err).Msg("Can't mount default mounts")
|
||||
KLog.Logger.Err(err).Msg("Can't mount default mounts")
|
||||
return err
|
||||
}
|
||||
defer func(c *Chroot) {
|
||||
@@ -153,13 +153,13 @@ func (c *Chroot) RunCallback(callback func() error) (err error) {
|
||||
// Change to new dir before running chroot!
|
||||
err = syscall.Chdir(c.path)
|
||||
if err != nil {
|
||||
Log.Err(err).Str("path", c.path).Msg("Can't chdir")
|
||||
KLog.Logger.Err(err).Str("path", c.path).Msg("Can't chdir")
|
||||
return err
|
||||
}
|
||||
|
||||
err = syscall.Chroot(c.path)
|
||||
if err != nil {
|
||||
Log.Err(err).Str("path", c.path).Msg("Can't chroot")
|
||||
KLog.Logger.Err(err).Str("path", c.path).Msg("Can't chroot")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -167,14 +167,14 @@ func (c *Chroot) RunCallback(callback func() error) (err error) {
|
||||
defer func() {
|
||||
tmpErr := oldRootF.Chdir()
|
||||
if tmpErr != nil {
|
||||
Log.Err(tmpErr).Str("path", oldRootF.Name()).Msg("Can't change to old root dir")
|
||||
KLog.Logger.Err(tmpErr).Str("path", oldRootF.Name()).Msg("Can't change to old root dir")
|
||||
if err == nil {
|
||||
err = tmpErr
|
||||
}
|
||||
} else {
|
||||
tmpErr = syscall.Chroot(".")
|
||||
if tmpErr != nil {
|
||||
Log.Err(tmpErr).Str("path", oldRootF.Name()).Msg("Can't chroot back to old root")
|
||||
KLog.Logger.Err(tmpErr).Str("path", oldRootF.Name()).Msg("Can't chroot back to old root")
|
||||
if err == nil {
|
||||
err = tmpErr
|
||||
}
|
||||
@@ -197,7 +197,7 @@ func (c *Chroot) Run(command string) (string, error) {
|
||||
}
|
||||
err = c.RunCallback(callback)
|
||||
if err != nil {
|
||||
Log.Err(err).Str("cmd", command).Msg("Cant run command on chroot")
|
||||
KLog.Logger.Err(err).Str("cmd", command).Msg("Cant run command on chroot")
|
||||
}
|
||||
return string(out), err
|
||||
}
|
||||
|
@@ -1,10 +1,9 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/kairos-io/immucore/internal/constants"
|
||||
@@ -13,7 +12,6 @@ import (
|
||||
"github.com/mudler/yip/pkg/logger"
|
||||
"github.com/mudler/yip/pkg/plugins"
|
||||
"github.com/mudler/yip/pkg/schema"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/twpayne/go-vfs/v4"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@@ -51,23 +49,12 @@ func NewYipExecutor(l logger.Interface) executor.Executor {
|
||||
return exec
|
||||
}
|
||||
|
||||
func RunStage(stage string) (bytes.Buffer, error) {
|
||||
func RunStage(stage string) error {
|
||||
var allErrors, err error
|
||||
var cmdLineYipURI string
|
||||
var buffer bytes.Buffer
|
||||
var level zerolog.Level
|
||||
|
||||
// Specific log here so it writes to a buffer and we can return that as output
|
||||
level = zerolog.InfoLevel
|
||||
// Set debug level
|
||||
debug := len(ReadCMDLineArg("rd.immucore.debug")) > 0
|
||||
debugFromEnv := os.Getenv("IMMUCORE_DEBUG") != ""
|
||||
if debug || debugFromEnv {
|
||||
level = zerolog.DebugLevel
|
||||
}
|
||||
log := MiddleLog{zerolog.New(zerolog.ConsoleWriter{Out: &buffer, TimeFormat: time.RFC3339, NoColor: true}).With().Timestamp().Logger().Level(level)}
|
||||
// Set debug logger
|
||||
yip := NewYipExecutor(log)
|
||||
yip := NewYipExecutor(KLog)
|
||||
c := ImmucoreConsole{}
|
||||
|
||||
stageBefore := fmt.Sprintf("%s.before", stage)
|
||||
@@ -117,11 +104,12 @@ func RunStage(stage string) (bytes.Buffer, error) {
|
||||
yip.Modifier(nil)
|
||||
|
||||
// Not doing anything with the errors yet, need to know which ones are permissible (no metadata, marshall errors, etc..)
|
||||
return buffer, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func onlyYAMLPartialErrors(er error) bool {
|
||||
if merr, ok := er.(*multierror.Error); ok {
|
||||
var merr *multierror.Error
|
||||
if errors.As(er, &merr) {
|
||||
for _, e := range merr.Errors {
|
||||
// Skip partial unmarshalling errors
|
||||
// TypeError is throwed when it is possible to read the yaml partially
|
||||
|
@@ -38,7 +38,7 @@ func (s ImmucoreConsole) RunTemplate(st []string, template string) error {
|
||||
for _, svc := range st {
|
||||
out, err := s.Run(fmt.Sprintf(template, svc))
|
||||
if err != nil {
|
||||
Log.Debug().Str("output", out).Msg("Run template")
|
||||
KLog.Logger.Debug().Str("output", out).Msg("Run template")
|
||||
errs = multierror.Append(errs, err)
|
||||
continue
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
// BootStateToLabelDevice lets us know the device we need to mount sysroot on based on labels.
|
||||
func BootStateToLabelDevice() string {
|
||||
runtime, err := state.NewRuntimeWithLogger(Log)
|
||||
runtime, err := state.NewRuntimeWithLogger(KLog.Logger)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
@@ -126,12 +126,12 @@ func GetTarget(dryRun bool) (string, string, error) {
|
||||
// If no image just panic here, we cannot longer continue
|
||||
if len(imgs) == 0 {
|
||||
msg := "could not get the image name from cmdline (i.e. cos-img/filename=/cOS/active.img)"
|
||||
Log.Error().Msg(msg)
|
||||
KLog.Logger.Error().Msg(msg)
|
||||
return "", "", errors.New(msg)
|
||||
}
|
||||
|
||||
Log.Debug().Str("what", imgs[0]).Msg("Target device")
|
||||
Log.Debug().Str("what", label).Msg("Target label")
|
||||
KLog.Logger.Debug().Str("what", imgs[0]).Msg("Target device")
|
||||
KLog.Logger.Debug().Str("what", label).Msg("Target label")
|
||||
return imgs[0], label, nil
|
||||
}
|
||||
|
||||
@@ -142,14 +142,14 @@ func GetTarget(dryRun bool) (string, string, error) {
|
||||
// If the error is not nil it will log it.
|
||||
func RebootOrWait(msg string, err error) {
|
||||
if err != nil {
|
||||
Log.Error().Err(err).Msg(msg)
|
||||
KLog.Logger.Error().Err(err).Msg(msg)
|
||||
}
|
||||
if len(ReadCMDLineArg("rd.immucore.rebootonfailure")) > 0 {
|
||||
Log.Warn().Msg(fmt.Sprintf("%s - Rebooting in 10 seconds", msg))
|
||||
KLog.Logger.Warn().Msg(fmt.Sprintf("%s - Rebooting in 10 seconds", msg))
|
||||
time.Sleep(10 * time.Second)
|
||||
_ = syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
|
||||
}
|
||||
Log.Warn().Msg(fmt.Sprintf("%s - Halting boot", msg))
|
||||
KLog.Logger.Warn().Msg(fmt.Sprintf("%s - Halting boot", msg))
|
||||
// Sleep forever.
|
||||
// We dont want to exit and print panics or kernel panic, so we print our message and wait for the user to ctrl+alt+del
|
||||
select {}
|
||||
@@ -169,7 +169,7 @@ func DisableImmucore() bool {
|
||||
// RootRW tells us if the mode to mount root.
|
||||
func RootRW() string {
|
||||
if len(ReadCMDLineArg("rd.cos.debugrw")) > 0 || len(ReadCMDLineArg("rd.immucore.debugrw")) > 0 {
|
||||
Log.Warn().Msg("Mounting root as RW")
|
||||
KLog.Logger.Warn().Msg("Mounting root as RW")
|
||||
return "rw"
|
||||
}
|
||||
return "ro"
|
||||
@@ -182,7 +182,7 @@ func GetState() string {
|
||||
|
||||
err := retry.Do(
|
||||
func() error {
|
||||
r, err := state.NewRuntimeWithLogger(Log)
|
||||
r, err := state.NewRuntimeWithLogger(KLog.Logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -200,21 +200,21 @@ func GetState() string {
|
||||
retry.Attempts(10),
|
||||
retry.DelayType(retry.FixedDelay),
|
||||
retry.OnRetry(func(n uint, _ error) {
|
||||
Log.Debug().Uint("try", n).Msg("Cannot get state label, retrying")
|
||||
KLog.Logger.Debug().Uint("try", n).Msg("Cannot get state label, retrying")
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
Log.Panic().Err(err).Msg("Could not get state label")
|
||||
KLog.Logger.Panic().Err(err).Msg("Could not get state label")
|
||||
}
|
||||
|
||||
Log.Debug().Str("what", label).Msg("Get state label")
|
||||
KLog.Logger.Debug().Str("what", label).Msg("Get state label")
|
||||
return filepath.Join("/dev/disk/by-label/", label)
|
||||
}
|
||||
|
||||
func IsUKI() bool {
|
||||
cmdline, err := os.ReadFile(GetHostProcCmdline())
|
||||
if err != nil {
|
||||
Log.Warn().Err(err).Msg("Error reading /proc/cmdline file " + err.Error())
|
||||
KLog.Logger.Warn().Err(err).Msg("Error reading /proc/cmdline file " + err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ func DropToEmergencyShell() {
|
||||
if err := syscall.Exec("/bin/sh", []string{"/bin/sh"}, env); err != nil {
|
||||
if err := syscall.Exec("/sysroot/bin/bash", []string{"/sysroot/bin/bash"}, env); err != nil {
|
||||
if err := syscall.Exec("/sysroot/bin/sh", []string{"/sysroot/bin/sh"}, env); err != nil {
|
||||
Log.Fatal().Msg("Could not drop to emergency shell")
|
||||
KLog.Logger.Fatal().Msg("Could not drop to emergency shell")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,98 +1,24 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/kairos-io/kairos-sdk/types"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/kairos-io/immucore/internal/constants"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/kairos-io/kairos-sdk/types"
|
||||
"os"
|
||||
)
|
||||
|
||||
var Log zerolog.Logger
|
||||
var logFile *os.File
|
||||
|
||||
// KLog is the generic KairosLogger that we pass to kcrypt calls
|
||||
var KLog types.KairosLogger
|
||||
|
||||
func CloseLogFiles() {
|
||||
logFile.Close()
|
||||
}
|
||||
|
||||
func SetLogger() {
|
||||
var loggers []io.Writer
|
||||
var level zerolog.Level
|
||||
level := "info"
|
||||
|
||||
_ = os.MkdirAll(constants.LogDir, os.ModeDir|os.ModePerm)
|
||||
logFile, err := os.Create(filepath.Join(constants.LogDir, "immucore.log"))
|
||||
if err == nil {
|
||||
loggers = append(loggers, zerolog.ConsoleWriter{Out: logFile, TimeFormat: time.RFC3339, NoColor: true})
|
||||
}
|
||||
|
||||
loggers = append(loggers, zerolog.NewConsoleWriter(func(w *zerolog.ConsoleWriter) {
|
||||
w.TimeFormat = time.RFC3339
|
||||
}))
|
||||
|
||||
multi := zerolog.MultiLevelWriter(loggers...)
|
||||
level = zerolog.InfoLevel
|
||||
// Set debug level
|
||||
debug := len(ReadCMDLineArg("rd.immucore.debug")) > 0
|
||||
debugFromEnv := os.Getenv("IMMUCORE_DEBUG") != ""
|
||||
if debug || debugFromEnv {
|
||||
level = zerolog.DebugLevel
|
||||
level = "debug"
|
||||
}
|
||||
Log = zerolog.New(multi).With().Timestamp().Logger().Level(level)
|
||||
KLog = types.NewNullLogger()
|
||||
KLog.Logger = Log
|
||||
}
|
||||
_ = os.MkdirAll(constants.LogDir, os.ModeDir|os.ModePerm)
|
||||
|
||||
// MiddleLog implements the bridge between zerolog and the logger.Interface that yip needs.
|
||||
type MiddleLog struct {
|
||||
zerolog.Logger
|
||||
}
|
||||
|
||||
func (m MiddleLog) Infof(tpl string, args ...interface{}) {
|
||||
m.Logger.Info().Msg(fmt.Sprintf(tpl, args...))
|
||||
}
|
||||
func (m MiddleLog) Info(args ...interface{}) {
|
||||
m.Logger.Info().Msg(fmt.Sprint(args...))
|
||||
}
|
||||
func (m MiddleLog) Warnf(tpl string, args ...interface{}) {
|
||||
m.Logger.Warn().Msg(fmt.Sprintf(tpl, args...))
|
||||
}
|
||||
func (m MiddleLog) Warn(args ...interface{}) {
|
||||
m.Logger.Warn().Msg(fmt.Sprint(args...))
|
||||
}
|
||||
func (m MiddleLog) Debugf(tpl string, args ...interface{}) {
|
||||
m.Logger.Debug().Msg(fmt.Sprintf(tpl, args...))
|
||||
}
|
||||
func (m MiddleLog) Debug(args ...interface{}) {
|
||||
m.Logger.Debug().Msg(fmt.Sprint(args...))
|
||||
}
|
||||
func (m MiddleLog) Errorf(tpl string, args ...interface{}) {
|
||||
m.Logger.Error().Msg(fmt.Sprintf(tpl, args...))
|
||||
}
|
||||
func (m MiddleLog) Error(args ...interface{}) {
|
||||
m.Logger.Error().Msg(fmt.Sprint(args...))
|
||||
}
|
||||
func (m MiddleLog) Fatalf(tpl string, args ...interface{}) {
|
||||
m.Logger.Fatal().Msg(fmt.Sprintf(tpl, args...))
|
||||
}
|
||||
func (m MiddleLog) Fatal(args ...interface{}) {
|
||||
m.Logger.Fatal().Msg(fmt.Sprint(args...))
|
||||
}
|
||||
func (m MiddleLog) Panicf(tpl string, args ...interface{}) {
|
||||
m.Logger.Panic().Msg(fmt.Sprintf(tpl, args...))
|
||||
}
|
||||
func (m MiddleLog) Panic(args ...interface{}) {
|
||||
m.Logger.Panic().Msg(fmt.Sprint(args...))
|
||||
}
|
||||
func (m MiddleLog) Tracef(tpl string, args ...interface{}) {
|
||||
m.Logger.Trace().Msg(fmt.Sprintf(tpl, args...))
|
||||
}
|
||||
func (m MiddleLog) Trace(args ...interface{}) {
|
||||
m.Logger.Trace().Msg(fmt.Sprint(args...))
|
||||
KLog = types.NewKairosLoggerWithExtraDirs("immucore", level, false, constants.LogDir)
|
||||
}
|
||||
|
@@ -64,10 +64,10 @@ func IsMounted(dev string) bool {
|
||||
// Does NOT need to be mounted
|
||||
// Needs full path so either /dev/sda1 or /dev/disk/by-{label,uuid}/{label,uuid} .
|
||||
func DiskFSType(s string) string {
|
||||
Log.Debug().Str("device", s).Msg("Getting disk type for device")
|
||||
KLog.Logger.Debug().Str("device", s).Msg("Getting disk type for device")
|
||||
out, e := CommandWithPath(fmt.Sprintf("blkid %s -s TYPE -o value", s))
|
||||
if e != nil {
|
||||
Log.Debug().Err(e).Msg("blkid")
|
||||
KLog.Logger.Debug().Err(e).Msg("blkid")
|
||||
}
|
||||
out = strings.Trim(strings.Trim(out, " "), "\n")
|
||||
blkidVersion, _ := CommandWithPath("blkid --help")
|
||||
@@ -75,19 +75,19 @@ func DiskFSType(s string) string {
|
||||
// BusyBox blkid returns the whole thing ¬_¬
|
||||
splitted := strings.Fields(out)
|
||||
if len(splitted) == 0 {
|
||||
Log.Debug().Str("what", out).Msg("blkid output")
|
||||
KLog.Logger.Debug().Str("what", out).Msg("blkid output")
|
||||
return "ext4"
|
||||
}
|
||||
typeFs := splitted[len(splitted)-1]
|
||||
typeFsSplitted := strings.Split(typeFs, "=")
|
||||
if len(typeFsSplitted) < 1 {
|
||||
Log.Debug().Str("what", typeFs).Msg("typeFs split")
|
||||
KLog.Logger.Debug().Str("what", typeFs).Msg("typeFs split")
|
||||
return "ext4"
|
||||
}
|
||||
finalFS := typeFsSplitted[1]
|
||||
out = strings.TrimSpace(strings.Trim(finalFS, "\""))
|
||||
}
|
||||
Log.Debug().Str("what", s).Str("type", out).Msg("Partition FS type")
|
||||
KLog.Logger.Debug().Str("what", s).Str("type", out).Msg("Partition FS type")
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func CleanSysrootForFstab(path string) string {
|
||||
if cleaned == "" {
|
||||
cleaned = "/"
|
||||
}
|
||||
Log.Debug().Str("old", path).Str("new", cleaned).Msg("Cleaning for sysroot")
|
||||
KLog.Logger.Debug().Str("old", path).Str("new", cleaned).Msg("Cleaning for sysroot")
|
||||
return cleaned
|
||||
}
|
||||
|
||||
@@ -186,10 +186,10 @@ func Fsck(device string) error {
|
||||
args = append(args, "-n")
|
||||
}
|
||||
cmd := strings.Join(args, " ")
|
||||
Log.Debug().Str("cmd", cmd).Msg("fsck command")
|
||||
KLog.Logger.Debug().Str("cmd", cmd).Msg("fsck command")
|
||||
out, e := CommandWithPath(cmd)
|
||||
if e != nil {
|
||||
Log.Debug().Err(e).Str("out", out).Str("what", device).Msg("fsck")
|
||||
KLog.Logger.Debug().Err(e).Str("out", out).Str("what", device).Msg("fsck")
|
||||
}
|
||||
return e
|
||||
}
|
||||
@@ -197,7 +197,7 @@ func Fsck(device string) error {
|
||||
// MountBasic will mount /proc and /run
|
||||
// For now proc is needed to read the cmdline fully in uki mode
|
||||
// in normal modes this should already be done by the initramfs process, so we can skip this.
|
||||
// /run is needed to start logging from the start.
|
||||
// /run is needed to start KLog.Loggerging from the start.
|
||||
func MountBasic() {
|
||||
_ = os.MkdirAll("/proc", 0755)
|
||||
if !IsMounted("/proc") {
|
||||
@@ -289,9 +289,9 @@ func GetOemLabel() string {
|
||||
return oemLabel
|
||||
}
|
||||
// We could not get it from the cmdline so get it from the runtime
|
||||
runtime, err := state.NewRuntimeWithLogger(Log)
|
||||
runtime, err := state.NewRuntimeWithLogger(KLog.Logger)
|
||||
if err != nil {
|
||||
Log.Debug().Err(err).Msg("runtime")
|
||||
KLog.Logger.Debug().Err(err).Msg("runtime")
|
||||
return ""
|
||||
}
|
||||
return runtime.OEM.FilesystemLabel
|
||||
@@ -303,9 +303,9 @@ func ActivateLVM() error {
|
||||
// This would be the same as passing rd.lvm.conf=0 in cmdline but rather do it here than add an extra option to cmdline
|
||||
_, _ = CommandWithPath("rm /etc/lvm/lvm.conf")
|
||||
out, err := CommandWithPath("lvm vgchange --refresh --sysinit")
|
||||
Log.Debug().Str("out", out).Msg("vgchange")
|
||||
KLog.Logger.Debug().Str("out", out).Msg("vgchange")
|
||||
if err != nil {
|
||||
Log.Err(err).Msg("vgchange")
|
||||
KLog.Logger.Err(err).Msg("vgchange")
|
||||
}
|
||||
|
||||
_, _ = CommandWithPath("udevadm --trigger")
|
||||
@@ -315,7 +315,7 @@ func ActivateLVM() error {
|
||||
// Force flushing the data to disk.
|
||||
func Sync() {
|
||||
// wrapper isn't necessary, but leaving it here in case
|
||||
// we want to add more logic in the future.
|
||||
// we want to add more KLog.Loggeric in the future.
|
||||
syscall.Sync()
|
||||
}
|
||||
|
||||
|
@@ -24,33 +24,33 @@ func UpgradeKcryptPartitions() error {
|
||||
for _, p := range disk.Partitions {
|
||||
if p.Type == "crypto_LUKS" {
|
||||
// Check against known partition label on persistent
|
||||
Log.Debug().Str("label", p.Label).Str("dev", p.Name).Msg("found luks partition")
|
||||
KLog.Logger.Debug().Str("label", p.Label).Str("dev", p.Name).Msg("found luks partition")
|
||||
if p.Label == "persistent" {
|
||||
// Get current UUID
|
||||
volumeUUID, err := utils.SH(fmt.Sprintf("cryptsetup luksUUID %s", filepath.Join("/dev", p.Name)))
|
||||
if err != nil {
|
||||
Log.Err(err).Send()
|
||||
KLog.Logger.Err(err).Send()
|
||||
return err
|
||||
}
|
||||
volumeUUID = strings.TrimSpace(volumeUUID)
|
||||
volumeUUIDParsed, err := uuid.FromString(volumeUUID)
|
||||
Log.Debug().Interface("volumeUUID", volumeUUIDParsed).Send()
|
||||
Log.Debug().Interface("persistentUUID", persistentUUID).Send()
|
||||
KLog.Logger.Debug().Interface("volumeUUID", volumeUUIDParsed).Send()
|
||||
KLog.Logger.Debug().Interface("persistentUUID", persistentUUID).Send()
|
||||
if err != nil {
|
||||
Log.Err(err).Send()
|
||||
KLog.Logger.Err(err).Send()
|
||||
return err
|
||||
}
|
||||
|
||||
// Check to see if it's the same already to not do anything
|
||||
if volumeUUIDParsed.String() != persistentUUID.String() {
|
||||
Log.Debug().Str("old", volumeUUIDParsed.String()).Str("new", persistentUUID.String()).Msg("Uuid is different, updating")
|
||||
KLog.Logger.Debug().Str("old", volumeUUIDParsed.String()).Str("new", persistentUUID.String()).Msg("Uuid is different, updating")
|
||||
out, err := utils.SH(fmt.Sprintf("cryptsetup luksUUID -q --uuid %s %s", persistentUUID, filepath.Join("/dev", p.Name)))
|
||||
if err != nil {
|
||||
Log.Err(err).Str("out", out).Msg("Updating uuid failed")
|
||||
KLog.Logger.Err(err).Str("out", out).Msg("Updating uuid failed")
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
Log.Debug().Msg("UUIDs are the same, not updating")
|
||||
KLog.Logger.Debug().Msg("UUIDs are the same, not updating")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
main.go
16
main.go
@@ -27,10 +27,10 @@ func main() {
|
||||
utils.SetLogger()
|
||||
|
||||
v := version.Get()
|
||||
utils.Log.Info().Str("commit", v.GitCommit).Str("compiled with", v.GoVersion).Str("version", v.Version).Msg("Immucore")
|
||||
utils.KLog.Logger.Info().Str("commit", v.GitCommit).Str("compiled_with", v.GoVersion).Str("version", v.Version).Msg("Immucore")
|
||||
|
||||
cmdline, _ := os.ReadFile(utils.GetHostProcCmdline())
|
||||
utils.Log.Debug().Str("content", string(cmdline)).Msg("cmdline")
|
||||
utils.KLog.Logger.Debug().Str("content", string(cmdline)).Msg("cmdline")
|
||||
g := herd.DAG(herd.EnableInit)
|
||||
|
||||
// Get targets and state
|
||||
@@ -48,13 +48,13 @@ func main() {
|
||||
}
|
||||
|
||||
if utils.DisableImmucore() {
|
||||
utils.Log.Info().Msg("Stanza rd.cos.disable/rd.immucore.disable on the cmdline or booting from CDROM/Netboot/Squash recovery. Disabling immucore.")
|
||||
utils.KLog.Logger.Info().Msg("Stanza rd.cos.disable/rd.immucore.disable on the cmdline or booting from CDROM/Netboot/Squash recovery. Disabling immucore.")
|
||||
err = dag.RegisterLiveMedia(st, g)
|
||||
} else if utils.IsUKI() {
|
||||
utils.Log.Info().Msg("UKI booting!")
|
||||
utils.KLog.Logger.Info().Msg("UKI booting!")
|
||||
err = dag.RegisterUKI(st, g)
|
||||
} else {
|
||||
utils.Log.Info().Msg("Booting on active/passive/recovery.")
|
||||
utils.KLog.Logger.Info().Msg("Booting on active/passive/recovery.")
|
||||
err = dag.RegisterNormalBoot(st, g)
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func main() {
|
||||
return err
|
||||
}
|
||||
|
||||
utils.Log.Info().Msg(st.WriteDAG(g))
|
||||
utils.KLog.Logger.Info().Msg(st.WriteDAG(g))
|
||||
|
||||
// Once we print the dag we can exit already
|
||||
if c.Bool("dry-run") {
|
||||
@@ -70,7 +70,7 @@ func main() {
|
||||
}
|
||||
|
||||
err = g.Run(context.Background())
|
||||
utils.Log.Info().Msg(st.WriteDAG(g))
|
||||
utils.KLog.Logger.Info().Msg(st.WriteDAG(g))
|
||||
return err
|
||||
}
|
||||
app.Flags = []cli.Flag{
|
||||
@@ -85,7 +85,7 @@ func main() {
|
||||
Action: func(_ *cli.Context) error {
|
||||
utils.SetLogger()
|
||||
v := version.Get()
|
||||
utils.Log.Info().Str("commit", v.GitCommit).Str("compiled with", v.GoVersion).Str("version", v.Version).Msg("Immucore")
|
||||
utils.KLog.Logger.Info().Str("commit", v.GitCommit).Str("compiled_with", v.GoVersion).Str("version", v.Version).Msg("Immucore")
|
||||
return nil
|
||||
},
|
||||
},
|
||||
|
@@ -81,7 +81,7 @@ func MountBind(mountpoint, root, stateTarget string) MountOperation {
|
||||
"bind",
|
||||
},
|
||||
}
|
||||
internalUtils.Log.Debug().Str("where", rootMount).Str("what", stateDir).Msg("Bind mount")
|
||||
internalUtils.KLog.Logger.Debug().Str("where", rootMount).Str("what", stateDir).Msg("Bind mount")
|
||||
tmpFstab := internalUtils.MountToFstab(tmpMount)
|
||||
tmpFstab.File = internalUtils.CleanSysrootForFstab(fmt.Sprintf("/%s", mountpoint))
|
||||
tmpFstab.Spec = internalUtils.CleanSysrootForFstab(tmpFstab.Spec)
|
||||
|
@@ -17,7 +17,7 @@ import (
|
||||
// returns the fstab entries created and an error if any.
|
||||
func MountOPWithFstab(what, where, t string, options []string, timeout time.Duration) (schema.FsTabs, error) {
|
||||
var fstab schema.FsTabs
|
||||
l := internalUtils.Log.With().Str("what", what).Str("where", where).Str("type", t).Strs("options", options).Logger()
|
||||
l := internalUtils.KLog.With().Str("what", what).Str("where", where).Str("type", t).Strs("options", options).Logger()
|
||||
// Not sure why this defaults to debuglevel when creating a sublogger, so make sure we set it properly
|
||||
debug := len(internalUtils.ReadCMDLineArg("rd.immucore.debug")) > 0
|
||||
if debug {
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/kairos-io/immucore/internal/constants"
|
||||
internalUtils "github.com/kairos-io/immucore/internal/utils"
|
||||
"github.com/moby/sys/mountinfo"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type MountOperation struct {
|
||||
@@ -21,12 +20,7 @@ func (m MountOperation) Run() error {
|
||||
defer internalUtils.Sync()
|
||||
|
||||
// Add context to sublogger
|
||||
l := internalUtils.Log.With().Str("what", m.MountOption.Source).Str("where", m.Target).Str("type", m.MountOption.Type).Strs("options", m.MountOption.Options).Logger()
|
||||
// Not sure why this defaults to debuglevel when creating a sublogger, so make sure we set it properly
|
||||
debug := len(internalUtils.ReadCMDLineArg("rd.immucore.debug")) > 0
|
||||
if debug {
|
||||
l = l.Level(zerolog.DebugLevel)
|
||||
}
|
||||
l := internalUtils.KLog.With().Str("what", m.MountOption.Source).Str("where", m.Target).Str("type", m.MountOption.Type).Strs("options", m.MountOption.Options).Logger()
|
||||
|
||||
if m.PrepareCallback != nil {
|
||||
if err := m.PrepareCallback(); err != nil {
|
||||
|
@@ -58,7 +58,7 @@ func (s *State) WriteFstab() func(context.Context) error {
|
||||
}
|
||||
_ = f.Close()
|
||||
for _, fst := range s.fstabs {
|
||||
internalUtils.Log.Debug().Str("what", fst.String()).Msg("Adding line to fstab")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", fst.String()).Msg("Adding line to fstab")
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
default:
|
||||
@@ -97,7 +97,7 @@ func (s *State) WriteDAG(g *herd.Graph) (out string) {
|
||||
// Context can be empty.
|
||||
func (s *State) LogIfError(e error, msgContext string) {
|
||||
if e != nil {
|
||||
internalUtils.Log.Err(e).Msg(msgContext)
|
||||
internalUtils.KLog.Logger.Err(e).Msg(msgContext)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (s *State) LogIfError(e error, msgContext string) {
|
||||
// Will also return the error.
|
||||
func (s *State) LogIfErrorAndReturn(e error, msgContext string) error {
|
||||
if e != nil {
|
||||
internalUtils.Log.Err(e).Msg(msgContext)
|
||||
internalUtils.KLog.Logger.Err(e).Msg(msgContext)
|
||||
}
|
||||
return e
|
||||
}
|
||||
@@ -116,8 +116,8 @@ func (s *State) LogIfErrorAndReturn(e error, msgContext string) error {
|
||||
// Will also panic.
|
||||
func (s *State) LogIfErrorAndPanic(e error, msgContext string) {
|
||||
if e != nil {
|
||||
internalUtils.Log.Err(e).Msg(msgContext)
|
||||
internalUtils.Log.Fatal().Msg(e.Error())
|
||||
internalUtils.KLog.Logger.Err(e).Msg(msgContext)
|
||||
internalUtils.KLog.Logger.Fatal().Msg(e.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func (s *State) AddToFstab(tmpFstab *fstab.Mount) {
|
||||
found := false
|
||||
for _, f := range s.fstabs {
|
||||
if f.Spec == tmpFstab.Spec {
|
||||
internalUtils.Log.Debug().Interface("existing", f).Interface("duplicated", tmpFstab).Msg("Duplicated fstab entry found, not adding")
|
||||
internalUtils.KLog.Logger.Debug().Interface("existing", f).Interface("duplicated", tmpFstab).Msg("Duplicated fstab entry found, not adding")
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ func (s *State) MountRootDagStep(g *herd.Graph) error {
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Send()
|
||||
internalUtils.KLog.Logger.Err(err).Send()
|
||||
}
|
||||
|
||||
// 2 - mount the image as a loop device
|
||||
@@ -65,7 +65,7 @@ func (s *State) MountRootDagStep(g *herd.Graph) error {
|
||||
func(_ context.Context) error {
|
||||
// Check if loop device is mounted already
|
||||
if internalUtils.IsMounted(s.TargetDevice) {
|
||||
internalUtils.Log.Debug().Str("targetImage", s.TargetImage).Str("path", s.Rootdir).Str("TargetDevice", s.TargetDevice).Msg("Not mounting loop, already mounted")
|
||||
internalUtils.KLog.Logger.Debug().Str("targetImage", s.TargetImage).Str("path", s.Rootdir).Str("TargetDevice", s.TargetDevice).Msg("Not mounting loop, already mounted")
|
||||
return nil
|
||||
}
|
||||
_ = internalUtils.Fsck(s.path("/run/initramfs/cos-state", s.TargetImage))
|
||||
@@ -77,13 +77,13 @@ func (s *State) MountRootDagStep(g *herd.Graph) error {
|
||||
// But on other it seems like it won't trigger which causes the sysroot to not be mounted as we cant find
|
||||
// the block device by the target label. Make sure we run this after mounting so we refresh the devices.
|
||||
sh, _ := utils.SH("udevadm trigger")
|
||||
internalUtils.Log.Debug().Str("output", sh).Msg("udevadm trigger")
|
||||
internalUtils.Log.Debug().Str("targetImage", s.TargetImage).Str("path", s.Rootdir).Str("TargetDevice", s.TargetDevice).Msg("mount done")
|
||||
internalUtils.KLog.Logger.Debug().Str("output", sh).Msg("udevadm trigger")
|
||||
internalUtils.KLog.Logger.Debug().Str("targetImage", s.TargetImage).Str("path", s.Rootdir).Str("TargetDevice", s.TargetDevice).Msg("mount done")
|
||||
return err
|
||||
},
|
||||
))
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Send()
|
||||
internalUtils.KLog.Logger.Err(err).Send()
|
||||
}
|
||||
|
||||
// 3 - Mount the labels as Rootdir
|
||||
@@ -110,7 +110,7 @@ func (s *State) MountRootDagStep(g *herd.Graph) error {
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Send()
|
||||
internalUtils.KLog.Logger.Err(err).Send()
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func (s *State) WaitForSysrootDagStep(g *herd.Graph) error {
|
||||
}
|
||||
}
|
||||
|
||||
internalUtils.Log.Debug().Str("timeout", timeout.String()).Msg("Waiting for sysroot")
|
||||
internalUtils.KLog.Logger.Debug().Str("timeout", timeout.String()).Msg("Waiting for sysroot")
|
||||
|
||||
cc := time.After(timeout)
|
||||
for {
|
||||
@@ -138,22 +138,22 @@ func (s *State) WaitForSysrootDagStep(g *herd.Graph) error {
|
||||
time.Sleep(2 * time.Second)
|
||||
_, err := os.Stat(s.Rootdir)
|
||||
if err != nil {
|
||||
internalUtils.Log.Debug().Str("what", s.Rootdir).Msg("Checking path existence")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", s.Rootdir).Msg("Checking path existence")
|
||||
continue
|
||||
}
|
||||
_, err = os.Stat(filepath.Join(s.Rootdir, "system"))
|
||||
if err != nil {
|
||||
internalUtils.Log.Debug().Str("what", filepath.Join(s.Rootdir, "system")).Msg("Checking path existence")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", filepath.Join(s.Rootdir, "system")).Msg("Checking path existence")
|
||||
continue
|
||||
}
|
||||
return nil
|
||||
case <-ctx.Done():
|
||||
e := fmt.Errorf("context canceled")
|
||||
internalUtils.Log.Err(e).Str("what", s.Rootdir).Msg("filepath check canceled")
|
||||
internalUtils.KLog.Logger.Err(e).Str("what", s.Rootdir).Msg("filepath check canceled")
|
||||
return e
|
||||
case <-cc:
|
||||
e := fmt.Errorf("timeout exhausted")
|
||||
internalUtils.Log.Err(e).Str("what", s.Rootdir).Msg("filepath check timeout")
|
||||
internalUtils.KLog.Logger.Err(e).Str("what", s.Rootdir).Msg("filepath check timeout")
|
||||
return e
|
||||
}
|
||||
}
|
||||
@@ -171,7 +171,7 @@ func (s *State) LVMActivation(g *herd.Graph) error {
|
||||
// Requires sysroot to be mounted as the kcrypt-challenger binary is not injected in the initramfs.
|
||||
func (s *State) RunKcrypt(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
return g.Add(cnst.OpKcryptUnlock, append(opts, herd.WithCallback(func(_ context.Context) error {
|
||||
internalUtils.Log.Debug().Msg("Unlocking with kcrypt")
|
||||
internalUtils.KLog.Logger.Debug().Msg("Unlocking with kcrypt")
|
||||
return kcrypt.UnlockAll(false, internalUtils.KLog)
|
||||
}))...)
|
||||
}
|
||||
|
@@ -28,19 +28,19 @@ func (s *State) WriteSentinelDagStep(g *herd.Graph, deps ...string) error {
|
||||
herd.WithCallback(func(_ context.Context) error {
|
||||
var sentinel string
|
||||
|
||||
internalUtils.Log.Debug().Msg("Will now create /run/cos is not exists")
|
||||
internalUtils.KLog.Logger.Debug().Msg("Will now create /run/cos is not exists")
|
||||
err := internalUtils.CreateIfNotExists("/run/cos/")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("failed to create /run/cos")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("failed to create /run/cos")
|
||||
return err
|
||||
}
|
||||
|
||||
internalUtils.Log.Debug().Msg("Will now create the runtime object")
|
||||
runtime, err := state.NewRuntimeWithLogger(internalUtils.Log)
|
||||
internalUtils.KLog.Logger.Debug().Msg("Will now create the runtime object")
|
||||
runtime, err := state.NewRuntimeWithLogger(internalUtils.KLog.Logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
internalUtils.Log.Debug().Msg("Bootstate: " + string(runtime.BootState))
|
||||
internalUtils.KLog.Logger.Debug().Msg("Bootstate: " + string(runtime.BootState))
|
||||
|
||||
switch runtime.BootState {
|
||||
case state.Active:
|
||||
@@ -57,9 +57,9 @@ func (s *State) WriteSentinelDagStep(g *herd.Graph, deps ...string) error {
|
||||
sentinel = string(state.Unknown)
|
||||
}
|
||||
|
||||
internalUtils.Log.Debug().Str("BootState", string(runtime.BootState)).Msg("The BootState was")
|
||||
internalUtils.KLog.Logger.Debug().Str("BootState", string(runtime.BootState)).Msg("The BootState was")
|
||||
|
||||
internalUtils.Log.Info().Str("to", sentinel).Msg("Setting sentinel file")
|
||||
internalUtils.KLog.Logger.Info().Str("to", sentinel).Msg("Setting sentinel file")
|
||||
err = os.WriteFile(filepath.Join("/run/cos/", sentinel), []byte("1"), os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -70,14 +70,14 @@ func (s *State) WriteSentinelDagStep(g *herd.Graph, deps ...string) error {
|
||||
if strings.Contains(string(cmdline), "rd.immucore.uki") {
|
||||
state.DetectUKIboot(string(cmdline))
|
||||
// sentinel for uki mode
|
||||
if state.EfiBootFromInstall(internalUtils.Log) {
|
||||
internalUtils.Log.Info().Str("to", "uki_boot_mode").Msg("Setting sentinel file")
|
||||
if state.EfiBootFromInstall(internalUtils.KLog.Logger) {
|
||||
internalUtils.KLog.Logger.Info().Str("to", "uki_boot_mode").Msg("Setting sentinel file")
|
||||
err = os.WriteFile("/run/cos/uki_boot_mode", []byte("1"), os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
internalUtils.Log.Info().Str("to", "uki_install_mode").Msg("Setting sentinel file")
|
||||
internalUtils.KLog.Logger.Info().Str("to", "uki_install_mode").Msg("Setting sentinel file")
|
||||
err := os.WriteFile("/run/cos/uki_install_mode", []byte("1"), os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -109,58 +109,31 @@ func (s *State) RunStageOp(stage string) func(context.Context) error {
|
||||
if _, err := os.Stat("/system"); os.IsNotExist(err) {
|
||||
err = os.Symlink("/sysroot/system", "/system")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("creating symlink")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("creating symlink")
|
||||
}
|
||||
}
|
||||
if _, err := os.Stat("/oem"); os.IsNotExist(err) {
|
||||
err = os.Symlink("/sysroot/oem", "/oem")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("creating symlink")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("creating symlink")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internalUtils.Log.Info().Msg("Running rootfs stage")
|
||||
output, _ := internalUtils.RunStage("rootfs")
|
||||
internalUtils.Log.Debug().Msg(output.String())
|
||||
err := internalUtils.CreateIfNotExists(cnst.LogDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
e := os.WriteFile(filepath.Join(cnst.LogDir, "rootfs_stage.log"), output.Bytes(), os.ModePerm)
|
||||
if e != nil {
|
||||
internalUtils.Log.Err(e).Msg("Writing log for rootfs stage")
|
||||
}
|
||||
return err
|
||||
internalUtils.KLog.Logger.Info().Msg("Running rootfs stage")
|
||||
_ = internalUtils.RunStage("rootfs")
|
||||
return nil
|
||||
case "initramfs":
|
||||
// Not sure if it will work under UKI where the s.Rootdir is the current root already
|
||||
internalUtils.Log.Info().Msg("Running initramfs stage")
|
||||
internalUtils.KLog.Logger.Info().Msg("Running initramfs stage")
|
||||
if internalUtils.IsUKI() {
|
||||
output, _ := internalUtils.RunStage("initramfs")
|
||||
internalUtils.Log.Debug().Msg(output.String())
|
||||
err := internalUtils.CreateIfNotExists(cnst.LogDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
e := os.WriteFile(filepath.Join(cnst.LogDir, "initramfs_stage.log"), output.Bytes(), os.ModePerm)
|
||||
if e != nil {
|
||||
internalUtils.Log.Err(e).Msg("Writing log for initramfs stage")
|
||||
}
|
||||
return err
|
||||
_ = internalUtils.RunStage("initramfs")
|
||||
return nil
|
||||
} else {
|
||||
chroot := internalUtils.NewChroot(s.Rootdir)
|
||||
return chroot.RunCallback(func() error {
|
||||
output, _ := internalUtils.RunStage("initramfs")
|
||||
internalUtils.Log.Debug().Msg(output.String())
|
||||
err := internalUtils.CreateIfNotExists(cnst.LogDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
e := os.WriteFile(filepath.Join(cnst.LogDir, "initramfs_stage.log"), output.Bytes(), os.ModePerm)
|
||||
if e != nil {
|
||||
internalUtils.Log.Err(e).Msg("Writing log for initramfs stage")
|
||||
}
|
||||
return err
|
||||
_ = internalUtils.RunStage("initramfs")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -181,7 +154,7 @@ func (s *State) LoadEnvLayoutDagStep(g *herd.Graph, opts ...herd.OpOption) error
|
||||
|
||||
env, err := internalUtils.ReadEnv("/run/cos/cos-layout.env")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("Reading env")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("Reading env")
|
||||
return err
|
||||
}
|
||||
// populate from env here
|
||||
@@ -236,13 +209,13 @@ func (s *State) MountOemDagStep(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
return g.Add(cnst.OpMountOEM,
|
||||
append(opts,
|
||||
herd.WithCallback(func(ctx context.Context) error {
|
||||
runtime, _ := state.NewRuntimeWithLogger(internalUtils.Log)
|
||||
runtime, _ := state.NewRuntimeWithLogger(internalUtils.KLog.Logger)
|
||||
if runtime.BootState == state.LiveCD {
|
||||
internalUtils.Log.Debug().Msg("Livecd mode detected, won't mount OEM")
|
||||
internalUtils.KLog.Logger.Debug().Msg("Livecd mode detected, won't mount OEM")
|
||||
return nil
|
||||
}
|
||||
if internalUtils.GetOemLabel() == "" {
|
||||
internalUtils.Log.Debug().Msg("OEM label from cmdline empty, won't mount OEM")
|
||||
internalUtils.KLog.Logger.Debug().Msg("OEM label from cmdline empty, won't mount OEM")
|
||||
return nil
|
||||
}
|
||||
op := func(_ context.Context) error {
|
||||
@@ -304,19 +277,19 @@ func (s *State) MountCustomOverlayDagStep(g *herd.Graph, opts ...herd.OpOption)
|
||||
herd.WithCallback(
|
||||
func(_ context.Context) error {
|
||||
var multierr *multierror.Error
|
||||
internalUtils.Log.Debug().Strs("dirs", s.OverlayDirs).Msg("Mounting overlays")
|
||||
internalUtils.KLog.Logger.Debug().Strs("dirs", s.OverlayDirs).Msg("Mounting overlays")
|
||||
for _, p := range s.OverlayDirs {
|
||||
internalUtils.Log.Debug().Str("what", p).Msg("Overlay mount start")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", p).Msg("Overlay mount start")
|
||||
op := op.MountWithBaseOverlay(p, s.Rootdir, "/run/overlay")
|
||||
err := op.Run()
|
||||
// Append to errors only if it's not an already mounted error
|
||||
if err != nil && !errors.Is(err, cnst.ErrAlreadyMounted) {
|
||||
internalUtils.Log.Err(err).Msg("overlay mount")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("overlay mount")
|
||||
multierr = multierror.Append(multierr, err)
|
||||
continue
|
||||
}
|
||||
s.fstabs = append(s.fstabs, &op.FstabEntry)
|
||||
internalUtils.Log.Debug().Str("what", p).Msg("Overlay mount done")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", p).Msg("Overlay mount done")
|
||||
}
|
||||
return multierr.ErrorOrNil()
|
||||
},
|
||||
@@ -329,10 +302,10 @@ func (s *State) MountCustomMountsDagStep(g *herd.Graph, opts ...herd.OpOption) e
|
||||
return g.Add(cnst.OpCustomMounts, append(opts, herd.WithDeps(cnst.OpLoadConfig),
|
||||
herd.WithCallback(func(_ context.Context) error {
|
||||
var err *multierror.Error
|
||||
internalUtils.Log.Debug().Interface("mounts", s.CustomMounts).Msg("Mounting custom mounts")
|
||||
internalUtils.KLog.Logger.Debug().Interface("mounts", s.CustomMounts).Msg("Mounting custom mounts")
|
||||
|
||||
for what, where := range s.CustomMounts {
|
||||
internalUtils.Log.Debug().Str("what", what).Str("where", where).Msg("Custom mount start")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", what).Str("where", where).Msg("Custom mount start")
|
||||
// TODO: scan for the custom mount disk to know the underlying fs and set it proper
|
||||
fstype := "ext4"
|
||||
mountOptions := []string{"ro"}
|
||||
@@ -356,9 +329,9 @@ func (s *State) MountCustomMountsDagStep(g *herd.Graph, opts ...herd.OpOption) e
|
||||
if err2 != nil && !strings.Contains(what, "COS_OEM") {
|
||||
err = multierror.Append(err, err2)
|
||||
}
|
||||
internalUtils.Log.Debug().Str("what", what).Str("where", where).Msg("Custom mount done")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", what).Str("where", where).Msg("Custom mount done")
|
||||
}
|
||||
internalUtils.Log.Warn().Err(err.ErrorOrNil()).Send()
|
||||
internalUtils.KLog.Logger.Warn().Err(err.ErrorOrNil()).Send()
|
||||
|
||||
return err.ErrorOrNil()
|
||||
}),
|
||||
@@ -373,10 +346,10 @@ func (s *State) MountCustomBindsDagStep(g *herd.Graph, opts ...herd.OpOption) er
|
||||
herd.WithCallback(
|
||||
func(_ context.Context) error {
|
||||
var err *multierror.Error
|
||||
internalUtils.Log.Debug().Strs("mounts", s.BindMounts).Msg("Mounting binds")
|
||||
internalUtils.KLog.Logger.Debug().Strs("mounts", s.BindMounts).Msg("Mounting binds")
|
||||
|
||||
for _, p := range s.SortedBindMounts() {
|
||||
internalUtils.Log.Debug().Str("what", p).Msg("Bind mount start")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", p).Msg("Bind mount start")
|
||||
op := op.MountBind(p, s.Rootdir, s.StateDir)
|
||||
err2 := op.Run()
|
||||
if err2 == nil {
|
||||
@@ -385,12 +358,12 @@ func (s *State) MountCustomBindsDagStep(g *herd.Graph, opts ...herd.OpOption) er
|
||||
}
|
||||
// Append to errors only if it's not an already mounted error
|
||||
if err2 != nil && !errors.Is(err2, cnst.ErrAlreadyMounted) {
|
||||
internalUtils.Log.Err(err2).Send()
|
||||
internalUtils.KLog.Logger.Err(err2).Send()
|
||||
err = multierror.Append(err, err2)
|
||||
}
|
||||
internalUtils.Log.Debug().Str("what", p).Msg("Bind mount end")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", p).Msg("Bind mount end")
|
||||
}
|
||||
internalUtils.Log.Warn().Err(err.ErrorOrNil()).Send()
|
||||
internalUtils.KLog.Logger.Warn().Err(err.ErrorOrNil()).Send()
|
||||
return err.ErrorOrNil()
|
||||
},
|
||||
),
|
||||
@@ -403,8 +376,8 @@ func (s *State) EnableSysExtensions(g *herd.Graph, opts ...herd.OpOption) error
|
||||
return g.Add(cnst.OpUkiCopySysExtensions, append(opts, herd.WithCallback(func(_ context.Context) error {
|
||||
// If uki and we are not booting from install media then do nothing
|
||||
if internalUtils.IsUKI() {
|
||||
if !state.EfiBootFromInstall(internalUtils.Log) {
|
||||
internalUtils.Log.Debug().Msg("Not copying sysextensions as we think we are booting from removable media")
|
||||
if !state.EfiBootFromInstall(internalUtils.KLog.Logger) {
|
||||
internalUtils.KLog.Logger.Debug().Msg("Not copying sysextensions as we think we are booting from removable media")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -417,13 +390,13 @@ func (s *State) EnableSysExtensions(g *herd.Graph, opts ...herd.OpOption) error
|
||||
if _, err := os.Stat(cnst.DestSysExtDir); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(cnst.DestSysExtDir, 0755)
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("Creating sysext dir")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("Creating sysext dir")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// At this point the extensions dir should be available
|
||||
r, err := state.NewRuntimeWithLogger(internalUtils.Log)
|
||||
r, err := state.NewRuntimeWithLogger(internalUtils.KLog.Logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -437,7 +410,7 @@ func (s *State) EnableSysExtensions(g *herd.Graph, opts ...herd.OpOption) error
|
||||
case state.Recovery:
|
||||
dir = fmt.Sprintf("%s/%s", cnst.SourceSysExtDir, "recovery")
|
||||
default:
|
||||
internalUtils.Log.Debug().Str("state", string(r.BootState)).Msg("Not copying sysextensions as we are not in a state that we know off")
|
||||
internalUtils.KLog.Logger.Debug().Str("state", string(r.BootState)).Msg("Not copying sysextensions as we are not in a state that we know off")
|
||||
return nil
|
||||
|
||||
}
|
||||
@@ -460,8 +433,8 @@ func (s *State) EnableSysExtensions(g *herd.Graph, opts ...herd.OpOption) error
|
||||
output, err := internalUtils.CommandWithPath(fmt.Sprintf("systemd-dissect --validate %s %s", cnst.SysextDefaultPolicy, s.path(filepath.Join(dir, entry.Name()))))
|
||||
if err != nil {
|
||||
// If the file didn't pass the validation, we don't copy it
|
||||
internalUtils.Log.Warn().Str("src", s.path(filepath.Join(dir, entry.Name()))).Msg("Sysextension does not pass validation")
|
||||
internalUtils.Log.Debug().Err(err).Str("src", s.path(filepath.Join(dir, entry.Name()))).Str("output", output).Msg("Validating sysextension")
|
||||
internalUtils.KLog.Logger.Warn().Str("src", s.path(filepath.Join(dir, entry.Name()))).Msg("Sysextension does not pass validation")
|
||||
internalUtils.KLog.Logger.Debug().Err(err).Str("src", s.path(filepath.Join(dir, entry.Name()))).Str("output", output).Msg("Validating sysextension")
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -470,16 +443,16 @@ func (s *State) EnableSysExtensions(g *herd.Graph, opts ...herd.OpOption) error
|
||||
// specific boot state dir have the same file, and we dont want to fail at this point, just warn and continue
|
||||
if _, err := os.Stat(filepath.Join(cnst.DestSysExtDir, entry.Name())); !os.IsNotExist(err) {
|
||||
// If it exists, we can just skip it
|
||||
internalUtils.Log.Warn().Str("file", filepath.Join(cnst.DestSysExtDir, entry.Name())).Msg("Skipping sysextension as its already enabled")
|
||||
internalUtils.KLog.Logger.Warn().Str("file", filepath.Join(cnst.DestSysExtDir, entry.Name())).Msg("Skipping sysextension as its already enabled")
|
||||
continue
|
||||
}
|
||||
// it has to link to the final dir after initramfs, so we avoid setting s.path here for the target
|
||||
err = os.Symlink(filepath.Join(dir, entry.Name()), filepath.Join(cnst.DestSysExtDir, entry.Name()))
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("Creating symlink")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("Creating symlink")
|
||||
return err
|
||||
}
|
||||
internalUtils.Log.Debug().Str("what", entry.Name()).Msg("Enabled sysextension")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", entry.Name()).Msg("Enabled sysextension")
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -140,20 +140,20 @@ func (s *State) UKIMountBaseSystem(g *herd.Graph) error {
|
||||
} {
|
||||
e := os.MkdirAll(dir, perm)
|
||||
if e != nil {
|
||||
internalUtils.Log.Err(e).Str("dir", dir).Interface("permissions", perm).Msg("Creating dir")
|
||||
internalUtils.KLog.Logger.Err(e).Str("dir", dir).Interface("permissions", perm).Msg("Creating dir")
|
||||
}
|
||||
}
|
||||
for _, m := range mounts {
|
||||
e := os.MkdirAll(m.where, 0755)
|
||||
if e != nil {
|
||||
err = multierror.Append(err, e)
|
||||
internalUtils.Log.Err(e).Msg("Creating dir")
|
||||
internalUtils.KLog.Logger.Err(e).Msg("Creating dir")
|
||||
}
|
||||
|
||||
e = internalUtils.Mount(m.what, m.where, m.fs, m.flags, m.data)
|
||||
if e != nil {
|
||||
err = multierror.Append(err, e)
|
||||
internalUtils.Log.Err(e).Str("what", m.what).Str("where", m.where).Str("type", m.fs).Msg("Mounting")
|
||||
internalUtils.KLog.Logger.Err(e).Str("what", m.what).Str("where", m.where).Str("type", m.fs).Msg("Mounting")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,25 +177,25 @@ func (s *State) UkiPivotToSysroot(g *herd.Graph) error {
|
||||
var err error
|
||||
// Create the new sysroot and move to it
|
||||
// We need the sysroot to NOT be of type rootfs, otherwise kubernetes stuff doesnt really work
|
||||
internalUtils.Log.Debug().Str("what", s.path(cnst.UkiSysrootDir)).Msg("Creating sysroot dir")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", s.path(cnst.UkiSysrootDir)).Msg("Creating sysroot dir")
|
||||
err = os.MkdirAll(s.path(cnst.UkiSysrootDir), 0755) // #nosec G301 -- Sysroot needs to be 755 to be world readable
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("creating sysroot dir")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("creating sysroot dir")
|
||||
internalUtils.DropToEmergencyShell()
|
||||
}
|
||||
|
||||
// Mount a tmpfs under sysroot
|
||||
internalUtils.Log.Debug().Msg("Mounting tmpfs on sysroot")
|
||||
internalUtils.KLog.Logger.Debug().Msg("Mounting tmpfs on sysroot")
|
||||
err = internalUtils.Mount("tmpfs", s.path(cnst.UkiSysrootDir), "tmpfs", 0, "")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("mounting tmpfs on sysroot")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("mounting tmpfs on sysroot")
|
||||
internalUtils.DropToEmergencyShell()
|
||||
}
|
||||
|
||||
// Move all the dirs in root FS that are not a mountpoint to the new root via cp -R
|
||||
rootDirs, err := os.ReadDir(s.Rootdir)
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("reading rootdir content")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("reading rootdir content")
|
||||
}
|
||||
|
||||
var mountPoints []string
|
||||
@@ -216,22 +216,22 @@ func (s *State) UkiPivotToSysroot(g *herd.Graph) error {
|
||||
}
|
||||
// If the directory has the same device as its parent, it's not a mount point.
|
||||
if fileInfo.Sys().(*syscall.Stat_t).Dev == parentInfo.Sys().(*syscall.Stat_t).Dev {
|
||||
internalUtils.Log.Debug().Str("what", path).Msg("simple directory")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", path).Msg("simple directory")
|
||||
err = os.MkdirAll(filepath.Join(s.path(cnst.UkiSysrootDir), path), fileInfo.Mode())
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Str("what", filepath.Join(s.path(cnst.UkiSysrootDir), path)).Msg("mkdir")
|
||||
internalUtils.KLog.Logger.Err(err).Str("what", filepath.Join(s.path(cnst.UkiSysrootDir), path)).Msg("mkdir")
|
||||
return err
|
||||
}
|
||||
|
||||
// Copy it over
|
||||
out, err := internalUtils.CommandWithPath(fmt.Sprintf("cp -a %s %s", s.path(path), s.path(cnst.UkiSysrootDir)))
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Str("out", out).Str("what", s.path(path)).Str("where", s.path(cnst.UkiSysrootDir)).Msg("copying dir into sysroot")
|
||||
internalUtils.KLog.Logger.Err(err).Str("out", out).Str("what", s.path(path)).Str("where", s.path(cnst.UkiSysrootDir)).Msg("copying dir into sysroot")
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
internalUtils.Log.Debug().Str("what", path).Msg("mount point")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", path).Msg("mount point")
|
||||
mountPoints = append(mountPoints, s.path(path))
|
||||
|
||||
continue
|
||||
@@ -249,16 +249,16 @@ func (s *State) UkiPivotToSysroot(g *herd.Graph) error {
|
||||
symlinkPath := s.path(filepath.Join(cnst.UkiSysrootDir, file.Name()))
|
||||
err = os.Symlink(target, symlinkPath)
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Str("from", target).Str("to", symlinkPath).Msg("Symlink")
|
||||
internalUtils.KLog.Logger.Err(err).Str("from", target).Str("to", symlinkPath).Msg("Symlink")
|
||||
internalUtils.DropToEmergencyShell()
|
||||
}
|
||||
internalUtils.Log.Debug().Str("from", target).Str("to", symlinkPath).Msg("Symlinked file")
|
||||
internalUtils.KLog.Logger.Debug().Str("from", target).Str("to", symlinkPath).Msg("Symlinked file")
|
||||
} else {
|
||||
// If its a file in the root dir just copy it over
|
||||
content, _ := os.ReadFile(s.path(file.Name()))
|
||||
newFilePath := s.path(filepath.Join(cnst.UkiSysrootDir, file.Name()))
|
||||
_ = os.WriteFile(newFilePath, content, info.Mode())
|
||||
internalUtils.Log.Debug().Str("from", s.path(file.Name())).Str("to", newFilePath).Msg("Copied file")
|
||||
internalUtils.KLog.Logger.Debug().Str("from", s.path(file.Name())).Str("to", newFilePath).Msg("Copied file")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,52 +268,52 @@ func (s *State) UkiPivotToSysroot(g *herd.Graph) error {
|
||||
if _, err := os.Stat(newDir); err != nil {
|
||||
err = os.MkdirAll(newDir, 0755)
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Str("what", newDir).Msg("mkdir")
|
||||
internalUtils.KLog.Logger.Err(err).Str("what", newDir).Msg("mkdir")
|
||||
}
|
||||
}
|
||||
|
||||
err = internalUtils.Mount(d, newDir, "", syscall.MS_MOVE, "")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Str("what", d).Str("where", newDir).Msg("move mount")
|
||||
internalUtils.KLog.Logger.Err(err).Str("what", d).Str("where", newDir).Msg("move mount")
|
||||
continue
|
||||
}
|
||||
internalUtils.Log.Debug().Str("from", d).Str("to", newDir).Msg("Mount moved")
|
||||
internalUtils.KLog.Logger.Debug().Str("from", d).Str("to", newDir).Msg("Mount moved")
|
||||
}
|
||||
|
||||
internalUtils.Log.Debug().Str("to", s.path(cnst.UkiSysrootDir)).Msg("Changing dir")
|
||||
internalUtils.KLog.Logger.Debug().Str("to", s.path(cnst.UkiSysrootDir)).Msg("Changing dir")
|
||||
if err = syscall.Chdir(s.path(cnst.UkiSysrootDir)); err != nil {
|
||||
internalUtils.Log.Err(err).Msg("chdir")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("chdir")
|
||||
internalUtils.DropToEmergencyShell()
|
||||
}
|
||||
|
||||
internalUtils.Log.Debug().Str("what", s.path(cnst.UkiSysrootDir)).Str("where", "/").Msg("Moving mount")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", s.path(cnst.UkiSysrootDir)).Str("where", "/").Msg("Moving mount")
|
||||
if err = internalUtils.Mount(s.path(cnst.UkiSysrootDir), "/", "", syscall.MS_MOVE, ""); err != nil {
|
||||
internalUtils.Log.Err(err).Msg("mount move")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("mount move")
|
||||
internalUtils.DropToEmergencyShell()
|
||||
}
|
||||
|
||||
internalUtils.Log.Debug().Str("to", ".").Msg("Chrooting")
|
||||
internalUtils.KLog.Logger.Debug().Str("to", ".").Msg("Chrooting")
|
||||
if err = syscall.Chroot("."); err != nil {
|
||||
internalUtils.Log.Err(err).Msg("chroot")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("chroot")
|
||||
internalUtils.DropToEmergencyShell()
|
||||
}
|
||||
|
||||
ext := "enter-initrd"
|
||||
pcrErr := UKIExtendPCR(ext)
|
||||
if pcrErr != nil {
|
||||
internalUtils.Log.Err(pcrErr).Str("ext", ext).Msg("extend-pcr")
|
||||
internalUtils.KLog.Logger.Err(pcrErr).Str("ext", ext).Msg("extend-pcr")
|
||||
}
|
||||
|
||||
pcrErr = os.MkdirAll("/run/systemd", 0755) // #nosec G301 -- Original dir has this permissions
|
||||
if pcrErr != nil {
|
||||
internalUtils.Log.Err(pcrErr).Msg("Creating /run/systemd dir")
|
||||
internalUtils.KLog.Logger.Err(pcrErr).Msg("Creating /run/systemd dir")
|
||||
}
|
||||
// This dir is created by systemd-stub and passed to the kernel as a cpio archive
|
||||
// that gets mounted in the initial ramdisk where we run immucore from
|
||||
// It contains the tpm public key and signatures of the current uki
|
||||
out, pcrErr := internalUtils.CommandWithPath("cp /.extra/* /run/systemd/")
|
||||
if pcrErr != nil {
|
||||
internalUtils.Log.Err(pcrErr).Str("out", out).Msg("Copying extra files")
|
||||
internalUtils.KLog.Logger.Err(pcrErr).Str("out", out).Msg("Copying extra files")
|
||||
}
|
||||
return err
|
||||
}))
|
||||
@@ -332,22 +332,22 @@ func (s *State) UKIUdevDaemon(g *herd.Graph) error {
|
||||
}
|
||||
cmd := fmt.Sprintf("%s --daemon", udevBin)
|
||||
out, err := internalUtils.CommandWithPath(cmd)
|
||||
internalUtils.Log.Debug().Str("out", out).Str("cmd", cmd).Msg("Udev daemon")
|
||||
internalUtils.KLog.Logger.Debug().Str("out", out).Str("cmd", cmd).Msg("Udev daemon")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("Udev daemon")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("Udev daemon")
|
||||
return err
|
||||
}
|
||||
out, err = internalUtils.CommandWithPath("udevadm trigger")
|
||||
internalUtils.Log.Debug().Str("out", out).Msg("Udev trigger")
|
||||
internalUtils.KLog.Logger.Debug().Str("out", out).Msg("Udev trigger")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("Udev trigger")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("Udev trigger")
|
||||
return err
|
||||
}
|
||||
|
||||
out, err = internalUtils.CommandWithPath("udevadm settle")
|
||||
internalUtils.Log.Debug().Str("out", out).Msg("Udev settle")
|
||||
internalUtils.KLog.Logger.Debug().Str("out", out).Msg("Udev settle")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("Udev settle")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("Udev settle")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -364,15 +364,15 @@ func (s *State) UKILoadKernelModules(g *herd.Graph) error {
|
||||
herd.WithCallback(func(_ context.Context) error {
|
||||
drivers, err := kdetect.ProbeKernelModules("")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("Detecting needed modules")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("Detecting needed modules")
|
||||
}
|
||||
drivers = append(drivers, cnst.GenericKernelDrivers()...)
|
||||
internalUtils.Log.Debug().Strs("drivers", drivers).Msg("Detecting needed modules")
|
||||
internalUtils.KLog.Logger.Debug().Strs("drivers", drivers).Msg("Detecting needed modules")
|
||||
for _, driver := range drivers {
|
||||
cmd := fmt.Sprintf("modprobe %s", driver)
|
||||
out, err := internalUtils.CommandWithPath(cmd)
|
||||
if err != nil {
|
||||
internalUtils.Log.Debug().Err(err).Str("out", out).Msg("modprobe")
|
||||
internalUtils.KLog.Logger.Debug().Err(err).Str("out", out).Msg("modprobe")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -384,12 +384,12 @@ func (s *State) UKILoadKernelModules(g *herd.Graph) error {
|
||||
func (s *State) UKIUnlock(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
return g.Add(cnst.OpUkiKcrypt, append(opts, herd.WithCallback(func(_ context.Context) error {
|
||||
// Set full path on uki to get all the binaries
|
||||
if !state.EfiBootFromInstall(internalUtils.Log) {
|
||||
internalUtils.Log.Debug().Msg("Not unlocking disks as we think we are booting from removable media")
|
||||
if !state.EfiBootFromInstall(internalUtils.KLog.Logger) {
|
||||
internalUtils.KLog.Logger.Debug().Msg("Not unlocking disks as we think we are booting from removable media")
|
||||
return nil
|
||||
}
|
||||
_ = os.Setenv("PATH", "/usr/bin:/usr/sbin:/bin:/sbin")
|
||||
internalUtils.Log.Debug().Msg("Will now try to unlock partitions")
|
||||
internalUtils.KLog.Logger.Debug().Msg("Will now try to unlock partitions")
|
||||
err := kcrypt.UnlockAll(true, internalUtils.KLog)
|
||||
if err != nil {
|
||||
internalUtils.RebootOrWait("Unlocking partitions failed", err)
|
||||
@@ -403,19 +403,19 @@ func (s *State) UKIUnlock(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
func (s *State) UKIMountLiveCd(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
return g.Add(cnst.OpUkiMountLivecd, append(opts, herd.WithCallback(func(_ context.Context) error {
|
||||
// If we are booting from Install Media
|
||||
if state.EfiBootFromInstall(internalUtils.Log) {
|
||||
internalUtils.Log.Debug().Msg("Not mounting livecd as we think we are booting from removable media")
|
||||
if state.EfiBootFromInstall(internalUtils.KLog.Logger) {
|
||||
internalUtils.KLog.Logger.Debug().Msg("Not mounting livecd as we think we are booting from removable media")
|
||||
return nil
|
||||
}
|
||||
|
||||
err := os.MkdirAll(s.path(cnst.UkiLivecdMountPoint), 0755)
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Creating %s", cnst.UkiLivecdMountPoint))
|
||||
internalUtils.KLog.Logger.Err(err).Msg(fmt.Sprintf("Creating %s", cnst.UkiLivecdMountPoint))
|
||||
return err
|
||||
}
|
||||
err = os.MkdirAll(s.path(cnst.UkiIsoBaseTree), 0755)
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Creating %s", cnst.UkiIsoBaseTree))
|
||||
internalUtils.KLog.Logger.Err(err).Msg(fmt.Sprintf("Creating %s", cnst.UkiIsoBaseTree))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -432,9 +432,9 @@ func (s *State) UKIMountLiveCd(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
break
|
||||
}
|
||||
|
||||
internalUtils.Log.Debug().Msg(fmt.Sprintf("No media with label found at %s", cnst.UkiLivecdPath))
|
||||
internalUtils.KLog.Logger.Debug().Msg(fmt.Sprintf("No media with label found at %s", cnst.UkiLivecdPath))
|
||||
out, _ := internalUtils.CommandWithPath("ls -ltra /dev/disk/by-label/")
|
||||
internalUtils.Log.Debug().Str("out", out).Msg("contents of /dev/disk/by-label/")
|
||||
internalUtils.KLog.Logger.Debug().Str("out", out).Msg("contents of /dev/disk/by-label/")
|
||||
time.Sleep(time.Duration(i) * time.Second)
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ func (s *State) UKIMountLiveCd(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
if err == nil {
|
||||
cdrom = cnst.UkiDefaultcdrom
|
||||
} else {
|
||||
internalUtils.Log.Debug().Msg(fmt.Sprintf("No media found at %s", cnst.UkiDefaultcdrom))
|
||||
internalUtils.KLog.Logger.Debug().Msg(fmt.Sprintf("No media found at %s", cnst.UkiDefaultcdrom))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,10 +452,10 @@ func (s *State) UKIMountLiveCd(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
if cdrom != "" {
|
||||
err = internalUtils.Mount(cdrom, s.path(cnst.UkiLivecdMountPoint), cnst.UkiDefaultcdromFsType, syscall.MS_RDONLY, "")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Mounting %s", cdrom))
|
||||
internalUtils.KLog.Logger.Err(err).Msg(fmt.Sprintf("Mounting %s", cdrom))
|
||||
return err
|
||||
}
|
||||
internalUtils.Log.Debug().Msg(fmt.Sprintf("Mounted %s", cdrom))
|
||||
internalUtils.KLog.Logger.Debug().Msg(fmt.Sprintf("Mounted %s", cdrom))
|
||||
|
||||
// This needs the loop module to be inserted in the kernel!
|
||||
cmd := fmt.Sprintf("losetup --show -f %s", s.path(filepath.Join(cnst.UkiLivecdMountPoint, cnst.UkiIsoBootImage)))
|
||||
@@ -463,18 +463,18 @@ func (s *State) UKIMountLiveCd(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
loop := strings.TrimSpace(out)
|
||||
|
||||
if err != nil || loop == "" {
|
||||
internalUtils.Log.Err(err).Str("out", out).Msg(cmd)
|
||||
internalUtils.KLog.Logger.Err(err).Str("out", out).Msg(cmd)
|
||||
return err
|
||||
}
|
||||
|
||||
err = internalUtils.Mount(loop, s.path(cnst.UkiIsoBaseTree), cnst.UkiDefaultEfiimgFsType, syscall.MS_RDONLY, "")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Mounting %s into %s", loop, s.path(cnst.UkiIsoBaseTree)))
|
||||
internalUtils.KLog.Logger.Err(err).Msg(fmt.Sprintf("Mounting %s into %s", loop, s.path(cnst.UkiIsoBaseTree)))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
internalUtils.Log.Debug().Msg("No livecd/install media found")
|
||||
internalUtils.KLog.Logger.Debug().Msg("No livecd/install media found")
|
||||
return nil
|
||||
}))...)
|
||||
}
|
||||
@@ -492,19 +492,19 @@ func (s *State) UKIBootInitDagStep(g *herd.Graph) error {
|
||||
ext := "leave-initrd"
|
||||
err = UKIExtendPCR(ext)
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Str("ext", ext).Msg("extend-pcr")
|
||||
internalUtils.KLog.Logger.Err(err).Str("ext", ext).Msg("extend-pcr")
|
||||
internalUtils.DropToEmergencyShell()
|
||||
}
|
||||
|
||||
internalUtils.Log.Debug().Str("what", s.path(s.Rootdir)).Msg("Mount / RO")
|
||||
internalUtils.KLog.Logger.Debug().Str("what", s.path(s.Rootdir)).Msg("Mount / RO")
|
||||
if err = internalUtils.Mount("", s.path(s.Rootdir), "", syscall.MS_REMOUNT|syscall.MS_RDONLY, "ro"); err != nil {
|
||||
internalUtils.Log.Err(err).Msg("Mount / RO")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("Mount / RO")
|
||||
internalUtils.DropToEmergencyShell()
|
||||
}
|
||||
|
||||
// Print dag before exit, otherwise its never printed as we never exit the program
|
||||
internalUtils.Log.Info().Msg(s.WriteDAG(g))
|
||||
internalUtils.Log.Debug().Msg("Executing init callback!")
|
||||
internalUtils.KLog.Logger.Info().Msg(s.WriteDAG(g))
|
||||
internalUtils.KLog.Logger.Debug().Msg("Executing init callback!")
|
||||
if err := syscall.Exec("/sbin/init", []string{"/sbin/init"}, os.Environ()); err != nil {
|
||||
internalUtils.DropToEmergencyShell()
|
||||
}
|
||||
@@ -516,15 +516,15 @@ func (s *State) UKIBootInitDagStep(g *herd.Graph) error {
|
||||
// Doesnt matter if it fails, its just for niceness.
|
||||
func (s *State) UKIMountESPPartition(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
return g.Add("mount-esp", append(opts, herd.WithCallback(func(_ context.Context) error {
|
||||
if !state.EfiBootFromInstall(internalUtils.Log) {
|
||||
internalUtils.Log.Debug().Msg("Not mounting ESP as we think we are booting from removable media")
|
||||
if !state.EfiBootFromInstall(internalUtils.KLog.Logger) {
|
||||
internalUtils.KLog.Logger.Debug().Msg("Not mounting ESP as we think we are booting from removable media")
|
||||
return nil
|
||||
}
|
||||
cmd := "lsblk -J -o NAME,PARTTYPE"
|
||||
out, err := internalUtils.CommandWithPath(cmd)
|
||||
internalUtils.Log.Debug().Str("out", out).Str("cmd", cmd).Msg("ESP")
|
||||
internalUtils.KLog.Logger.Debug().Str("out", out).Str("cmd", cmd).Msg("ESP")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("ESP")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("ESP")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -627,8 +627,8 @@ func (s *State) ExtractCerts(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
// Remove it from the old location.
|
||||
func (s *State) MigrateSysExt(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
return g.Add(cnst.OpUkiTransitionSysext, append(opts, herd.WithCallback(func(_ context.Context) error {
|
||||
if !state.EfiBootFromInstall(internalUtils.Log) {
|
||||
internalUtils.Log.Debug().Msg("Not transitioning sysext as we think we are booting from removable media")
|
||||
if !state.EfiBootFromInstall(internalUtils.KLog.Logger) {
|
||||
internalUtils.KLog.Logger.Debug().Msg("Not transitioning sysext as we think we are booting from removable media")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -643,25 +643,25 @@ func (s *State) MigrateSysExt(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
// We have to remount the EFI partition as RW to be able to move the files
|
||||
err := syscall.Mount(cnst.EfiDir, cnst.EfiDir, cnst.UkiDefaultEfiimgFsType, syscall.MS_REMOUNT, "rw")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("Mounting EFI partition")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("Mounting EFI partition")
|
||||
return err
|
||||
}
|
||||
// We need to remount it as RO after we are done
|
||||
defer func() {
|
||||
err := syscall.Mount(cnst.EfiDir, cnst.EfiDir, cnst.UkiDefaultEfiimgFsType, syscall.MS_REMOUNT|syscall.MS_RDONLY, "")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("Mounting EFI partition as RO")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("Mounting EFI partition as RO")
|
||||
} else {
|
||||
internalUtils.Log.Debug().Msg("Remounting EFI partition as RO")
|
||||
internalUtils.KLog.Logger.Debug().Msg("Remounting EFI partition as RO")
|
||||
}
|
||||
}()
|
||||
|
||||
for _, bootState := range []string{"active", "passive"} {
|
||||
sourceDir := s.path(fmt.Sprintf("/efi/EFI/kairos/%s.efi.extra.d/", bootState))
|
||||
internalUtils.Log.Debug().Str("dir", sourceDir).Msg("Checking for sysextensions")
|
||||
internalUtils.KLog.Logger.Debug().Str("dir", sourceDir).Msg("Checking for sysextensions")
|
||||
targetDir := s.path(fmt.Sprintf("/var/lib/kairos/extensions/%s", bootState))
|
||||
if _, err := os.Stat(sourceDir); os.IsNotExist(err) {
|
||||
internalUtils.Log.Debug().Str("dir", sourceDir).Msg("No sysextensions found")
|
||||
internalUtils.KLog.Logger.Debug().Str("dir", sourceDir).Msg("No sysextensions found")
|
||||
continue
|
||||
}
|
||||
// Create target dirs as well
|
||||
@@ -674,7 +674,7 @@ func (s *State) MigrateSysExt(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
// Move the files over to the main extensions dir
|
||||
files, err := os.ReadDir(sourceDir)
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg("Reading dir")
|
||||
internalUtils.KLog.Logger.Err(err).Msg("Reading dir")
|
||||
continue
|
||||
}
|
||||
for _, file := range files {
|
||||
@@ -685,28 +685,28 @@ func (s *State) MigrateSysExt(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
source := filepath.Join(sourceDir, file.Name())
|
||||
target := filepath.Join(s.path("/var/lib/kairos/extensions"), file.Name())
|
||||
// Copy the file to the main extensions dir
|
||||
internalUtils.Log.Debug().Str("source", source).Str("target", target).Msg("Moving sysextension")
|
||||
internalUtils.KLog.Logger.Debug().Str("source", source).Str("target", target).Msg("Moving sysextension")
|
||||
err = internalUtils.Copy(source, target)
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Str("source", source).Str("target", target).Msg("Moving sysextension")
|
||||
internalUtils.KLog.Logger.Err(err).Str("source", source).Str("target", target).Msg("Moving sysextension")
|
||||
continue
|
||||
}
|
||||
internalUtils.Log.Debug().Str("source", source).Str("target", target).Msg("Moved sysextension")
|
||||
internalUtils.KLog.Logger.Debug().Str("source", source).Str("target", target).Msg("Moved sysextension")
|
||||
|
||||
internalUtils.Log.Debug().Str("target", target).Str("to", s.path(filepath.Join("/var/lib/kairos/extensions", bootState, file.Name()))).Msg("Creating symlink")
|
||||
internalUtils.KLog.Logger.Debug().Str("target", target).Str("to", s.path(filepath.Join("/var/lib/kairos/extensions", bootState, file.Name()))).Msg("Creating symlink")
|
||||
// Create a symlink to the new location
|
||||
err = os.Symlink(target, s.path(filepath.Join("/var/lib/kairos/extensions", bootState, file.Name())))
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Str("target", target).Str("to", s.path(filepath.Join("/var/lib/kairos/extensions", bootState, file.Name()))).Msg("Creating symlink")
|
||||
internalUtils.KLog.Logger.Err(err).Str("target", target).Str("to", s.path(filepath.Join("/var/lib/kairos/extensions", bootState, file.Name()))).Msg("Creating symlink")
|
||||
continue
|
||||
}
|
||||
// If no errors at this point, remove the original sysext
|
||||
err = os.Remove(source)
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Str("source", source).Msg("Removing old sysext")
|
||||
internalUtils.KLog.Logger.Err(err).Str("source", source).Msg("Removing old sysext")
|
||||
continue
|
||||
}
|
||||
internalUtils.Log.Debug().Str("source", source).Msg("Done sysext")
|
||||
internalUtils.KLog.Logger.Debug().Str("source", source).Msg("Done sysext")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user