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: siderolabs#3532

Machine install section now has `markMBRBootable` option.

Signed-off-by: Artem Chernyshev <artem.0xD2@gmail.com>
  • Loading branch information
Unix4ever committed May 27, 2021
1 parent e0f5b1e commit 1fae37a
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 24 deletions.
1 change: 1 addition & 0 deletions cmd/installer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ func init() {
rootCmd.PersistentFlags().BoolVar(&options.Upgrade, "upgrade", false, "Indicates that the install is being performed by an upgrade")
rootCmd.PersistentFlags().BoolVar(&options.Force, "force", false, "Indicates that the install should forcefully format the partition")
rootCmd.PersistentFlags().BoolVar(&options.Zero, "zero", false, "Indicates that the install should write zeros to the disk before installing")
rootCmd.PersistentFlags().BoolVar(&options.LegacyBIOSSupport, "legacy-bios-support", false, "Indicates that the system has the legacy BIOS that doesn't support GPT partitioning scheme")
}
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/talos-systems/talos
go 1.16

replace (
github.com/talos-systems/go-blockdevice => github.com/Unix4ever/go-blockdevice v0.1.1-0.20210526144506-0573ad3d7b15
github.com/talos-systems/talos/pkg/machinery => ./pkg/machinery

// forked go-yaml that introduces RawYAML interface, which can be used to populate YAML fields using bytes
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/Unix4ever/go-blockdevice v0.1.1-0.20210526144506-0573ad3d7b15 h1:NVGypa8rYLAoenbA8r6R8jI4V9mwZ99syfGvm3PjhX4=
github.com/Unix4ever/go-blockdevice v0.1.1-0.20210526144506-0573ad3d7b15/go.mod h1:qnn/zDc09I1DA2BUDDCOSA2D0P8pIDjN8pGiRoRaQig=
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
github.com/a8m/tree v0.0.0-20210115125333-10a5fd5b637d/go.mod h1:FSdwKX97koS5efgm8WevNf7XS3PqtyFkKDDXrz778cg=
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
Expand Down Expand Up @@ -1214,8 +1216,6 @@ 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-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
2 changes: 2 additions & 0 deletions internal/app/machined/internal/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func RunInstallerContainer(disk, platform, ref string, configBytes []byte, reg c
upgrade := strconv.FormatBool(options.Upgrade)
force := strconv.FormatBool(options.Force)
zero := strconv.FormatBool(options.Zero)
legacyBIOSSupport := strconv.FormatBool(options.LegacyBIOSSupport)

args := []string{
"/bin/installer",
Expand All @@ -94,6 +95,7 @@ func RunInstallerContainer(disk, platform, ref string, configBytes []byte, reg c
"--upgrade=" + upgrade,
"--force=" + force,
"--zero=" + zero,
"--legacy-bios-support=" + legacyBIOSSupport,
}

if c := procfs.ProcCmdline().Get(constants.KernelParamBoard).First(); c != nil {
Expand Down
20 changes: 15 additions & 5 deletions internal/app/machined/internal/install/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ type Option func(o *Options) error

// Options describes the install options.
type Options struct {
Pull bool
Force bool
Upgrade bool
Zero bool
ExtraKernelArgs []string
Pull bool
Force bool
Upgrade bool
Zero bool
LegacyBIOSSupport bool
ExtraKernelArgs []string
}

// DefaultInstallOptions returns default options.
Expand Down Expand Up @@ -87,3 +88,12 @@ func WithExtraKernelArgs(s []string) Option {
return nil
}
}

// WithLegacyBIOSSupport sets MBR partition bootable.
func WithLegacyBIOSSupport(b bool) Option {
return func(o *Options) error {
o.LegacyBIOSSupport = b

return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,7 @@ func Install(seq runtime.Sequence, data interface{}) (runtime.TaskExecutionFunc,
install.WithForce(true),
install.WithZero(r.Config().Machine().Install().Zero()),
install.WithExtraKernelArgs(r.Config().Machine().Install().ExtraKernelArgs()),
install.WithLegacyBIOSSupport(r.Config().Machine().Install().LegacyBIOSSupport()),
)
if err != nil {
return err
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 = "markMBRBootable"
InstallConfigDoc.Fields[6].Type = "bool"
InstallConfigDoc.Fields[6].Note = ""
InstallConfigDoc.Fields[6].Description = "Indicates if MBR partition should be marked as bootable (active)."
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
13 changes: 13 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,19 @@ Valid values:
<hr />
<div class="dd">
<code>markMBRBootable</code> <i>bool</i>
</div>
<div class="dt">
Indicates if MBR partition should be marked as bootable (active).
</div>
<hr />
Expand Down

0 comments on commit 1fae37a

Please sign in to comment.