Skip to content

Commit

Permalink
feat: add ability to mark MBR partition bootable
Browse files Browse the repository at this point in the history
Fixes: #3532

Machine install section now has `markMBRBootable` option.

Signed-off-by: Artem Chernyshev <artem.0xD2@gmail.com>
  • Loading branch information
Unix4ever authored and talos-bot committed May 27, 2021
1 parent e0f5b1e commit 76dbfb3
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 22 deletions.
4 changes: 4 additions & 0 deletions cmd/installer/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func runInstallCmd() (err error) {
log.Printf(" %s", warning)
}
}

if config.Machine().Install().LegacyBIOSSupport() {
options.LegacyBIOSSupport = true
}
}

return install.Install(p, seq, options)
Expand Down
21 changes: 11 additions & 10 deletions cmd/installer/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ import (

// Options represents the set of options available for an install.
type Options struct {
ConfigSource string
Disk string
Platform string
Arch string
Board string
ExtraKernelArgs []string
Bootloader bool
Upgrade bool
Force bool
Zero bool
ConfigSource string
Disk string
Platform string
Arch string
Board string
ExtraKernelArgs []string
Bootloader bool
Upgrade bool
Force bool
Zero bool
LegacyBIOSSupport bool
}

// Install installs Talos.
Expand Down
16 changes: 10 additions & 6 deletions cmd/installer/pkg/install/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ import (
// Manifest represents the instructions for preparing all block devices
// for an installation.
type Manifest struct {
PartitionOptions *runtime.PartitionOptions
Devices map[string]Device
Targets map[string][]*Target
PartitionOptions *runtime.PartitionOptions
Devices map[string]Device
Targets map[string][]*Target
LegacyBIOSSupport bool
}

// Device represents device options.
Expand All @@ -52,8 +53,9 @@ func NewManifest(label string, sequence runtime.Sequence, bootPartitionFound boo
}

manifest = &Manifest{
Devices: map[string]Device{},
Targets: map[string][]*Target{},
Devices: map[string]Device{},
Targets: map[string][]*Target{},
LegacyBIOSSupport: opts.LegacyBIOSSupport,
}

if opts.Board != constants.BoardNone {
Expand Down Expand Up @@ -271,7 +273,9 @@ func (m *Manifest) executeOnDevice(device Device, targets []*Target) (err error)

log.Printf("creating new partition table on %s", device.Device)

gptOpts := []gpt.Option{}
gptOpts := []gpt.Option{
gpt.WithMarkMBRBootable(m.LegacyBIOSSupport),
}

if m.PartitionOptions != nil {
gptOpts = append(gptOpts, gpt.WithPartitionEntriesStartLBA(m.PartitionOptions.PartitionsOffset))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ require (
github.com/spf13/cobra v1.1.3
github.com/stretchr/testify v1.7.0
github.com/talos-systems/crypto v0.2.1-0.20210526123943-7776057f5086
github.com/talos-systems/go-blockdevice v0.2.1-0.20210510233948-1292574643e0
github.com/talos-systems/go-blockdevice v0.2.1-0.20210526155905-30c2bc3cb62a
github.com/talos-systems/go-cmd v0.0.0-20210216164758-68eb0067e0f0
github.com/talos-systems/go-debug v0.2.1-0.20210525175311-3d0a6e1bf5e3
github.com/talos-systems/go-kmsg v0.1.0
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,9 @@ github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/talos-systems/crypto v0.2.1-0.20210526123943-7776057f5086 h1:SAyrAftTtxzEUqr9alFt1iezS5vuwCm7/yE8ydR0h+A=
github.com/talos-systems/crypto v0.2.1-0.20210526123943-7776057f5086/go.mod h1:xaNCB2/Bxaj+qrkdeodhRv5eKQVvKOGBBMj58MrIPY8=
github.com/talos-systems/go-blockdevice v0.2.1-0.20210510233948-1292574643e0 h1:EdawBvWE2v9+oiT6vFfUJB9cSTNWRPwcIamCyHEtthQ=
github.com/talos-systems/go-blockdevice v0.2.1-0.20210510233948-1292574643e0/go.mod h1:qnn/zDc09I1DA2BUDDCOSA2D0P8pIDjN8pGiRoRaQig=
github.com/talos-systems/go-blockdevice v0.2.1-0.20210526155905-30c2bc3cb62a h1:NLuIVKi5tBnRMgxk185AVGmMUzlRcggb2Abrw9uUq3E=
github.com/talos-systems/go-blockdevice v0.2.1-0.20210526155905-30c2bc3cb62a/go.mod h1:qnn/zDc09I1DA2BUDDCOSA2D0P8pIDjN8pGiRoRaQig=
github.com/talos-systems/go-cmd v0.0.0-20210216164758-68eb0067e0f0 h1:DI+BjK+fcrLBc70Fi50dZocQcaHosqsuWHrGHKp2NzE=
github.com/talos-systems/go-cmd v0.0.0-20210216164758-68eb0067e0f0/go.mod h1:kf+rZzTEmlDiYQ6ulslvRONnKLQH8x83TowltGMhO+k=
github.com/talos-systems/go-debug v0.2.1-0.20210525175311-3d0a6e1bf5e3 h1:beG97JtuU5oIL+ArSOKbJxbfsCfELOQ5VZu4RuSBJHU=
Expand Down
7 changes: 7 additions & 0 deletions hack/release.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ preface = """\
description = """\
Talos installer image (for any arch) now contains artifacts for both `amd64` and `arm64` architecture.
This means that e.g. images for arm64 SBCs can be generated on amd64 host.
"""

[notes.legacy_bios]
title = "Legacy BIOS Support"
description = """\
Added an option to the `machine.install` section of the machine config that can enable marking MBR partition bootable
for the machines that have legacy BIOS which does not support GPT partitioning scheme.
"""

[notes.components]
Expand Down
1 change: 1 addition & 0 deletions pkg/machinery/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type Install interface {
Disk() (string, error)
ExtraKernelArgs() []string
Zero() bool
LegacyBIOSSupport() bool
WithBootloader() bool
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/machinery/config/types/v1alpha1/v1alpha1_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,11 @@ func (i *InstallConfig) Zero() bool {
return i.InstallWipe
}

// LegacyBIOSSupport implements the config.Provider interface.
func (i *InstallConfig) LegacyBIOSSupport() bool {
return i.InstallLegacyBIOSSupport
}

// WithBootloader implements the config.Provider interface.
func (i *InstallConfig) WithBootloader() bool {
return i.InstallBootloader
Expand Down
4 changes: 4 additions & 0 deletions pkg/machinery/config/types/v1alpha1/v1alpha1_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,10 @@ type InstallConfig struct {
// - false
// - no
InstallWipe bool `yaml:"wipe"`
// description: |
// Indicates if MBR partition should be marked as bootable (active).
// Should be enabled only for the systems with legacy BIOS that doesn't support GPT partitioning scheme.
InstallLegacyBIOSSupport bool `yaml:"legacyBIOSSupport,omitempty"`
}

// InstallDiskSizeMatcher disk size condition parser.
Expand Down
7 changes: 6 additions & 1 deletion pkg/machinery/config/types/v1alpha1/v1alpha1_types_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func init() {
FieldName: "install",
},
}
InstallConfigDoc.Fields = make([]encoder.Doc, 6)
InstallConfigDoc.Fields = make([]encoder.Doc, 7)
InstallConfigDoc.Fields[0].Name = "disk"
InstallConfigDoc.Fields[0].Type = "string"
InstallConfigDoc.Fields[0].Note = ""
Expand Down Expand Up @@ -543,6 +543,11 @@ func init() {
"false",
"no",
}
InstallConfigDoc.Fields[6].Name = "legacyBIOSSupport"
InstallConfigDoc.Fields[6].Type = "bool"
InstallConfigDoc.Fields[6].Note = ""
InstallConfigDoc.Fields[6].Description = "Indicates if MBR partition should be marked as bootable (active).\nShould be enabled only for the systems with legacy BIOS that doesn't support GPT partitioning scheme."
InstallConfigDoc.Fields[6].Comments[encoder.LineComment] = "Indicates if MBR partition should be marked as bootable (active)."

InstallDiskSizeMatcherDoc.Type = "InstallDiskSizeMatcher"
InstallDiskSizeMatcherDoc.Comments[encoder.LineComment] = "InstallDiskSizeMatcher disk size condition parser."
Expand Down
2 changes: 1 addition & 1 deletion pkg/machinery/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/talos-systems/crypto v0.2.1-0.20210526123943-7776057f5086
github.com/talos-systems/go-blockdevice v0.2.1-0.20210510233948-1292574643e0
github.com/talos-systems/go-blockdevice v0.2.1-0.20210526155905-30c2bc3cb62a
github.com/talos-systems/net v0.2.1-0.20210212213224-05190541b0fa
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
golang.org/x/sys v0.0.0-20210324051608-47abb6519492 // indirect
Expand Down
4 changes: 2 additions & 2 deletions pkg/machinery/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/talos-systems/crypto v0.2.1-0.20210526123943-7776057f5086 h1:SAyrAftTtxzEUqr9alFt1iezS5vuwCm7/yE8ydR0h+A=
github.com/talos-systems/crypto v0.2.1-0.20210526123943-7776057f5086/go.mod h1:xaNCB2/Bxaj+qrkdeodhRv5eKQVvKOGBBMj58MrIPY8=
github.com/talos-systems/go-blockdevice v0.2.1-0.20210510233948-1292574643e0 h1:EdawBvWE2v9+oiT6vFfUJB9cSTNWRPwcIamCyHEtthQ=
github.com/talos-systems/go-blockdevice v0.2.1-0.20210510233948-1292574643e0/go.mod h1:qnn/zDc09I1DA2BUDDCOSA2D0P8pIDjN8pGiRoRaQig=
github.com/talos-systems/go-blockdevice v0.2.1-0.20210526155905-30c2bc3cb62a h1:NLuIVKi5tBnRMgxk185AVGmMUzlRcggb2Abrw9uUq3E=
github.com/talos-systems/go-blockdevice v0.2.1-0.20210526155905-30c2bc3cb62a/go.mod h1:qnn/zDc09I1DA2BUDDCOSA2D0P8pIDjN8pGiRoRaQig=
github.com/talos-systems/go-cmd v0.0.0-20210216164758-68eb0067e0f0/go.mod h1:kf+rZzTEmlDiYQ6ulslvRONnKLQH8x83TowltGMhO+k=
github.com/talos-systems/go-retry v0.1.1-0.20201113203059-8c63d290a688/go.mod h1:HiXQqyVStZ35uSY/MTLWVvQVmC3lIW2MS5VdDaMtoKM=
github.com/talos-systems/go-retry v0.2.1-0.20210119124456-b9dc1a990133/go.mod h1:HiXQqyVStZ35uSY/MTLWVvQVmC3lIW2MS5VdDaMtoKM=
Expand Down
14 changes: 14 additions & 0 deletions website/content/docs/v0.11/Reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,20 @@ Valid values:
<hr />
<div class="dd">
<code>legacyBIOSSupport</code> <i>bool</i>
</div>
<div class="dt">
Indicates if MBR partition should be marked as bootable (active).
Should be enabled only for the systems with legacy BIOS that doesn't support GPT partitioning scheme.
</div>
<hr />
Expand Down

0 comments on commit 76dbfb3

Please sign in to comment.