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 ¶
- Variables
- func Classic(chrootDir string) error
- func ClassicReset(chrootDir string) error
- func Core20(opts *CoreOptions) error
- func MockMakePreseedTempDir(f func() (string, error)) (restore func())
- func MockMakeWritableTempDir(f func() (string, error)) (restore func())
- func MockSnapdMountPath(path string) (restore func())
- func MockSyscallChroot(f func(string) error) (restore func())
- func MockSystemSnapFromSeed(f func(rootDir, sysLabel string) (string, string, error)) (restore func())
- func MockTrusted(mockTrusted []asserts.Assertion) (restore func())
- type CoreOptions
Constants ¶
This section is empty.
Variables ¶
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 ClassicReset ¶
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 MockMakeWritableTempDir ¶
func MockSnapdMountPath ¶
func MockSnapdMountPath(path string) (restore func())
func MockSyscallChroot ¶
func MockSystemSnapFromSeed ¶
func MockTrusted ¶
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.
Click to show internal directories.
Click to hide internal directories.