Files
snapd/boot/kernel_os.go
T

85 lines
2.3 KiB
Go
Raw Normal View History

// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2014-2019 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package boot
import (
"fmt"
"github.com/snapcore/snapd/bootloader"
"github.com/snapcore/snapd/snap"
)
2019-08-02 10:45:05 +01:00
type coreBootParticipant struct {
s snap.PlaceInfo
bs bootState
}
2019-09-02 14:24:41 +01:00
// ensure coreBootParticipant is a BootParticipant
2019-08-02 10:45:05 +01:00
var _ BootParticipant = (*coreBootParticipant)(nil)
func (*coreBootParticipant) IsTrivial() bool { return false }
2022-07-11 16:49:06 +01:00
func (bp *coreBootParticipant) SetNextBoot(bootCtx NextBootContext) (rebootInfo RebootInfo, err error) {
const errPrefix = "cannot set next boot: %s"
2022-07-11 16:49:06 +01:00
rebootInfo, u, err := bp.bs.setNext(bp.s, bootCtx)
if err != nil {
2022-02-02 18:13:57 +01:00
return RebootInfo{RebootRequired: false}, fmt.Errorf(errPrefix, err)
}
if u != nil {
if err := u.commit(); err != nil {
2022-02-02 18:13:57 +01:00
return RebootInfo{RebootRequired: false}, fmt.Errorf(errPrefix, err)
2018-05-09 12:42:12 +02:00
}
}
2022-02-02 18:13:57 +01:00
2022-02-08 13:44:01 +01:00
return rebootInfo, nil
}
2019-08-14 16:40:07 +01:00
type coreKernel struct {
s snap.PlaceInfo
bopts *bootloader.Options
2019-08-14 16:40:07 +01:00
}
2019-09-02 14:24:41 +01:00
// ensure coreKernel is a Kernel
2019-09-03 15:27:17 +01:00
var _ BootKernel = (*coreKernel)(nil)
2019-08-14 16:40:07 +01:00
func (*coreKernel) IsTrivial() bool { return false }
2019-08-14 16:40:07 +01:00
func (k *coreKernel) RemoveKernelAssets() error {
// XXX: shouldn't we check the snap type?
bootloader, err := bootloader.Find("", k.bopts)
2019-08-14 16:40:07 +01:00
if err != nil {
return fmt.Errorf("cannot remove kernel assets: %s", err)
}
// ask bootloader to remove the kernel assets if needed
return bootloader.RemoveKernelAssets(k.s)
}
func (k *coreKernel) ExtractKernelAssets(snapf snap.Container) error {
bootloader, err := bootloader.Find("", k.bopts)
2019-08-14 16:40:07 +01:00
if err != nil {
return fmt.Errorf("cannot extract kernel assets: %s", err)
}
// ask bootloader to extract the kernel assets if needed
return bootloader.ExtractKernelAssets(k.s, snapf)
}