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 26, 2021
1 parent 7235976 commit dd73109
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 5 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.MarkMBRBootable, "mbr-bootable", false, "Indicates that the MBR should be marked as bootable")
}
1 change: 1 addition & 0 deletions cmd/installer/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Options struct {
Upgrade bool
Force bool
Zero bool
MarkMBRBootable bool
}

// Install installs Talos.
Expand Down
10 changes: 7 additions & 3 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
MarkMBRBootable 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{},
MarkMBRBootable: opts.MarkMBRBootable,
}

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.MarkMBRBootable),
}

if m.PartitionOptions != nil {
gptOpts = append(gptOpts, gpt.WithPartitionEntriesStartLBA(m.PartitionOptions.PartitionsOffset))
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ 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.20210427105118-4f80b976b640 h1:dDChkGwqk1jcRO0k63VTgGzt1UrY20UiDS3yNcCLW0k=
github.com/talos-systems/crypto v0.2.1-0.20210427105118-4f80b976b640/go.mod h1:OXCK52Q0dzm88YRG4VdTBdidkPUtqrCxCyW7bUs4DAw=
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)
mbrBootable := strconv.FormatBool(options.MarkMBRBootable)

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,
"--mbr-bootable=" + mbrBootable,
}

if c := procfs.ProcCmdline().Get(constants.KernelParamBoard).First(); c != nil {
Expand Down
10 changes: 10 additions & 0 deletions internal/app/machined/internal/install/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Options struct {
Force bool
Upgrade bool
Zero bool
MarkMBRBootable bool
ExtraKernelArgs []string
}

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

// WithMarkMBRBootable sets MBR partition bootable.
func WithMarkMBRBootable(b bool) Option {
return func(o *Options) error {
o.MarkMBRBootable = 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.WithMarkMBRBootable(r.Config().Machine().Install().MarkMBRBootable()),
)
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
MarkMBRBootable() 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
}

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

// WithBootloader implements the config.Provider interface.
func (i *InstallConfig) WithBootloader() bool {
return i.InstallBootloader
Expand Down
3 changes: 3 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,9 @@ type InstallConfig struct {
// - false
// - no
InstallWipe bool `yaml:"wipe"`
// description: |
// Indicates if MBR partition should be marked as bootable (active).
InstallMarkMBRBootable bool `yaml:"markMBRBootable,omitempty"`
}

// InstallDiskSizeMatcher disk size condition parser.
Expand Down

0 comments on commit dd73109

Please sign in to comment.