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 <andrew@andrewrynhard.com>
This commit is contained in:
Andrew Rynhard 2020-04-21 15:07:31 -07:00 committed by talos-bot
parent 3332ca58d3
commit d34e9f0984
5 changed files with 40 additions and 3 deletions

View File

@ -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
}

View File

@ -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 != "" {

1
go.sum
View File

@ -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=

View File

@ -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
}

View File

@ -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.