From d34e9f0984df2b22508142d2eec2e617b98ee5aa Mon Sep 17 00:00:00 2001 From: Andrew Rynhard Date: Tue, 21 Apr 2020 15:07:31 -0700 Subject: [PATCH] fix: pass dev path to mkfs This fixes a bug caused by a missing device argument to `mkfs.xfs`. Without a device, `mkfs.xfs` will error out. Additionally, this ensures that the installer container is started with the `kmsg` writer that ensures logs are formatted correctly for `/dev/kmsg`. Without this we lose a lot of the logs output by the container, one of them being any error from `mkfs.xfs` Signed-off-by: Andrew Rynhard --- cmd/installer/pkg/installer.go | 16 ++++++++++++++++ cmd/installer/pkg/manifest/manifest.go | 4 ++-- go.sum | 1 + internal/pkg/install/install.go | 16 +++++++++++++++- pkg/blockdevice/filesystem/xfs/xfs.go | 6 ++++++ 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/cmd/installer/pkg/installer.go b/cmd/installer/pkg/installer.go index 784648817..99652999d 100644 --- a/cmd/installer/pkg/installer.go +++ b/cmd/installer/pkg/installer.go @@ -24,6 +24,8 @@ import ( "github.com/talos-systems/talos/internal/pkg/runtime" "github.com/talos-systems/talos/pkg/blockdevice" "github.com/talos-systems/talos/pkg/blockdevice/probe" + "github.com/talos-systems/talos/pkg/blockdevice/table" + "github.com/talos-systems/talos/pkg/blockdevice/util" "github.com/talos-systems/talos/pkg/config/machine" "github.com/talos-systems/talos/pkg/constants" ) @@ -143,7 +145,21 @@ func (i *Installer) Install(sequence runtime.Sequence) (err error) { // nolint: errcheck defer bd.Close() + var pt table.PartitionTable + + pt, err = bd.PartitionTable(true) + if err != nil { + return err + } + for _, target := range targets { + for _, part := range pt.Partitions() { + switch target.Label { + case constants.BootPartitionLabel, constants.EphemeralPartitionLabel: + target.PartitionName = util.PartPath(target.Device, int(part.No())) + } + } + if target.Label == constants.BootPartitionLabel { continue } diff --git a/cmd/installer/pkg/manifest/manifest.go b/cmd/installer/pkg/manifest/manifest.go index 92a856024..e6d7b51d4 100644 --- a/cmd/installer/pkg/manifest/manifest.go +++ b/cmd/installer/pkg/manifest/manifest.go @@ -184,11 +184,11 @@ func (t *Target) Partition(bd *blockdevice.BlockDevice) (err error) { // Format creates a filesystem on the device/partition. func (t *Target) Format() error { if t.Label == constants.BootPartitionLabel { - log.Printf("formatting partition %s - %s as %s\n", t.PartitionName, t.Label, "fat") + log.Printf("formatting partition %q - %q as %q\n", t.PartitionName, t.Label, "fat") return vfat.MakeFS(t.PartitionName, vfat.WithLabel(t.Label)) } - log.Printf("formatting partition %s - %s as %s\n", t.PartitionName, t.Label, "xfs") + log.Printf("formatting partition %q - %q as %q\n", t.PartitionName, t.Label, "xfs") opts := []xfs.Option{xfs.WithForce(t.Force)} if t.Label != "" { diff --git a/go.sum b/go.sum index 5beff4bfb..4da39a7dc 100644 --- a/go.sum +++ b/go.sum @@ -176,6 +176,7 @@ github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8 github.com/elazarl/goproxy/ext v0.0.0-20191011121108-aa519ddbe484/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= +github.com/emicklei/go-restful v2.11.1+incompatible h1:CjKsv3uWcCMvySPQYKxO8XX3f9zD4FeZRsW4G0B4ffE= github.com/emicklei/go-restful v2.11.1+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= diff --git a/internal/pkg/install/install.go b/internal/pkg/install/install.go index 77d0cc66f..73772323b 100644 --- a/internal/pkg/install/install.go +++ b/internal/pkg/install/install.go @@ -8,6 +8,7 @@ import ( "context" "fmt" "log" + "os" "strconv" "github.com/containerd/containerd" @@ -15,10 +16,12 @@ import ( "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/oci" "github.com/opencontainers/runtime-spec/specs-go" + "golang.org/x/sys/unix" "github.com/talos-systems/go-procfs/procfs" "github.com/talos-systems/talos/internal/pkg/containers/image" + "github.com/talos-systems/talos/internal/pkg/kmsg" "github.com/talos-systems/talos/internal/pkg/runtime" "github.com/talos-systems/talos/pkg/constants" ) @@ -109,7 +112,18 @@ func RunInstallerContainer(r runtime.Runtime, opts ...Option) error { return err } - t, err := container.NewTask(ctx, cio.LogFile("/dev/kmsg")) + f, err := os.OpenFile("/dev/kmsg", os.O_RDWR|unix.O_CLOEXEC|unix.O_NONBLOCK|unix.O_NOCTTY, 0666) + if err != nil { + return fmt.Errorf("failed to open /dev/kmsg: %w", err) + } + // nolint: errcheck + defer f.Close() + + w := &kmsg.Writer{KmsgWriter: f} + + creator := cio.NewCreator(cio.WithStreams(nil, w, w)) + + t, err := container.NewTask(ctx, creator) if err != nil { return err } diff --git a/pkg/blockdevice/filesystem/xfs/xfs.go b/pkg/blockdevice/filesystem/xfs/xfs.go index 8a49fc226..873dc8c63 100644 --- a/pkg/blockdevice/filesystem/xfs/xfs.go +++ b/pkg/blockdevice/filesystem/xfs/xfs.go @@ -6,6 +6,8 @@ package xfs import ( + "fmt" + "github.com/talos-systems/talos/pkg/cmd" ) @@ -19,6 +21,10 @@ func GrowFS(partname string) error { // MakeFS creates a XFS filesystem on the specified partition. func MakeFS(partname string, setters ...Option) error { + if partname == "" { + return fmt.Errorf("missing path to disk") + } + opts := NewDefaultOptions(setters...) // The ftype=1 naming option is required by overlayfs.