Documentation
¶
Index ¶
- Constants
- Variables
- func ComposeCandidateCommandLine(model *asserts.Model) (string, error)
- func ComposeCommandLine(model *asserts.Model) (string, error)
- func ComposeRecoveryCommandLine(model *asserts.Model, system string) (string, error)
- func CopyBootAssetsCacheToRoot(dstRoot string) error
- func DumpBootVars(w io.Writer, dir string, uc20 bool) error
- func EnsureNextBootToRunMode(systemLabel string) error
- func FindPartitionUUIDForBootedKernelDisk() (string, error)
- func GetCurrentBoot(t snap.Type, dev Device) (snap.PlaceInfo, error)
- func InitramfsRunModeSelectSnapsToMount(typs []snap.Type, modeenv *Modeenv) (map[snap.Type]snap.PlaceInfo, error)
- func MakeBootable(model *asserts.Model, rootdir string, bootWith *BootableSet, ...) error
- func MarkBootSuccessful(dev Device) error
- func MockInitramfsReboot(f func() error) (restore func())
- func MockProcCmdline(newPath string) (restore func())
- func ModeAndRecoverySystemFromKernelCommandLine() (mode, sysLabel string, err error)
- func SetRecoveryBootSystemAndMode(dev Device, systemLabel, mode string) error
- type BootKernel
- type BootParticipant
- type BootableSet
- type Device
- type InUseFunc
- type Modeenv
- type TrustedAssetsInstallObserver
- func (o *TrustedAssetsInstallObserver) ChosenEncryptionKey(key secboot.EncryptionKey)
- func (o *TrustedAssetsInstallObserver) Observe(op gadget.ContentOperation, affectedStruct *gadget.LaidOutStructure, ...) (bool, error)
- func (o *TrustedAssetsInstallObserver) ObserveExistingTrustedRecoveryAssets(recoveryRootDir string) error
- type TrustedAssetsUpdateObserver
Constants ¶
const ( // DefaultStatus is the value of a status boot variable when nothing is // being tried DefaultStatus = "" // TryStatus is the value of a status boot variable when something is about // to be tried TryStatus = "try" // TryingStatus is the value of a status boot variable after we have // attempted a boot with a try snap - this status is only set in the early // boot sequence (bootloader, initramfs, etc.) TryingStatus = "trying" )
const ( // ModeRun indicates the regular operating system mode of the device. ModeRun = "run" // ModeInstall is a mode in which a new system is installed on the // device. ModeInstall = "install" // ModeRecover is a mode in which the device boots into the recovery // system. ModeRecover = "recover" )
Variables ¶
var ( // InitramfsRunMntDir is the directory where ubuntu partitions are mounted // during the initramfs. InitramfsRunMntDir string // InitramfsDataDir is the location of system-data role partition // (typically a partition labeled "ubuntu-data") during the initramfs. InitramfsDataDir string // InitramfsHostUbuntuDataDir is the location of the host ubuntu-data // during the initramfs, typically used in recover mode. InitramfsHostUbuntuDataDir string // InitramfsUbuntuBootDir is the location of ubuntu-boot during the // initramfs. InitramfsUbuntuBootDir string // InitramfsUbuntuSeedDir is the location of ubuntu-seed during the // initramfs. InitramfsUbuntuSeedDir string // InitramfsWritableDir is the location of the writable partition during the // initramfs. Note that this may refer to a temporary filesystem or a // physical partition depending on what system mode the system is in. InitramfsWritableDir string // InstallHostWritableDir is the location of the writable partition of the // installed host during install mode. This should always be on a physical // partition. InstallHostWritableDir string // InstallHostFDEDataDir is the location of the FDE data during install mode. InstallHostFDEDataDir string // InitramfsEncryptionKeyDir is the location of the encrypted partition keys // during the initramfs. InitramfsEncryptionKeyDir string )
var ( // ErrBootNameAndRevisionNotReady is returned when the boot revision is not // established yet. ErrBootNameAndRevisionNotReady = errors.New("boot revision not yet established") )
var ErrObserverNotApplicable = errors.New("observer not applicable")
ErrObserverNotApplicable indicates that observer is not applicable for use with the model.
var ErrUnsupportedSystemMode = errors.New("system mode is unsupported")
Functions ¶
func ComposeCandidateCommandLine ¶
ComposeCandidateCommandLine composes the kernel command line used when booting the system in run mode with the current built-in edition of managed boot assets.
func ComposeCommandLine ¶
ComposeCommandLine composes the kernel command line used when booting the system in run mode.
func ComposeRecoveryCommandLine ¶
ComposeRecoveryCommandLine composes the kernel command line used when booting a given system in recover mode.
func CopyBootAssetsCacheToRoot ¶
CopyBootAssetsCacheToRoot copies the boot assets cache to a corresponding location under a new root directory.
func DumpBootVars ¶
DumpBootVars writes a dump of the snapd bootvars to the given writer
func EnsureNextBootToRunMode ¶
EnsureNextBootToRunMode will mark the bootenv of the recovery bootloader such that recover mode is now ready to switch back to run mode upon any reboot.
func FindPartitionUUIDForBootedKernelDisk ¶
FindPartitionUUIDForBootedKernelDisk returns the partition uuid for the partition that the booted kernel is located on.
func GetCurrentBoot ¶
GetCurrentBoot returns the currently set name and revision for boot for the given type of snap, which can be snap.TypeBase (or snap.TypeOS), or snap.TypeKernel. Returns ErrBootNameAndRevisionNotReady if the values are temporarily not established.
func InitramfsRunModeSelectSnapsToMount ¶
func InitramfsRunModeSelectSnapsToMount( typs []snap.Type, modeenv *Modeenv, ) (map[snap.Type]snap.PlaceInfo, error)
InitramfsRunModeSelectSnapsToMount returns a map of the snap paths to mount for the specified snap types.
func MakeBootable ¶
func MakeBootable(model *asserts.Model, rootdir string, bootWith *BootableSet, sealer *TrustedAssetsInstallObserver) error
MakeBootable sets up the given bootable set and target filesystem such that the system can be booted.
rootdir points to an image filesystem (UC 16/18), image recovery filesystem (UC20 at prepare-image time) or ephemeral system (UC20 install mode).
func MarkBootSuccessful ¶
MarkBootSuccessful marks the current boot as successful. This means that snappy will consider this combination of kernel/os a valid target for rollback.
The states that a boot goes through for UC16/18 are the following:
- By default snap_mode is "" in which case the bootloader loads two squashfs'es denoted by variables snap_core and snap_kernel.
- On a refresh of core/kernel snapd will set snap_mode=try and will also set snap_try_{core,kernel} to the core/kernel that will be tried next.
- On reboot the bootloader will inspect the snap_mode and if the mode is set to "try" it will set "snap_mode=trying" and then try to boot the snap_try_{core,kernel}".
- On a successful boot snapd resets snap_mode to "" and copies snap_try_{core,kernel} to snap_{core,kernel}. The snap_try_* values are cleared afterwards.
- On a failing boot the bootloader will see snap_mode=trying which means snapd did not start successfully. In this case the bootloader will set snap_mode="" and the system will boot with the known good values from snap_{core,kernel}
func MockInitramfsReboot ¶
func MockInitramfsReboot(f func() error) (restore func())
func MockProcCmdline ¶
func MockProcCmdline(newPath string) (restore func())
MockProcCmdline overrides the path to /proc/cmdline. For use in tests.
func ModeAndRecoverySystemFromKernelCommandLine ¶
ModeAndRecoverySystemFromKernelCommandLine returns the current system mode and the recovery system label as passed in the kernel command line by the bootloader.
func SetRecoveryBootSystemAndMode ¶
SetRecoveryBootSystemAndMode configures the recovery bootloader to boot into the given recovery system in a particular mode. Returns ErrUnsupportedSystemMode when booting into a recovery system is not supported by the device.
Types ¶
type BootKernel ¶
type BootKernel interface { // RemoveKernelAssets removes the unpacked kernel/initrd for the given // kernel snap. RemoveKernelAssets() error // ExtractKernelAssets extracts kernel/initrd/dtb data from the given // kernel snap, if required, to a versioned bootloader directory so // that the bootloader can use it. ExtractKernelAssets(snap.Container) error // Is this a trivial implementation of the interface? IsTrivial() bool }
A BootKernel handles the bootloader setup of a kernel.
type BootParticipant ¶
type BootParticipant interface { // SetNextBoot will schedule the snap to be used in the next boot. For // base snaps it is up to the caller to select the right bootable base // (from the model assertion). It is a noop for not relevant snaps. // Otherwise it returns whether a reboot is required. SetNextBoot() (rebootRequired bool, err error) // Is this a trivial implementation of the interface? IsTrivial() bool }
A BootParticipant handles the boot process details for a snap involved in it.
func Participant ¶
Participant figures out what the BootParticipant is for the given arguments, and returns it. If the snap does _not_ participate in the boot process, the returned object will be a NOP, so it's safe to call anything on it always.
Currently, on classic, nothing is a boot participant (returned will always be NOP).
type BootableSet ¶
type BootableSet struct { Base *snap.Info BasePath string Kernel *snap.Info KernelPath string RecoverySystemLabel string RecoverySystemDir string UnpackedGadgetDir string // Recover is set when making the recovery partition bootable. Recovery bool }
BootableSet represents the boot snaps of a system to be made bootable.
type Device ¶
type Device interface { RunMode() bool Classic() bool Kernel() string Base() string HasModeenv() bool }
Device carries information about the device model and mode that is relevant to boot. Note snapstate.DeviceContext implements this, and that's the expected use case.
type Modeenv ¶
type Modeenv struct { Mode string RecoverySystem string CurrentRecoverySystems []string Base string TryBase string BaseStatus string CurrentKernels []string Model string BrandID string Grade string // CurrentTrustedBootAssets is a map of a run bootloader's asset names to // a list of hashes of the asset contents. Typically the first entry in // the list is a hash of an asset the system currently boots with (or is // expected to have booted with). The second entry, if present, is the // hash of an entry added when an update of the asset was being applied // and will become the sole entry after a successful boot. CurrentTrustedBootAssets bootAssetsMap // CurrentTrustedRecoveryBootAssetsMap is a map of a recovery bootloader's // asset names to a list of hashes of the asset contents. Used similarly // to CurrentTrustedBootAssets. CurrentTrustedRecoveryBootAssets bootAssetsMap // contains filtered or unexported fields }
Modeenv is a file on UC20 that provides additional information about the current mode (run,recover,install)
func ReadModeenv ¶
ReadModeenv attempts to read the modeenv file at <rootdir>/var/iib/snapd/modeenv.
type TrustedAssetsInstallObserver ¶
type TrustedAssetsInstallObserver struct {
// contains filtered or unexported fields
}
TrustedAssetsInstallObserver tracks the installation of trusted boot assets.
func TrustedAssetsInstallObserverForModel ¶
func TrustedAssetsInstallObserverForModel(model *asserts.Model, gadgetDir string) (*TrustedAssetsInstallObserver, error)
TrustedAssetsInstallObserverForModel returns a new trusted assets observer for use during installation of the run mode system, provided the device model supports secure boot. Otherwise, nil and ErrObserverNotApplicable is returned.
func (*TrustedAssetsInstallObserver) ChosenEncryptionKey ¶
func (o *TrustedAssetsInstallObserver) ChosenEncryptionKey(key secboot.EncryptionKey)
func (*TrustedAssetsInstallObserver) Observe ¶
func (o *TrustedAssetsInstallObserver) Observe(op gadget.ContentOperation, affectedStruct *gadget.LaidOutStructure, root, relativeTarget string, data *gadget.ContentChange) (bool, error)
Observe observes the operation related to the content of a given gadget structure. In particular, the TrustedAssetsInstallObserver tracks writing of managed boot assets, such as the bootloader binary which is measured as part of the secure boot.
Implements gadget.ContentObserver.
func (*TrustedAssetsInstallObserver) ObserveExistingTrustedRecoveryAssets ¶
func (o *TrustedAssetsInstallObserver) ObserveExistingTrustedRecoveryAssets(recoveryRootDir string) error
ObserveExistingTrustedRecoveryAssets observes existing trusted assets of a recovery bootloader located inside a given root directory.
type TrustedAssetsUpdateObserver ¶
type TrustedAssetsUpdateObserver struct {
// contains filtered or unexported fields
}
TrustedAssetsUpdateObserver tracks the updates of trusted boot assets and attempts to reseal when needed.
func TrustedAssetsUpdateObserverForModel ¶
func TrustedAssetsUpdateObserverForModel(model *asserts.Model) (*TrustedAssetsUpdateObserver, error)
TrustedAssetsUpdateObserverForModel returns a new trusted assets observer for tracking changes to the measured boot assets during gadget updates, provided the device model supports secure boot. Otherwise, nil and ErrObserverNotApplicable is returned.
func (*TrustedAssetsUpdateObserver) BeforeWrite ¶
func (o *TrustedAssetsUpdateObserver) BeforeWrite() error
BeforeWrite is called when the update process has been staged for execution.
func (*TrustedAssetsUpdateObserver) Canceled ¶
func (o *TrustedAssetsUpdateObserver) Canceled() error
Canceled is called when the update has been canceled, or if changes were written and the update has been reverted.
func (*TrustedAssetsUpdateObserver) Observe ¶
func (o *TrustedAssetsUpdateObserver) Observe(op gadget.ContentOperation, affectedStruct *gadget.LaidOutStructure, root, relativeTarget string, data *gadget.ContentChange) (bool, error)
Observe observes the operation related to the update or rollback of the content of a given gadget structure. In particular, the TrustedAssetsUpdateObserver tracks updates of managed boot assets, such as the bootloader binary which is measured as part of the secure boot.
Implements gadget.ContentUpdateObserver.