Skip to content

Commit

Permalink
fix: add a check for overlay mounts in installer pre-flight checks
Browse files Browse the repository at this point in the history
Overlay mount in `mountinfo` don't show up as mounts for any particular
block device, so the existing check doesn't catch them.

This was discovered as our current master can't upgrade because of
overlay mount for `/opt` and `apid` image in `/opt/apid` (which will be
fixed in a separate PR).

Without the check, installer fails on resetting partition table for the
disk effectively wiping the node (`device or resource busy` error).

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed Apr 2, 2021
1 parent 61b694b commit 6b88910
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cmd/installer/pkg/install/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Manifest struct {
PartitionOptions *runtime.PartitionOptions
Devices map[string]Device
Targets map[string][]*Target
ImageCreation bool
}

// Device represents device options.
Expand All @@ -52,6 +53,8 @@ func NewManifest(label string, sequence runtime.Sequence, bootPartitionFound boo
manifest = &Manifest{
Devices: map[string]Device{},
Targets: map[string][]*Target{},

ImageCreation: sequence == runtime.SequenceNoop,
}

if opts.Board != constants.BoardNone {
Expand Down Expand Up @@ -170,6 +173,8 @@ func (m *Manifest) Execute() (err error) {
}

// checkMounts verifies that no active mounts in any mount namespace exist for the device.
//
//nolint:gocyclo
func (m *Manifest) checkMounts(device Device) error {
matches, err := filepath.Glob("/proc/*/mountinfo")
if err != nil {
Expand Down Expand Up @@ -198,6 +203,22 @@ func (m *Manifest) checkMounts(device Device) error {
continue
}

if !m.ImageCreation && fields[len(fields)-2] == "overlay" {
// parsing options (last column) in the overlay mount line which looks like:
// 163 70 0:52 /apid / ro,relatime - overlay overlay rw,lowerdir=/opt,upperdir=/var/system/overlays/opt-diff,workdir=/var/system/overlays/opt-workdir

options := strings.Split(fields[len(fields)-1], ",")

for _, option := range options {
parts := strings.SplitN(option, "=", 2)
if len(parts) == 2 {
if strings.HasPrefix(parts[1], "/var/") {
return fmt.Errorf("found overlay mount in %q: %s", path, scanner.Text())
}
}
}
}

if fields[len(fields)-2] == device.Device {
return fmt.Errorf("found active mount in %q for %q: %s", path, device.Device, scanner.Text())
}
Expand Down

0 comments on commit 6b88910

Please sign in to comment.