preseed

package
v0.0.0-...-bc60ea4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2024 License: GPL-3.0 Imports: 28 Imported by: 2

Documentation

Overview

Package preseed provides functions for preseeding of classic and UC20 systems. Preseeding runs snapd in special mode that executes significant portion of initial seeding in a chroot environment and stores the resulting modifications in the image so that they can be reused and skipped on first boot, speeding it up.

Index

Constants

This section is empty.

Variables

View Source
var (
	Stdout io.Writer = os.Stdout
	Stderr io.Writer = os.Stderr
)
View Source
var ResetPreseededChroot = func(preseedChroot string) error {
	var err error
	preseedChroot, err = filepath.Abs(preseedChroot)
	if err != nil {
		return err
	}

	exists, isDir, err := osutil.DirExists(preseedChroot)
	if err != nil {
		return fmt.Errorf("cannot reset %q: %v", preseedChroot, err)
	}
	if !exists {
		return fmt.Errorf("cannot reset non-existing directory %q", preseedChroot)
	}
	if !isDir {
		return fmt.Errorf("cannot reset %q, it is not a directory", preseedChroot)
	}

	globs := []string{
		dirs.SnapStateFile,
		dirs.SnapSystemKeyFile,
		filepath.Join(dirs.SnapBlobDir, "*.snap"),
		filepath.Join(dirs.SnapUdevRulesDir, "*-snap.*.rules"),
		filepath.Join(dirs.SnapDBusSystemPolicyDir, "snap.*.*.conf"),
		filepath.Join(dirs.SnapServicesDir, "snap.*.service"),
		filepath.Join(dirs.SnapServicesDir, "snap.*.timer"),
		filepath.Join(dirs.SnapServicesDir, "snap.*.socket"),
		filepath.Join(dirs.SnapServicesDir, "snap-*.mount"),
		filepath.Join(dirs.SnapServicesDir, "multi-user.target.wants", "snap-*.mount"),
		filepath.Join(dirs.SnapServicesDir, "default.target.wants", "snap-*.mount"),
		filepath.Join(dirs.SnapServicesDir, "snapd.mounts.target.wants", "snap-*.mount"),
		filepath.Join(dirs.SnapUserServicesDir, "snap.*.service"),
		filepath.Join(dirs.SnapUserServicesDir, "snap.*.socket"),
		filepath.Join(dirs.SnapUserServicesDir, "snap.*.timer"),
		filepath.Join(dirs.SnapUserServicesDir, "default.target.wants", "snap.*.service"),
		filepath.Join(dirs.SnapUserServicesDir, "sockets.target.wants", "snap.*.socket"),
		filepath.Join(dirs.SnapUserServicesDir, "timers.target.wants", "snap.*.timer"),
		filepath.Join(runinhibit.InhibitDir, "*.lock"),
	}

	for _, gl := range globs {
		matches, err := filepath.Glob(filepath.Join(preseedChroot, gl))
		if err != nil {

			return err
		}
		for _, path := range matches {
			if err := os.Remove(path); err != nil {
				return fmt.Errorf("error removing %s: %v", path, err)
			}
		}
	}

	globs = []string{
		filepath.Join(dirs.SnapDataDir, "*"),
		filepath.Join(dirs.SnapCacheDir, "*"),
		filepath.Join(apparmor_sandbox.CacheDir, "*"),
		filepath.Join(dirs.SnapDesktopFilesDir, "*"),
		filepath.Join(dirs.SnapDBusSessionServicesDir, "*"),
		filepath.Join(dirs.SnapDBusSystemServicesDir, "*"),
	}

	for _, gl := range globs {
		matches, err := filepath.Glob(filepath.Join(preseedChroot, gl))
		if err != nil {

			return err
		}
		for _, path := range matches {
			if err := os.RemoveAll(path); err != nil {
				return fmt.Errorf("error removing %s: %v", path, err)
			}
		}
	}

	paths := []string{
		dirs.SnapAssertsDBDir,
		dirs.FeaturesDir,
		dirs.SnapDesktopIconsDir,
		dirs.SnapDeviceDir,
		dirs.SnapCookieDir,
		dirs.SnapMountPolicyDir,
		dirs.SnapAppArmorDir,
		dirs.SnapSeqDir,
		dirs.SnapMountDir,
		dirs.SnapSeccompBase,
	}

	for _, path := range paths {
		if err := os.RemoveAll(filepath.Join(preseedChroot, path)); err != nil {

			return fmt.Errorf("error removing %s: %v", path, err)
		}
	}

	for _, completersPath := range []string{dirs.CompletersDir, dirs.LegacyCompletersDir} {
		if err := resetCompletionSymlinks(filepath.Join(preseedChroot, completersPath)); err != nil {
			return err
		}
	}

	return nil
}

ResetPreseededChroot removes all preseeding artifacts from preseedChroot (classic Ubuntu only).

Functions

func Classic

func Classic(chrootDir string) error

Classic runs preseeding of a classic ubuntu system pointed by chrootDir.

func ClassicReset

func ClassicReset(chrootDir string) error

func Core20

func Core20(opts *CoreOptions) error

Core20 runs preseeding of UC20 system prepared by prepare-image in prepareImageDir and stores the resulting preseed preseed.tgz file in system-seed/systems/<systemlabel>/preseed.tgz.

func MockMakePreseedTempDir

func MockMakePreseedTempDir(f func() (string, error)) (restore func())

func MockMakeWritableTempDir

func MockMakeWritableTempDir(f func() (string, error)) (restore func())

func MockSnapdMountPath

func MockSnapdMountPath(path string) (restore func())

func MockSyscallChroot

func MockSyscallChroot(f func(string) error) (restore func())

func MockSystemSnapFromSeed

func MockSystemSnapFromSeed(f func(rootDir, sysLabel string) (string, string, error)) (restore func())

func MockTrusted

func MockTrusted(mockTrusted []asserts.Assertion) (restore func())

Types

type CoreOptions

type CoreOptions struct {
	// prepare image directory
	PrepareImageDir string
	// key to sign preseeded data with
	PreseedSignKey string
	// optional path to AppArmor kernel features directory
	AppArmorKernelFeaturesDir string
	// optional sysfs overlay
	SysfsOverlay string
}

CoreOptions provides required and optional options for core preseeding.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL